public ActionResult Create(ArticleCategoryModel viewModel)
        {
            var strMessage = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {
                    #region Current User

                    var userName = HttpContext.User.Identity.Name;
                    viewModel.IUser = userName;
                    viewModel.IDate = DateTime.Now;
                    viewModel.EDate = DateTime.Now;

                    #endregion

                    var entity = viewModel.ToEntity();
                    _sdArtCategoryService.INVUnit.ArticleCategoryRepository.Add(entity);
                    _sdArtCategoryService.INVUnit.ArticleCategoryRepository.SaveChanges();

                    return(Content(Boolean.TrueString));
                    //return Content("Information has been saved successfully");
                }

                strMessage = Common.GetModelStateErrorMessage(ModelState);
            }
            catch (Exception ex)
            {
                strMessage = CommonExceptionMessage.GetExceptionMessage(ex, CommonAction.Save);
            }

            return(Content(strMessage));
        }
        public ActionResult Edit(ArticleCategoryModel viewModel)
        {
            var strMessage = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {
                    var model = _sdArtCategoryService.INVUnit.ArticleCategoryRepository.GetByID(viewModel.Id);

                    #region Current User

                    viewModel.IUser = model.IUser;
                    viewModel.IDate = model.IDate;

                    var userName = HttpContext.User.Identity.Name;
                    viewModel.EUser = userName;
                    viewModel.EDate = DateTime.Now;

                    #endregion

                    var entity = viewModel.ToEntity();

                    _sdArtCategoryService.INVUnit.ArticleCategoryRepository.Update(entity);
                    _sdArtCategoryService.INVUnit.ArticleCategoryRepository.SaveChanges();

                    return(Content(Boolean.TrueString));
                }

                strMessage = Common.GetModelStateErrorMessage(ModelState);
            }
            catch (Exception ex)
            {
                strMessage = CommonExceptionMessage.GetExceptionMessage(ex, CommonAction.Update);
            }

            return(Content(strMessage));
        }
Пример #3
0
        public ActionResult Edit(ArticleCategoryModel model, bool continueEditing, bool continueCreate, FormCollection form)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }
            var category = _categoryService.GetArticleCategoryById(model.Id);

            if (category == null)
            {
                //No category found with the specified id
                return(RedirectToAction("List"));
            }
            if (ModelState.IsValid)
            {
                int prevPictureId = category.PictureId.GetValueOrDefault();
                category = model.ToEntity(category);
                category.AddEntitySysParam(false, true);
                if (category.ParentCategoryId != 0 && category.ChannelId == 0)
                {
                    category.ChannelId = _categoryService.GetArticleCategoryById(category.ParentCategoryId).ChannelId;
                }

                model.SeName = category.ValidateSeName(model.SeName, category.Name, true);
                _urlRecordService.SaveSlug(category, model.SeName, 0);
                //locales
                UpdateLocales(category, model);
                //delete an old picture (if deleted or updated)
                if (prevPictureId > 0 && prevPictureId != category.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                    {
                        _pictureService.DeletePicture(prevPicture);
                    }
                }
                //update picture seo file name
                UpdatePictureSeoNames(category);

                //ACL
                UpdateCategoryAcl(category, model);

                //SiteMap
                UpdateSiteMappings(category, model);

                _categoryService.UpdateArticleCategory(category);

                _eventPublisher.Publish(new ModelBoundEvent(model, category, form));

                NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.ArticleCategorys.Updated"));
                if (continueCreate)
                {
                    return(RedirectToAction("Create", new { channelId = model.ChannelId }));
                }
                return(continueEditing ? RedirectToAction("Edit", new { id = category.Id }) : RedirectToAction("Center", new { channelId = model.ChannelId }));
            }


            //parent categories
            if (model.ParentCategoryId.HasValue)
            {
                var parentCategory = _categoryService.GetArticleCategoryById(model.ParentCategoryId.Value);
                if (parentCategory != null && !parentCategory.Deleted)
                {
                    model.ParentCategoryBreadcrumb = parentCategory.GetCategoryBreadCrumb(_categoryService);
                }
                else
                {
                    model.ParentCategoryId = 0;
                }
            }
            //templates
            PrepareTemplatesModel(model);
            //channel
            PrepareChannelsModel(model);
            PrepareCategoryModel(model, category);
            //ACL
            PrepareAclModel(model, category, true);
            //Sites
            PrepareSitesMappingModel(model, category, true);
            return(View(model));
        }
Пример #4
0
        public ActionResult Create(ArticleCategoryModel model, bool continueEditing, bool continueCreate, FormCollection form)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }
            if (ModelState.IsValid)
            {
                var category = model.ToEntity();
                if (category.ParentCategoryId != 0 && category.ChannelId == 0)
                {
                    category.ChannelId = _categoryService.GetArticleCategoryById(category.ParentCategoryId).ChannelId;
                }
                category.AddEntitySysParam();
                _categoryService.InsertArticleCategory(category);
                //search engine name
                model.SeName = category.ValidateSeName(model.SeName, category.Name, true);
                _urlRecordService.SaveSlug(category, model.SeName, 0);

                //locales
                UpdateLocales(category, model);

                //update picture seo file name
                UpdatePictureSeoNames(category);

                //ACL (customer roles)
                UpdateCategoryAcl(category, model);

                //SiteMap
                UpdateSiteMappings(category, model);

                _categoryService.UpdateArticleCategory(category);


                _eventPublisher.Publish(new ModelBoundEvent(model, category, form));

                //activity log
                _userActivityService.InsertActivity("AddNewArticleCategory", _localizationService.GetResource("ActivityLog.AddNewArticleCategory"), category.Name);


                NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.ArticleCategorys.Added"));
                if (continueCreate)
                {
                    return(RedirectToAction("Create", new { channelId = model.ChannelId }));
                }

                return(continueEditing ? RedirectToAction("Edit", new { id = category.Id }) : RedirectToAction("Center", new { channelId = model.ChannelId }));
            }
            //templates
            PrepareTemplatesModel(model);
            //channel
            PrepareChannelsModel(model);
            //parent categories
            if (model.ParentCategoryId.HasValue)
            {
                var parentCategory = _categoryService.GetArticleCategoryById(model.ParentCategoryId.Value);
                if (parentCategory != null && !parentCategory.Deleted)
                {
                    model.ParentCategoryBreadcrumb = parentCategory.GetCategoryBreadCrumb(_categoryService);
                }
                else
                {
                    model.ParentCategoryId = 0;
                }
            }

            PrepareCategoryModel(model, null);
            //ACL
            PrepareAclModel(model, null, true);
            //Sites
            PrepareSitesMappingModel(model, null, true);
            return(View(model));
        }