public ActionResult Edit(GeneralCategory generalCategory)
        {
            if (ModelState.IsValid)
            {
                //ModelState.Clear();

                try
                {
                    if (_generalCategoryManager.Update(generalCategory))
                    {
                        ViewBag.Msg = "Updated successfully!";
                        return(View());
                    }
                }
                catch (Exception exception)
                {
                    int NameExist = _generalCategoryManager.GetAll(c => c.Name == generalCategory.Name).Count();

                    if (NameExist > 0)
                    {
                        ModelState.AddModelError("Name", "Name already exists in the system");
                    }

                    int ShortNameExist = _generalCategoryManager.GetAll(c => c.ShortName == generalCategory.ShortName).Count();

                    if (ShortNameExist > 0)
                    {
                        ModelState.AddModelError("ShortName", "Short name already exists in the system");
                    }
                }
            }
            return(View(generalCategory));
        }
 public ActionResult Edit([Bind(Include = "Id,Name,ShortName,Description")] GeneralCategory generalCategory)
 {
     if (ModelState.IsValid)
     {
         if (_generalCategoryManager.IsShortNameUnique(generalCategory.ShortName))
         {
             _generalCategoryManager.Update(generalCategory);
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError("ShortName", "ShortName Is Not Unique!");
     }
     return(View(generalCategory));
 }
Ejemplo n.º 3
0
        public ActionResult Edit(int?id, Organization organizations)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GeneralCategory generalCategory = generalCategoryManager.GetById(id);

            generalCategory.Name = organizations.Name;
            generalCategory.Code = organizations.ShortName;
            if (generalCategoryManager.IsExistUpdate(generalCategory.Code, id))
            {
                ViewData["exist"] = "Code Already Exist";
            }
            else
            {
                generalCategoryManager.Update(generalCategory);
                return(RedirectToAction("Edit", new { Update = "true" }));
            }

            return(View(generalCategory));
        }