public virtual ActionResult Edit(BlogPostModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            var blogPost = _blogService.GetBlogPostById(model.Id);

            if (blogPost == null)
            {
                //No blog post found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                blogPost = model.ToEntity(blogPost);
                blogPost.StartDateUtc = model.StartDate;
                blogPost.EndDateUtc   = model.EndDate;
                _blogService.UpdateBlogPost(blogPost);

                //activity log
                _customerActivityService.InsertActivity("EditBlogPost", _localizationService.GetResource("ActivityLog.EditBlogPost"), blogPost.Id);

                //search engine name
                var seName = blogPost.ValidateSeName(model.SeName, model.Title, true);
                _urlRecordService.SaveSlug(blogPost, seName, blogPost.LanguageId);

                //Stores
                SaveStoreMappings(blogPost, model);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Blog.BlogPosts.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();

                    return(RedirectToAction("Edit", new { id = blogPost.Id }));
                }
                return(RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareStoresMappingModel(model, blogPost, true);
            PrepareLanguagesModel(model);
            return(View(model));
        }
        public virtual async Task <IActionResult> BlogPostEdit(BlogPostModel model, bool continueEditing)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            //try to get a blog post with the specified id
            var blogPost = await _blogService.GetBlogPostByIdAsync(model.Id);

            if (blogPost == null)
            {
                return(RedirectToAction("BlogPosts"));
            }

            if (ModelState.IsValid)
            {
                blogPost = model.ToEntity(blogPost);
                await _blogService.UpdateBlogPostAsync(blogPost);

                //activity log
                await _customerActivityService.InsertActivityAsync("EditBlogPost",
                                                                   string.Format(await _localizationService.GetResourceAsync("ActivityLog.EditBlogPost"), blogPost.Id), blogPost);

                //search engine name
                var seName = await _urlRecordService.ValidateSeNameAsync(blogPost, model.SeName, model.Title, true);

                await _urlRecordService.SaveSlugAsync(blogPost, seName, blogPost.LanguageId);

                //Stores
                await SaveStoreMappingsAsync(blogPost, model);

                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.ContentManagement.Blog.BlogPosts.Updated"));

                if (!continueEditing)
                {
                    return(RedirectToAction("BlogPosts"));
                }

                return(RedirectToAction("BlogPostEdit", new { id = blogPost.Id }));
            }

            //prepare model
            model = await _blogModelFactory.PrepareBlogPostModelAsync(model, blogPost, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Example #3
0
        public ActionResult Edit(BlogPostModel model, bool continueEditing, FormCollection form)
        {
            var blogPost = _blogService.GetBlogPostById(model.Id);

            if (blogPost == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                blogPost = model.ToEntity(blogPost);

                MediaHelper.UpdatePictureTransientStateFor(blogPost, c => c.MediaFileId);
                MediaHelper.UpdatePictureTransientStateFor(blogPost, c => c.PreviewMediaFileId);

                blogPost.CreatedOnUtc = model.CreatedOnUtc;
                blogPost.StartDateUtc = model.StartDate;
                blogPost.EndDateUtc   = model.EndDate;

                _blogService.UpdateBlogPost(blogPost);

                // Search engine name.
                var seName = blogPost.ValidateSeName(model.SeName, model.Title, true);
                _urlRecordService.SaveSlug(blogPost, seName, blogPost.LanguageId);

                SaveStoreMappings(blogPost, model.SelectedStoreIds);

                Services.EventPublisher.Publish(new ModelBoundEvent(model, blogPost, form));
                NotifySuccess(T("Admin.ContentManagement.Blog.BlogPosts.Updated"));

                return(continueEditing ? RedirectToAction("Edit", new { id = blogPost.Id }) : RedirectToAction("List"));
            }

            ViewBag.AllLanguages = _languageService.GetAllLanguages(true);

            // Tags
            var allTags = _blogService.GetAllBlogPostTags(0, 0, true).Select(x => x.Name).ToList();

            model.AvailableTags = new MultiSelectList(allTags, model.AvailableTags);
            model.Tags          = blogPost.Tags.SplitSafe(",");

            PrepareStoresMappingModel(model, blogPost, true);

            return(View(model));
        }
Example #4
0
        public virtual IActionResult BlogPostCreate(BlogPostModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var blogPost = model.ToEntity <BlogPost>();
                blogPost.StartDateUtc = model.StartDate;
                blogPost.EndDateUtc   = model.EndDate;
                blogPost.CreatedOnUtc = DateTime.UtcNow;
                _blogService.InsertBlogPost(blogPost);

                //activity log
                _customerActivityService.InsertActivity("AddNewBlogPost",
                                                        string.Format(_localizationService.GetResource("ActivityLog.AddNewBlogPost"), blogPost.Id), blogPost);

                //search engine name
                var seName = _urlRecordService.ValidateSeName(blogPost, model.SeName, model.Title, true);
                _urlRecordService.SaveSlug(blogPost, seName, blogPost.LanguageId);

                //Stores
                SaveStoreMappings(blogPost, model);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Blog.BlogPosts.Added"));

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                //selected tab
                SaveSelectedTabName();

                return(RedirectToAction("BlogPostEdit", new { id = blogPost.Id }));
            }

            //prepare model
            model = _blogModelFactory.PrepareBlogPostModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Example #5
0
        public virtual IActionResult BlogPostCreate(BlogPostModel model, bool continueEditing)
        {
            bool isAuthorized = _authorizationService.AuthorizeAsync(User, GetCurrentUserAsync(), CustomerOperations.Create).Result.Succeeded;

            if (!isAuthorized)
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                BlogPost blogPost = model.ToEntity <BlogPost>();
                blogPost.StartDateUtc = model.StartDate;
                blogPost.EndDateUtc   = model.EndDate;
                blogPost.CreatedOnUtc = DateTime.UtcNow;
                blogPost.CustomerId   = model.CustomerId;

                _blogService.InsertBlogPost(blogPost);

                //activity log
                _customerActivityService.InsertActivity("AddNewBlogPost",
                                                        string.Format("AddNewBlogPost{0}", blogPost.Id), blogPost);

                //search engine name
                string seName = _urlRecordService.ValidateSeName(blogPost, model.SeName, model.Title, true);
                _urlRecordService.SaveSlug(blogPost, seName);
                SuccessNotification("Yazı Eklendi");

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                //selected tab
                SaveSelectedTabName();

                return(RedirectToAction("BlogPostEdit", new { id = blogPost.Id }));
            }

            //prepare model
            model = _blogModelFactory.PrepareBlogPostModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Example #6
0
        public ActionResult Edit(BlogPostModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            var blogPost = _blogService.GetBlogPostById(model.Id);

            if (blogPost.CustomerId != _workContext.CurrentCustomer.Id)
            {
                return(AccessDeniedView());
            }
            if (blogPost == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                blogPost = model.ToEntity(blogPost);
                blogPost.CreatedOnUtc = model.CreatedOnUtc;
                blogPost.StartDateUtc = model.StartDate;
                blogPost.EndDateUtc   = model.EndDate;
                blogPost.CustomerId   = _workContext.CurrentCustomer.Id;
                _blogService.UpdateBlogPost(blogPost);

                //search engine name
                var seName = blogPost.ValidateSeName(model.SeName, model.Title, true);
                _urlRecordService.SaveSlug(blogPost, seName, blogPost.LanguageId);

                //Stores
                _storeMappingService.SaveStoreMappings <BlogPost>(blogPost, model.SelectedStoreIds);

                NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.Blog.BlogPosts.Updated"));
                return(continueEditing ? RedirectToAction("Edit", new { id = blogPost.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            ViewBag.AllLanguages = _languageService.GetAllLanguages(true);
            //Store
            PrepareStoresMappingModel(model, blogPost, true);
            return(View(model));
        }
Example #7
0
        public virtual ActionResult Edit(BlogPostModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlogposts))
            {
                return(AccessDeniedView());
            }

            var blogPost = _blogService.GetBlogPostById(model.Id);

            if (blogPost == null || blogPost.Deleted)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                blogPost = model.ToEntity(blogPost);
                blogPost.UpdatedOnUtc = DateTime.UtcNow;
                _blogService.UpdateBlogPost(blogPost);
                //Locales
                UpdateLocales(blogPost, model);
                //Tags
                _blogPostTagService.UpdateBlogPostTags(blogPost, ParseBlogPostTags(model.BlogPostTags));
                //Categories
                SaveCategoryMappings(blogPost, model);

                //Activity log
                _customerActivityService.InsertActivity("EditBlogPost", _localizationService.GetResource("ActivityLog.EditBlogPost"), blogPost.Title);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Blog.Posts.Updated"));

                if (continueEditing)
                {
                    SaveSelectedTabName();
                    return(RedirectToAction("Edit", new { id = blogPost.Id }));
                }
                return(RedirectToAction("List"));
            }
            PrepareBlogPostModel(model, blogPost);
            AddLocales(_languageService, model.Locales);
            PrepareCategoryMappingModel(model, blogPost, true);
            return(View(model));
        }
Example #8
0
        public virtual BlogPost InsertBlogPostModel(BlogPostModel model)
        {
            var blogPost = model.ToEntity();

            blogPost.CreatedOnUtc = DateTime.UtcNow;
            _blogService.InsertBlogPost(blogPost);

            //search engine name
            var seName = blogPost.ValidateSeName(model.SeName, model.Title, true);

            blogPost.SeName  = seName;
            blogPost.Locales = model.Locales.ToLocalizedProperty(blogPost, x => x.Title, _urlRecordService);
            _blogService.UpdateBlogPost(blogPost);
            _urlRecordService.SaveSlug(blogPost, seName, "");

            //update picture seo file name
            _pictureService.UpdatePictureSeoNames(blogPost.PictureId, blogPost.Title);

            return(blogPost);
        }
Example #9
0
        public ActionResult Create(BlogPostModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var blogPost = model.ToEntity();
                blogPost.CreatedOnUtc = DateTime.UtcNow;
                _blogService.InsertBlogPost(blogPost);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Blog.BlogPosts.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = blogPost.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            ViewBag.AllLanguages = _languageService.GetAllLanguages(true);
            return(View(model));
        }
Example #10
0
        public ActionResult Create(BlogPostModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var blogPost = model.ToEntity();
                blogPost.StartDateUtc = model.StartDate;
                blogPost.EndDateUtc   = model.EndDate;
                blogPost.CreatedOnUtc = DateTime.UtcNow;
                _blogService.InsertBlogPost(blogPost);

                //search engine name
                var seName = blogPost.ValidateSeName(model.SeName, model.Title, true);
                _urlRecordService.SaveSlug(blogPost, seName, blogPost.LanguageId);

                //Stores
                SaveStoreMappings(blogPost, model);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Blog.BlogPosts.Added"));

                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();

                    return(RedirectToAction("Edit", new { id = blogPost.Id }));
                }
                return(RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            ViewBag.AllLanguages = _languageService.GetAllLanguages(true);
            //Stores
            PrepareStoresMappingModel(model, null, true);
            return(View(model));
        }
        public virtual async Task <BlogPost> InsertBlogPostModel(BlogPostModel model)
        {
            var blogPost = model.ToEntity();

            blogPost.CreatedOnUtc = DateTime.UtcNow;
            await _blogService.InsertBlogPost(blogPost);

            //search engine name
            var seName = await blogPost.ValidateSeName(model.SeName, model.Title, true, _seoSettings, _urlRecordService, _languageService);

            blogPost.SeName  = seName;
            blogPost.Locales = await model.Locales.ToLocalizedProperty(blogPost, x => x.Title, _seoSettings, _urlRecordService, _languageService);

            await _blogService.UpdateBlogPost(blogPost);

            await _urlRecordService.SaveSlug(blogPost, seName, "");

            //update picture seo file name
            await _pictureService.UpdatePictureSeoNames(blogPost.PictureId, blogPost.Title);

            return(blogPost);
        }
Example #12
0
        public ActionResult Edit(BlogPostModel model, bool continueEditing, FormCollection form)
        {
            var blogPost = _blogService.GetBlogPostById(model.Id);

            if (blogPost == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                blogPost = model.ToEntity(blogPost);

                blogPost.CreatedOnUtc = model.CreatedOnUtc;
                blogPost.StartDateUtc = model.StartDate;
                blogPost.EndDateUtc   = model.EndDate;

                model.SeName = blogPost.ValidateSeName(model.SeName, blogPost.Title, true);
                _urlRecordService.SaveSlug(blogPost, model.SeName, 0);

                UpdateLocales(blogPost, model);

                _blogService.UpdateBlogPost(blogPost);

                SaveStoreMappings(blogPost, model.SelectedStoreIds);

                Services.EventPublisher.Publish(new ModelBoundEvent(model, blogPost, form));
                NotifySuccess(T("Admin.ContentManagement.Blog.BlogPosts.Updated"));

                return(continueEditing ? RedirectToAction("Edit", new { id = blogPost.Id }) : RedirectToAction("List"));
            }

            PrepareBlogPostModel(model, blogPost);

            return(View(model));
        }
Example #13
0
        public IActionResult Edit(BlogPostModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            var blogPost = _blogService.GetBlogPostById(model.Id);

            if (blogPost == null)
            {
                //No blog post found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                string prevPictureId = blogPost.PictureId;

                blogPost = model.ToEntity(blogPost);
                blogPost.StartDateUtc = model.StartDate;
                blogPost.EndDateUtc   = model.EndDate;
                blogPost.Stores       = model.SelectedStoreIds != null?model.SelectedStoreIds.ToList() : new List <string>();

                _blogService.UpdateBlogPost(blogPost);

                //search engine name
                var seName = blogPost.ValidateSeName(model.SeName, model.Title, true);
                blogPost.SeName  = seName;
                blogPost.Locales = UpdateLocales(blogPost, model);
                _blogService.UpdateBlogPost(blogPost);
                _urlRecordService.SaveSlug(blogPost, seName, "");

                //delete an old picture (if deleted or updated)
                if (!String.IsNullOrEmpty(prevPictureId) && prevPictureId != blogPost.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                    {
                        _pictureService.DeletePicture(prevPicture);
                    }
                }

                //update picture seo file name
                UpdatePictureSeoNames(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);
            //Store
            PrepareStoresMappingModel(model, blogPost, true);
            //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));
        }
Example #14
0
        public ActionResult Edit(BlogPostModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
                return AccessDeniedView();

            var blogPost = _blogService.GetBlogPostById(model.Id);
            if (blogPost == null)
                //No blog post found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                blogPost = model.ToEntity(blogPost);
                blogPost.StartDateUtc = model.StartDate;
                blogPost.EndDateUtc = model.EndDate;
                _blogService.UpdateBlogPost(blogPost);

                //search engine name
                var seName = blogPost.ValidateSeName(model.SeName, model.Title, true);
                _urlRecordService.SaveSlug(blogPost, seName, blogPost.LanguageId);

                //Stores
                SaveStoreMappings(blogPost, model);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Blog.BlogPosts.Updated"));
                return continueEditing ? RedirectToAction("Edit", new { id = blogPost.Id }) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form
            ViewBag.AllLanguages = _languageService.GetAllLanguages(true);
            //Store
            PrepareStoresMappingModel(model, blogPost, true);
            return View(model);
        }