Пример #1
0
        public IActionResult Edit(int id, NutrientEditViewModel data)
        {
            var userId = int.Parse(User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Sid)?.Value);

            if (!decimal.TryParse(data.MaxIntake, out var amount))
            {
                return(View(data));
            }

            var nutrient = new Nutrient
            {
                Id        = id,
                Name      = data.Name,
                MaxIntake = amount
            };


            if (_nutrientLogic.Edit(userId, nutrient))
            {
                return(RedirectToAction("List", "Nutrient"));
            }


            ViewData["message"] = "Er ging iets fout";
            return(View(data));
        }
Пример #2
0
        public IActionResult Edit(int id)
        {
            var nutrient = _nutrientLogic.GetBy(id);


            var viemodel = new NutrientEditViewModel
            {
                Name      = nutrient.Name,
                MaxIntake = nutrient.MaxIntake.ToString()
            };


            return(View(viemodel));
        }