// GET: /Dinners/Details/2 public ViewResult Details(int id) { Dinner dinner = _dinnerRepository.TryGetDinner(id); if (dinner == null) { return(View(ViewNames.NotFound)); } bool modificationIsAuthorized = ModificationIsAuthorized(dinner); bool userHasRsvp = dinner.UserHasRsvp(User.Identity.Name); var viewModel = new DinnerDetailsViewModel(dinner, modificationIsAuthorized, userHasRsvp); return(View(viewModel)); }
public static Dinner ToModel(this DinnerViewModel viewModel, NerdDinnerDataContext dataContext) { if (viewModel == null) { throw new ArgumentNullException("viewModel"); } if (dataContext == null) { throw new ArgumentNullException("dataContext"); } var dinnerRepository = new DinnerRepository(dataContext); var countryRepository = new CountryRepository(dataContext); Dinner model = dinnerRepository.TryGetDinner(viewModel.DinnerID) ?? new Dinner(); model.Address = viewModel.Address; model.ContactPhone = viewModel.ContactPhone; model.Description = viewModel.Description; model.EventDate = viewModel.EventDate; model.Latitude = viewModel.Latitude; model.Longitude = viewModel.Longitude; model.Title = viewModel.Title; model.HostedBy = viewModel.HostedBy; model.Country = viewModel.Country != null?countryRepository.GetCountry(viewModel.Country.CountryID) : null; return(model); }