public ActionResult CreateEdit(NeCategory model, string save) { bool isSuccess = false; ViewBag.MessageType = "ErrorMessage"; ViewBag.Message = "Error occoured. Please fill up all field correctly."; if (ModelState.IsValid) { //unique name check model.Name = model.Name.Trim(); var itemCount = _neCategoryService.LoadAll(true, 0, model.Name).Where(x => x.Id != model.Id).ToList().Count(); if (itemCount > 0) { ViewBag.Message = "Duplicate name found."; } else { if (model.Id > 0) { _neCategoryService.Update(model); isSuccess = true; ViewBag.MessageType = "SuccessMessage"; ViewBag.Message = "Data updated successfull."; } else { _neCategoryService.Save(model); isSuccess = true; ViewBag.MessageType = "SuccessMessage"; ViewBag.Message = "Data saved successfull."; } } } if (isSuccess == true && save == "Save") { return(RedirectToAction("Manage")); } return(View(model)); }
public ActionResult CreateEdit(NeCategory model, string save) { bool isSuccess = false; string returnMessage = "Error occoured. Please fill up all field correctly."; if (ModelState.IsValid) { isSuccess = true; #region For default language var defaultDetails = model.Details.Where(x => x.Language == GlobalContext.WebSite.Language).FirstOrDefault(); if (defaultDetails == null) { isSuccess = false; returnMessage = "Default language data can't be null"; } else { //title empty validation if (string.IsNullOrEmpty(defaultDetails.Name)) { isSuccess = false; returnMessage = "Default language Name can't be null"; } else { model.Name = defaultDetails.Name; } } #endregion #region Check validation for other languages List <NeCategoryDetails> deletedList = new List <NeCategoryDetails>(); foreach (var item in model.Details.Where(x => x.Language != GlobalContext.WebSite.Language).ToList()) { if (item.Id == 0 && string.IsNullOrEmpty(item.Name)) { deletedList.Add(item); } else { if (string.IsNullOrEmpty(item.Name)) { isSuccess = false; returnMessage = "Name can't be null for language " + item.Language; } } } //Remove empty if (isSuccess) { foreach (var item in deletedList) { model.Details.Remove(item); } } #endregion #region Operation if (isSuccess) { //unique name check model.Name = model.Name.Trim(); var itemCount = _neCategoryService.LoadAll(true, 0, model.Name).Where(x => x.Id != model.Id).ToList().Count(); if (itemCount > 0) { isSuccess = false; returnMessage = "Duplicate name found."; } else { if (model.Id > 0) { _neCategoryService.Update(model); isSuccess = true; returnMessage = "Data updated successfull."; } else { _neCategoryService.Save(model); isSuccess = true; returnMessage = "Data saved successfull."; } } } #endregion } else { returnMessage = string.Join("; ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage)); } if (isSuccess) { ShowMessage(returnMessage, Framework.Core.Mvc.Views.MessageType.Success); } else { ShowMessage(returnMessage, Framework.Core.Mvc.Views.MessageType.Error, false, true); } if (isSuccess == true && save == "Save") { return(RedirectToAction("Manage")); } else if (isSuccess == true) { return(RedirectToAction("CreateEdit")); } return(View(model)); }