public ActionResult SelectFavorite(SupplementFavoriteSelectionModel model) { var entryModel = new SupplementEntryModel { ConsumedDate = model.ConsumedDate }; if (ModelState.IsValid && !String.IsNullOrEmpty(model.Selection)) { int favoriteId = int.Parse(model.Selection); using (var context = new DietJournalEntities()) { var favorite = context.SupplementFavorites.FirstOrDefault(f => f.Id == favoriteId); if (favorite != null) { entryModel.Milligrams = favorite.Milligrams.HasValue ? favorite.Milligrams.Value.ToString() : string.Empty; entryModel.Name = favorite.Name; entryModel.Favorite = true; } } } return EntryView(entryModel); }
public ActionResult SelectFavorite(DateTime date) { var model = new SupplementFavoriteSelectionModel { ConsumedDate = date }; return View(model); }