コード例 #1
0
        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);
        }
コード例 #2
0
 public ActionResult SelectFavorite(DateTime date)
 {
     var model = new SupplementFavoriteSelectionModel
     {
         ConsumedDate = date
     };
     return View(model);
 }