public ActionResult CreateEdit(long Id = 0) { NeNews item = new NeNews(); ViewBag.CategoryList = _neCategoryService.LoadAll(true); if (Id > 0) { item = _neNewsService.Get(Id); } else { NeNewsDetails _itemDetails = new NeNewsDetails(); _itemDetails.Language = GlobalContext.WebSite.Language; item.Details.Add(_itemDetails); } if (GlobalContext.WebSite.IsMultiLangual) { foreach (var lang in SupportedCultures.Cultures) { var count = item.Details.Where(x => x.Language == lang.TwoLetterISOLanguageName).Count(); if (count <= 0) { NeNewsDetails _itemDetails = new NeNewsDetails(); _itemDetails.Language = lang.TwoLetterISOLanguageName; item.Details.Add(_itemDetails); } } } return(View(item)); }
public ActionResult CreateEdit(long Id = 0) { NeNews item = new NeNews(); ViewBag.CategoryList = _neCategoryService.LoadAll(true); if (Id > 0) { item = _neNewsService.Get(Id); } return(View(item)); }
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)); }
public ActionResult Manage() { var itemList = _neCategoryService.LoadAll().OrderByDescending(x => x.Id).ToList();; return(View(itemList)); }