Ejemplo n.º 1
0
        public IActionResult UpdateBlogPostCategory(BlogPostCategoryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try {
                var category = _blogService.GetBlogPostCategoryById(model.CategoryId);
                if (category == null)
                {
                    ModelState.AddModelError("", "Invalid blog post category id specified");
                    return(View(model));
                }

                category.Name        = model.Name;
                category.Slug        = model.Slug;
                category.Description = model.Description;

                _blogService.UpdateBlogPostCategory(category);
                _activityService.InsertActivity(_workContext.CurrentUser, ActivityLogDefaults.EditBlogPostCategory, "Updated blog post category: {0} - {1}", model.CategoryId, model.Name);

                ViewBag.Status  = "OK";
                ViewBag.Message = "Your changes have been saved successfully.";
            }
            catch (Exception ex) {
                ModelState.AddModelError("", $"Unable to update blog post category: {ex.Message}");
                _logService.InsertLog(LogLevel.Error, ex.Message, ex.ToString());
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public IActionResult Categories()
        {
            var model = new BlogPostCategoryViewModel()
            {
                BlogPostCategories = _blogService.GetBlogPostCategories(),
                PostAction         = "categories"
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public IActionResult UpdateBlogPostCategory(int id)
        {
            var blogPostCategory = _blogService.GetBlogPostCategoryById(id);

            if (blogPostCategory == null)
            {
                return(RedirectToAction("categories"));
            }

            var model = new BlogPostCategoryViewModel()
            {
                PostAction  = "UpdateBlogPostCategory",
                Name        = blogPostCategory.Name,
                Slug        = blogPostCategory.Slug,
                Description = blogPostCategory.Description,
                CategoryId  = id
            };

            return(View(model));
        }
Ejemplo n.º 4
0
        public IActionResult Categories(BlogPostCategoryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try {
                _blogService.CreateBlogPostCategory(model.Name, model.Slug, model.Description);
                _activityService.InsertActivity(_workContext.CurrentUser, ActivityLogDefaults.AddBlogPostCategory, "Created new blog post category: {0}", model.Name);

                ViewBag.Status  = "OK";
                ViewBag.Message = "New blog post category successfully added";

                model.BlogPostCategories = _blogService.GetBlogPostCategories();
                model.PostAction         = "categories";
            }
            catch (Exception ex) {
                ModelState.AddModelError("", $"Unable to create new blog post category: {ex.Message}");
                _logService.InsertLog(LogLevel.Error, ex.Message, ex.ToString());
            }

            return(View(model));
        }