Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,DateTimePosted,DateTimeChanged,ApplicationUserId,DateTime,Meal,Calories,Fat,SaturatedFat,PolyunsaturatedFat,MonounsaturatedFat,TransFat,Cholesterol,Sodium,Potassium,Carbohydrates,Fibers,Sugar,Protein,VitaminA,VitaminC,Calcium,Iron,Notes")] FoodDiaryPost foodDiaryPost)
        {
            if (id != foodDiaryPost.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(foodDiaryPost);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FoodDiaryPostExists(foodDiaryPost.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "FullName", foodDiaryPost.ApplicationUserId);
            return(View(foodDiaryPost));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,DateTimePosted,DateTimeChanged,ApplicationUserId,DateTime,Meal,Calories,Fat,SaturatedFat,PolyunsaturatedFat,MonounsaturatedFat,TransFat,Cholesterol,Sodium,Potassium,Carbohydrates,Fibers,Sugar,Protein,VitaminA,VitaminC,Calcium,Iron,Notes")] FoodDiaryPost foodDiaryPost)
        {
            if (ModelState.IsValid)
            {
                _context.Add(foodDiaryPost);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "FullName", foodDiaryPost.ApplicationUserId);
            return(View(foodDiaryPost));
        }