public JsonResult GetByMenuId(int menuId, int entityId) { var valueItemResponses = new List <ControlValueItemResponse>(); var menuLink = _menuLinkService.GetMenu(menuId); if (menuLink != null) { var genericControls = menuLink.GenericControls; if (genericControls.IsAny()) { valueItemResponses.AddRange(from item in genericControls from gcValue in item.GenericControlValues.Where(m => m.Status == (int)Status.Enable) select new ControlValueItemResponse { GenericControlValueId = gcValue.Id, Name = gcValue.ValueName, ValueName = gcValue.GetValueItem(entityId) }); } } var jsonResult = Json( new { success = valueItemResponses.Any(), list = this.RenderRazorViewToString("_PostDetail.Attribute", valueItemResponses) }, JsonRequestBehavior.AllowGet); return(jsonResult); }
public JsonResult GetByMenuId(int menuId, int entityId) { var lstValueResponse = new List <ControlValueItemResponse>(); var menuLink = _menuLinkService.GetMenu(menuId); if (menuLink != null) { var genericControls = menuLink.GenericControls; if (genericControls.IsAny()) { foreach (var item in genericControls) { var genericControlValues = item.GenericControlValues.Where(m => m.Status == 1); foreach (var gcValue in genericControlValues) { var objValueResponse = new ControlValueItemResponse { GenericControlValueId = gcValue.Id, Name = gcValue.ValueName, ValueName = gcValue.GetValueItem(entityId) }; lstValueResponse.Add(objValueResponse); } } } } var jsonResult = Json( new { success = lstValueResponse.Count > 0, list = this.RenderRazorViewToString("_CreateOrUpdate.GenericControlValue", lstValueResponse) }, JsonRequestBehavior.AllowGet); return(jsonResult); }
public ActionResult Create(MenuLinkViewModel model, string returnUrl) { ActionResult action; try { if (!ModelState.IsValid) { var messages = string.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors) .Select(v => v.ErrorMessage + " " + v.Exception)); ModelState.AddModelError("", messages); return(View(model)); } var menuName = model.MenuName.NonAccent(); var menuExsist = _menuLinkService.GetListSeoUrl(menuName); model.SeoUrl = model.MenuName.NonAccent(); if (menuExsist.Any(x => x.Id != model.Id)) { var menuLinkViewModel = model; var seoUrl = menuLinkViewModel.SeoUrl; var num = menuExsist.Count(); menuLinkViewModel.SeoUrl = string.Concat(seoUrl, "-", num.ToString()); } ImageHandler(model); var guid = Guid.NewGuid().ToString(); if (model.ParentId.HasValue) { model.CurrentVirtualId = guid; var byId = _menuLinkService.GetMenu(model.ParentId.Value); model.VirtualId = $"{byId.VirtualId}/{guid}"; model.VirtualSeoUrl = $"{byId.SeoUrl}/{model.SeoUrl}"; } else { model.VirtualId = guid; model.CurrentVirtualId = guid; } var modelMap = Mapper.Map <MenuLinkViewModel, MenuLink>(model); _menuLinkService.Create(modelMap); //Update Localized foreach (var localized in model.Locales) { _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MenuName, localized.MenuName, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.SeoUrl, localized.MenuName.NonAccent(), localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId); } Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.MenuLink))); if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\")) { action = RedirectToAction("Index"); } else { action = Redirect(returnUrl); } } catch (Exception ex) { LogText.Log(string.Concat("MenuLink.Create: ", ex.Message)); return(View(model)); } return(action); }
public ActionResult Edit(GenericControlViewModel model, string returnUrl) { ActionResult action; try { if (!ModelState.IsValid) { var messages = string.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors) .Select(v => v.ErrorMessage + " " + v.Exception)); ModelState.AddModelError("", messages); return(View(model)); } var objGenericControl = _gCService.GetById(model.Id); var menuLinks = new List <MenuLink>(); var menuIds = new List <int>(); var menuLink = Request["MenuLink"]; if (!string.IsNullOrEmpty(menuLink)) { foreach (var item in menuLink.Split(',').ToList()) { var menuId = int.Parse(item); menuIds.Add(menuId); menuLinks.Add(_menuLinkService.GetMenu(menuId, false)); } if (menuIds.IsAny()) { (from x in objGenericControl.MenuLinks where !menuIds.Contains(x.Id) select x).ToList() .ForEach(m => objGenericControl.MenuLinks.Remove(m) ); } } objGenericControl.MenuLinks = menuLinks; var modelMap = Mapper.Map <GenericControlViewModel, GenericControl>(model); _gCService.Update(objGenericControl); //Update Localized foreach (var localized in model.Locales) { _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Name, localized.Name, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId); } Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.UpdateSuccess, FormUI.GenericControl))); if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\")) { action = RedirectToAction("Index"); } else { action = Redirect(returnUrl); } } catch (Exception ex) { LogText.Log(string.Concat("GenericControl.Create: ", ex.Message)); return(View(model)); } return(action); }
public ActionResult Create(NewsViewModel model, string returnUrl) { ActionResult action; try { if (!ModelState.IsValid) { var messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors) .Select(v => v.ErrorMessage + " " + v.Exception)); ModelState.AddModelError("", messages); return(View(model)); } var titleNonAccent = model.Title.NonAccent(); var bySeoUrl = _newsService.GetBySeoUrl(titleNonAccent); model.SeoUrl = model.Title.NonAccent(); if (bySeoUrl.Any(x => x.Id != model.Id)) { var newsViewModel = model; newsViewModel.SeoUrl = string.Concat(newsViewModel.SeoUrl, "-", bySeoUrl.Count()); } ImageHandler(model); if (model.MenuId > 0) { var byId = _menuLinkService.GetMenu(model.MenuId, false); model.VirtualCatUrl = byId.VirtualSeoUrl; model.VirtualCategoryId = byId.VirtualId; } var modelMap = Mapper.Map <NewsViewModel, News>(model); _newsService.Create(modelMap); //Update Localized foreach (var localized in model.Locales) { _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.ShortDesc, localized.ShortDesc, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.SeoUrl, localized.Title.NonAccent(), localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId); } Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.News))); if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\")) { action = RedirectToAction("Index"); } else { action = Redirect(returnUrl); } } catch (Exception ex) { LogText.Log(string.Concat("News.Create: ", ex.Message)); ModelState.AddModelError("", ex.Message); return(View(model)); } return(action); }