i have a viewmodel:
public class ManageUserViewModel
{
public Entities.User User { get; set; }
public bool IsLockedOut { get; set; }
public bool IsActivated { get; set; }
public bool IsArchived { get; set; }
}
in Entities.User User i have a method:
/// Gets the incentive programs that this user is participating in.
public IEnumerable<IncentiveProgram> GetParticipatingIncentivePrograms()
{
return Node.ParticipatingIncentivePrograms
.Where(x => x.PublishingState == PublishingState.Live
&& DateTime.UtcNow.Date >= x.DateStart && DateTime.UtcNow.Date <= x.DateEnd);
}
then i have my controller:
[HttpGet]
public ActionResult UserDetails(int id)
{
var user = ZincService.GetUserForId(id);
if (user == null || user.Customer.CustomerId != CurrentCustomer.CustomerId)
return DataNotFound();
ManageUserViewModel viewModel = new ManageUserViewModel();
viewModel.User = user;
viewModel.IsLockedOut = MembershipService.IsUserLocked(user.Email);
viewModel.IsActivated = user.DateTimeActivated.HasValue && MembershipService.IsUserApproved(user.Email);
viewModel.IsArchived = user.IsArchived;
viewModel.User.GetParticipatingIncentivePrograms();
return View(viewModel);
}
how do i get to output of GetParticipatingIncentivePrograms in my view?
I dont have code in my view yet.
thanks
Imho, you’d be better representing your incentive programs in your view model. In fact to have a userViewModel and then probably have a list of programs within this. Then load these within your controller
It’s usually best to not load your whole domain graph into a view as you could run into several issues (N+1 db calls, accessing a closed proxy, etc). I’ve typed your programs as a simple list of names, but you might expand this to a dictionary or lookup. Again keeping the view model as light and simple as possible.
UPDATE:
As you can’t change the viewmodel then it looks like you must set the value, you are only calling at present. So try the following
If there is such a collection on user or set them to something else on your view model.