Esempio n. 1
0
        public async Task <IActionResult> EditAward(IFormFile newImage, EditAwardModel model)
        {
            if (ModelState.IsValid)
            {
                Award award = await _awardLogic.GetAwardByIdAsync(model.AwardId);

                if (award != null)
                {
                    award.AwardTitle  = model.AwardTitle;
                    award.AwardType   = model.AwardType;
                    award.Description = model.Description;

                    await _awardLogic.EditAwardAsync(newImage, award, _env.WebRootPath);

                    return(RedirectToAction("AwardList", "Award"));
                }
                else
                {
                    ModelState.AddModelError("", "Award does not exists");
                }
            }

            var awardTypes = Enum.GetValues(typeof(AwardType))
                             .Cast <AwardType>()
                             .Select(at => at.ToString())
                             .Where(at => at != "None")
                             .ToArray();

            ViewBag.AwardTypes = new SelectList(awardTypes);

            return(View(model));
        }