public ActionResult Details(long newsId) { NeNews item = new NeNews(); item = _neNewsService.Get(newsId); 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); } 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(NeNews model, string save, long[] LsCategory) { bool isSuccess = false; ViewBag.MessageType = "ErrorMessage"; ViewBag.Message = "Error occoured. Please fill up all field correctly."; if (ModelState.IsValid) { if (LsCategory == null || LsCategory.Count() == 0) { ViewBag.Message = "You have to select at least one category."; } else { model.CategoryList = new List <NeNewsCategory>(); foreach (var item in LsCategory) { model.CategoryList.Add(new NeNewsCategory() { NeNews = model, NeCategoryId = item }); } if (model.Id > 0) { _neNewsService.Update(model); isSuccess = true; ViewBag.MessageType = "SuccessMessage"; ViewBag.Message = "Data updated successfull."; } else { _neNewsService.Save(model); isSuccess = true; ViewBag.MessageType = "SuccessMessage"; ViewBag.Message = "Data saved successfull."; } } } if (isSuccess == true && save == "Save") { return(RedirectToAction("Manage")); } ViewBag.CategoryList = _neCategoryService.LoadAll(true); return(View(model)); }
public ActionResult Delete(long Id) { NeNews item = _neNewsService.Get(Id); return(View(item)); }
public ActionResult CreateEdit(NeNews model, string save, long[] LsCategory) { 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 <NeNewsDetails> deletedList = new List <NeNewsDetails>(); 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) { if (LsCategory == null || LsCategory.Count() == 0) { isSuccess = false; returnMessage = "You have to select at least one category."; } else { model.CategoryList = new List <NeNewsCategory>(); foreach (var item in LsCategory) { model.CategoryList.Add(new NeNewsCategory() { NeNews = model, NeCategoryId = item }); } if (model.Id > 0) { _neNewsService.Update(model); isSuccess = true; returnMessage = "Data updated successfull."; } else { _neNewsService.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, false, true); } else { ShowMessage(returnMessage, Framework.Core.Mvc.Views.MessageType.Error); } if (isSuccess == true && save == "Save") { return(RedirectToAction("Manage")); } else if (isSuccess == true) { return(RedirectToAction("CreateEdit")); } ViewBag.CategoryList = _neCategoryService.LoadAll(true); return(View(model)); }