Ejemplo n.º 1
0
        public async Task <IActionResult> CreateAward(IFormFile newImage, CreateAwardModel model)
        {
            if (ModelState.IsValid)
            {
                Award award = await _awardLogic.GetAwardByNameAsync(model.AwardTitle);

                if (award == null)
                {
                    award = new Award
                    {
                        AwardTitle  = model.AwardTitle,
                        Description = model.Description,
                        AwardType   = model.AwardType,
                        Creater     = new User {
                            Email = User.Identity.Name
                        }
                    };

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

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Award with this title already exists");
                }
            }

            return(View(model));
        }