Example #1
0
        public ActionResult OnEdit(CountryModels country)
        {
            if (ModelState.IsValid)
            {
                var result = CountryService.Update(country.CloneTo <Country>());
                if (result == Result.NotExists)
                {
                    ModelState.AddModelError("", "Id không tồn tại trên hệ thống.");
                    return(View("Edit", country));
                }

                SetFlashMessage($"Cập nhật Quốc gia '{country.Name}' thành công.");
                if (country.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                return(View("Edit", country));
            }
            return(View("Edit", country));
        }
Example #2
0
 public ActionResult OnCreate(CountryModels country)
 {
     if (ModelState.IsValid)
     {
         var result = CountryService.Insert(country.CloneTo <Country>());
         if (result == Result.Exists)
         {
             ModelState.AddModelError("", $"Quốc gia {country.Name} đã tồn tại trên hệ thống.");
             return(View("Create", country));
         }
         SetFlashMessage($"Thêm Quốc gia '{country.Name}' thành công.");
         if (country.SaveList)
         {
             return(RedirectToAction("Index"));
         }
         ModelState.Clear();
         return(View("Create", country.ResetValue()));
     }
     return(View("Create", country));
 }