public async Task <IActionResult> Edit(BlogPostModel model, bool continueEditing) { var blogPost = await _blogService.GetBlogPostById(model.Id); if (blogPost == null) { //No blog post found with the specified id return(RedirectToAction("List")); } if (_workContext.CurrentCustomer.IsStaff()) { if (!blogPost.AccessToEntityByStore(_workContext.CurrentCustomer.StaffStoreId)) { return(RedirectToAction("Edit", new { id = blogPost.Id })); } } if (ModelState.IsValid) { if (_workContext.CurrentCustomer.IsStaff()) { model.LimitedToStores = true; model.SelectedStoreIds = new string[] { _workContext.CurrentCustomer.StaffStoreId }; } blogPost = await _blogViewModelService.UpdateBlogPostModel(model, blogPost); SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Blog.BlogPosts.Updated")); if (continueEditing) { //selected tab await SaveSelectedTabIndex(); return(RedirectToAction("Edit", new { id = blogPost.Id })); } return(RedirectToAction("List")); } //If we got this far, something failed, redisplay form ViewBag.AllLanguages = await _languageService.GetAllLanguages(true); model = await _blogViewModelService.PrepareBlogPostModel(model, blogPost); //locales await AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Title = blogPost.GetLocalized(x => x.Title, languageId, false, false); locale.Body = blogPost.GetLocalized(x => x.Body, languageId, false, false); locale.BodyOverview = blogPost.GetLocalized(x => x.BodyOverview, languageId, false, false); locale.MetaKeywords = blogPost.GetLocalized(x => x.MetaKeywords, languageId, false, false); locale.MetaDescription = blogPost.GetLocalized(x => x.MetaDescription, languageId, false, false); locale.MetaTitle = blogPost.GetLocalized(x => x.MetaTitle, languageId, false, false); locale.SeName = blogPost.GetSeName(languageId, false, false); }); return(View(model)); }
public IActionResult Edit(BlogPostModel model, bool continueEditing) { var blogPost = _blogService.GetBlogPostById(model.Id); if (blogPost == null) { //No blog post found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { blogPost = _blogViewModelService.UpdateBlogPostModel(model, blogPost); SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Blog.BlogPosts.Updated")); if (continueEditing) { //selected tab SaveSelectedTabIndex(); return(RedirectToAction("Edit", new { id = blogPost.Id })); } return(RedirectToAction("List")); } //If we got this far, something failed, redisplay form ViewBag.AllLanguages = _languageService.GetAllLanguages(true); model = _blogViewModelService.PrepareBlogPostModel(model, blogPost); //locales AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Title = blogPost.GetLocalized(x => x.Title, languageId, false, false); locale.Body = blogPost.GetLocalized(x => x.Body, languageId, false, false); locale.BodyOverview = blogPost.GetLocalized(x => x.BodyOverview, languageId, false, false); locale.MetaKeywords = blogPost.GetLocalized(x => x.MetaKeywords, languageId, false, false); locale.MetaDescription = blogPost.GetLocalized(x => x.MetaDescription, languageId, false, false); locale.MetaTitle = blogPost.GetLocalized(x => x.MetaTitle, languageId, false, false); locale.SeName = blogPost.GetSeName(languageId, false, false); }); return(View(model)); }