public ActionResult Edit(StaticContentType contentType) { CheckIfSiteAdmin(); var staticContentViewModel = new StaticContentViewModel(); var staticContent = _staticContentService.GetStaticContent(contentType); staticContentViewModel.Content = staticContent.Content; try { // Format the HTML returned by Telerik control so that indented HTML will be shown in HTML editor. staticContentViewModel.Content = XElement.Parse(staticContentViewModel.Content).ToString(); } catch (XmlException) { try { // In case if the HTML doesn't have a root, add a <p> tag as wrapper. staticContentViewModel.Content = XElement.Parse(string.Format(CultureInfo.CurrentCulture, "<p>{0}</p>", staticContentViewModel.Content)).ToString(); } catch (XmlException) { // Consume any other Xml exception with parsing and try to load the string as is. // There could be problem like the text is not a valid XML. } } return(View("Save", staticContentViewModel)); }
public ActionResult Edit() { CheckIfSiteAdmin(); var staticContentViewModel = new StaticContentViewModel(); return(View("Save", staticContentViewModel)); }
public ActionResult Create() { var model = new StaticContentViewModel(); //Add locales to model AddLocales(_languageService, model.Locales); return(base.View(model)); }
public async Task <IActionResult> RenderCreate() { var nextOrder = await _staticContentService.GetNextOrder(); var viewModel = new StaticContentViewModel() { Order = nextOrder, IsShow = true, }; return(View("Create", viewModel)); }
public async Task <bool> InsertAsync(StaticContentViewModel viewModel) { var entity = new StaticContent() { Id = viewModel.Id, Name = viewModel.Name, Content = viewModel.Content, Order = viewModel.Order, IsShow = viewModel.IsShow, }; await _staticContents.AddAsync(entity); var result = await _unitOfWork.SaveChangesAsync(); return(result != 0); }
public async Task <bool> UpdateAsync(StaticContentViewModel viewModel) { var entity = await _staticContents.FirstOrDefaultAsync(p => p.Id == viewModel.Id); if (entity != null) { entity.Name = viewModel.Name; entity.Content = viewModel.Content; entity.Order = viewModel.Order; entity.IsShow = viewModel.IsShow; var result = await _unitOfWork.SaveChangesAsync(); return(result != 0); } return(await Task.FromResult(false)); }
public ActionResult Edit(int Id) { StaticContentViewModel modelMap = Mapper.Map <StaticContent, StaticContentViewModel>(this._staticContentService.GetById(Id)); //Add Locales to model AddLocales(_languageService, modelMap.Locales, (locale, languageId) => { locale.Id = modelMap.Id; locale.LocalesId = modelMap.Id; locale.Title = modelMap.GetLocalized(x => x.Title, Id, languageId, false, false); locale.ShortDesc = modelMap.GetLocalized(x => x.ShortDesc, Id, languageId, false, false); locale.Description = modelMap.GetLocalized(x => x.Description, Id, languageId, false, false); locale.MetaTitle = modelMap.GetLocalized(x => x.MetaTitle, Id, languageId, false, false); locale.MetaKeywords = modelMap.GetLocalized(x => x.MetaKeywords, Id, languageId, false, false); locale.MetaDescription = modelMap.GetLocalized(x => x.MetaDescription, Id, languageId, false, false); locale.SeoUrl = modelMap.GetLocalized(x => x.SeoUrl, Id, languageId, false, false); }); return(base.View(modelMap)); }
private void ImageHandler(StaticContentViewModel model) { if (model.Image != null && model.Image.ContentLength > 0) { var folderName = CommonHelper.FolderName(model.Title); var fileExtension = Path.GetExtension(model.Image.FileName); var fileNameOriginal = Path.GetFileNameWithoutExtension(model.Image.FileName); var fileName = fileNameOriginal.FileNameFormat(fileExtension); var sizeWidthBg = _settingService.GetSetting("StaticContent.WidthBigSize", ImageSize.WidthDefaultSize); var sizeHeighthBg = _settingService.GetSetting("StaticContent.HeightBigSize", ImageSize.HeightDefaultSize); var isPng = _settingService.GetSetting("StaticContent.pngFormat", 0); _imageService.CropAndResizeImage(model.Image, $"{Constant.StaticContentFolder}{folderName}/", fileName, sizeWidthBg, sizeHeighthBg, isPng != 0); model.ImagePath = $"{Constant.StaticContentFolder}{folderName}/{fileName}"; } }
public async Task <IActionResult> Create(StaticContentViewModel viewModel) { if (ModelState.IsValid) { if (await _staticContentService.CheckExistNameAsync(viewModel.Id, viewModel.Name)) { ModelState.AddModelError(nameof(viewModel.Name), "نام وارد شده تکراری است"); return(View(viewModel)); } var result = await _staticContentService.InsertAsync(viewModel); if (result) { return(RedirectToAction("Index", "StaticContents")); } return(View(viewModel)); } return(View(viewModel)); }
public async Task <IActionResult> Delete(StaticContentViewModel viewModel) { var staticContentViewModel = await _staticContentService.GetByIdAsync(viewModel.Id); if (staticContentViewModel == null) { ModelState.AddModelError("", RequestNotFound); } else { var result = await _staticContentService.DeleteAsync(staticContentViewModel.Id); if (result) { return(Json(new { success = true })); } ModelState.AddModelError("", RequestNotFound); } return(PartialView("_Delete", model: viewModel)); }
public ActionResult Create(StaticContentViewModel model, string ReturnUrl) { ActionResult action; try { if (!base.ModelState.IsValid) { String messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors) .Select(v => v.ErrorMessage + " " + v.Exception)); base.ModelState.AddModelError("", messages); return(base.View(model)); } else { string titleNonAccent = model.Title.NonAccent(); IEnumerable <StaticContent> bySeoUrl = this._staticContentService.GetBySeoUrl(titleNonAccent, isCache: false); model.SeoUrl = model.Title.NonAccent(); if (bySeoUrl.Any <StaticContent>((StaticContent x) => x.Id != model.Id)) { StaticContentViewModel staticContentViewModel = model; staticContentViewModel.SeoUrl = string.Concat(staticContentViewModel.SeoUrl, "-", bySeoUrl.Count <StaticContent>()); } if (model.Image != null && model.Image.ContentLength > 0) { string fileName = Path.GetFileName(model.Image.FileName); string extension = Path.GetExtension(model.Image.FileName); fileName = fileName.FileNameFormat(extension); string str = Path.Combine(base.Server.MapPath(string.Concat("~/", Contains.ImageFolder)), fileName); model.Image.SaveAs(str); model.ImagePath = string.Concat(Contains.ImageFolder, fileName); } if (model.MenuId > 0) { MenuLink menuLink = this._menuLinkService.GetById(model.MenuId, isCache: false); model.MenuLink = Mapper.Map <MenuLink, MenuLinkViewModel>(menuLink); model.VirtualCategoryId = menuLink.VirtualId; } StaticContent modelMap = Mapper.Map <StaticContentViewModel, StaticContent>(model); this._staticContentService.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); } base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.StaticContent))); if (!base.Url.IsLocalUrl(ReturnUrl) || ReturnUrl.Length <= 1 || !ReturnUrl.StartsWith("/") || ReturnUrl.StartsWith("//") || ReturnUrl.StartsWith("/\\")) { action = base.RedirectToAction("Index"); } else { action = this.Redirect(ReturnUrl); } } } catch (Exception exception1) { Exception exception = exception1; ExtentionUtils.Log(string.Concat("Post.Create: ", exception.Message)); base.ModelState.AddModelError("", exception.Message); return(base.View(model)); } return(action); }
public ActionResult Save(StaticContentViewModel staticContentViewModel) { CheckIfSiteAdmin(); // Make sure staticContentViewModel is not null this.CheckNotNull(() => new { staticContentViewModel }); if (ModelState.IsValid) { var staticContent = new StaticContentDetails() { TypeID = staticContentViewModel.ContentType, Content = staticContentViewModel.Content, ModifiedByID = CurrentUserId }; var status = _staticContentService.UpdateStaticContent(staticContent); if (!status.Succeeded) { throw new Exception(status.ErrorMessage, status.Exception); } switch (staticContentViewModel.ContentType) { case (int)StaticContentType.HomePageHelpText: return(RedirectToAction("Index", "Home")); case (int)StaticContentType.FAQ: return(RedirectToAction("FAQs", "Home")); case (int)StaticContentType.WWTInstall: return(RedirectToAction("InstallWWT", "Home")); case (int)StaticContentType.ExcelInstall: return(RedirectToAction("ExcelAddInWelcome", "Home")); case (int)StaticContentType.ExcelHelp: return(RedirectToAction("ExcelAddInHelp", "Home")); case (int)StaticContentType.LearnMore: return(RedirectToAction("LearnMore", "Home")); case (int)StaticContentType.GetStarted: return(RedirectToAction("GetStarted", "Home")); case (int)StaticContentType.VisualizingContentinWWT: return(RedirectToAction("VisualizingContentinWWT", "Home")); case (int)StaticContentType.Narwhal: return(RedirectToAction("Narwhal", "Home")); case (int)StaticContentType.WWTAddinForExcel: return(RedirectToAction("WWTAddinForExcel", "Home")); default: return(RedirectToAction("Index", "Admin")); } } else { // In case of any validation error stay in the same page. staticContentViewModel.Content = Server.HtmlDecode(staticContentViewModel.Content); return(View("Save", staticContentViewModel)); } }
public ActionResult Create(StaticContentViewModel model, string returnUrl) { ActionResult action; try { if (!ModelState.IsValid) { var messages = 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 = _staticContentService.GetBySeoUrl(titleNonAccent, false); model.SeoUrl = model.Title.NonAccent(); if (bySeoUrl.Any(x => x.Id != model.Id)) { var staticContentViewModel = model; staticContentViewModel.SeoUrl = Concat(staticContentViewModel.SeoUrl, "-", bySeoUrl.Count()); } if (model.Image != null && model.Image.ContentLength > 0) { var folderName = Utils.FolderName(model.Title); var fileExtension = Path.GetExtension(model.Image.FileName); var fileNameOriginal = Path.GetFileNameWithoutExtension(model.Image.FileName); var fileName = fileNameOriginal.FileNameFormat(fileExtension); _imagePlugin.CropAndResizeImage(model.Image, $"{Contains.StaticContentFolder}{folderName}/", fileName, ImageSize.StaticContentWithBigSize, ImageSize.StaticContentHeightBigSize, true); model.ImagePath = $"{Contains.StaticContentFolder}{folderName}/{fileName}"; //var fileName = Path.GetFileName(model.Image.FileName); //var extension = Path.GetExtension(model.Image.FileName); //fileName = fileName.FileNameFormat(extension); //var str = Path.Combine(Server.MapPath(Concat("~/", Contains.StaticContentFolder)), fileName); //model.Image.SaveAs(str); //model.ImagePath = Concat(Contains.StaticContentFolder, fileName); } if (model.MenuId > 0) { var menuLink = _menuLinkService.GetById(model.MenuId, false); model.MenuLink = Mapper.Map <MenuLink, MenuLinkViewModel>(menuLink); model.VirtualCategoryId = menuLink.VirtualId; } var modelMap = Mapper.Map <StaticContentViewModel, StaticContent>(model); _staticContentService.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", Format(MessageUI.CreateSuccess, FormUI.StaticContent))); if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\")) { action = RedirectToAction("Index"); } else { action = Redirect(returnUrl); } } catch (Exception ex) { ExtentionUtils.Log(Concat("StaticContent.Create: ", ex.Message)); ModelState.AddModelError("", ex.Message); return(View(model)); } return(action); }
public ActionResult Create(StaticContentViewModel model, string returnUrl) { ActionResult action; try { if (!ModelState.IsValid) { var messages = 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 = _staticContentService.GetBySeoUrls(titleNonAccent, isCache: false); model.SeoUrl = model.Title.NonAccent(); if (bySeoUrl.Any(x => x.Id != model.Id)) { var staticContentViewModel = model; staticContentViewModel.SeoUrl = Concat(staticContentViewModel.SeoUrl, "-", bySeoUrl.Count()); } ImageHandler(model); if (model.MenuId > 0) { var menuLink = _menuLinkService.GetMenu(model.MenuId, false); model.MenuLink = Mapper.Map <MenuLink, MenuLinkViewModel>(menuLink); model.VirtualCategoryId = menuLink.VirtualId; } var modelMap = Mapper.Map <StaticContentViewModel, StaticContent>(model); _staticContentService.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", Format(MessageUI.CreateSuccess, FormUI.StaticContent))); 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(Concat("StaticContent.Create: ", ex.Message)); ModelState.AddModelError("", ex.Message); return(View(model)); } return(action); }