Exemplo n.º 1
0
 public IActionResult New(ImageViewModel img)
 {
     try{
         if (ModelState.IsValid)
         {
             if (!_repo.CheckName(img.Name))
             {
                 var model = new ImageModel()
                 {
                     Name        = img.Name,
                     Alias       = img.Alias,
                     IsLogo      = img.IsLogo,
                     IsProject   = img.IsProject,
                     IsSlide     = img.IsSlide,
                     Link        = img.Link,
                     Image       = img.Image,
                     Description = img.Description
                 };
                 _repo.Insert(model);
                 return(RedirectToAction("New"));
             }
             else
             {
                 ModelState.AddModelError("", "tên này đã tồn tại rồi, hãy thử tên khác.");
                 return(View(img));
             }
         }
         return(View());
     }catch (Exception ex) {
         ModelState.AddModelError("", ex.Message);
         return(View(img));
     }
 }