Esempio n. 1
0
        public BsJsonResult ReturnDraft(DraftVm draft)
        {
            Article   model     = null;
            CustomUrl customUrl = null;

            if (ModelState.IsValid)
            {
                var article = _articleService.GetById(draft.Id);
                model = Mapper.Map(draft, article);
                model.ArticleState = ArticleState.ReturnedDraft;
                customUrl          = CreateOrUpdateCustomUrl(draft);
            }

            if (!ModelState.IsValid)
            {
                ModelState.AddFormError("Ошибка: ",
                                        "Поля заполнены не верно. Черновик не был сохранен и не может быть возвращен.");

                return(new BsJsonResult(
                           new Dictionary <string, object> {
                    { "Errors", ModelState.GetErrors() }
                },
                           BsResponseStatus.ValidationError));
            }

            _articleService.Update(model);
            if (customUrl != null)
            {
                _customUrlService.CreateOrUpdate(customUrl);
            }

            return(new BsJsonResult(new { Status = BsResponseStatus.Success }));
        }
Esempio n. 2
0
        public BsJsonResult SaveDraft(DraftVm draft)
        {
            string    errorText = null;
            string    indexHtml = null;
            Article   model     = null;
            CustomUrl customUrl = null;

            if (ModelState.IsValid)
            {
                var article = _articleService.GetById(draft.Id);
                model = Mapper.Map(draft, article);


                customUrl = CreateOrUpdateCustomUrl(draft);

                if (model.ArticleState == ArticleState.New)
                {
                    model.ArticleState = ArticleState.Draft;
                }

                if (model.ArticleState == ArticleState.Article)
                {
                    if (!_htmlParserHelper.GetIndexHtmlFromArticleText(model.Text, out indexHtml))
                    {
                        errorText = "Статья не содержит линии разрыва печати. Без неё публиковать нельзя!";
                    }
                }
            }

            if (!ModelState.IsValid)
            {
                errorText = "Поля заполнены не верно. Черновик не был сохранен.";
            }

            if (errorText != null)
            {
                ModelState.AddFormError("Ошибка: ", errorText);

                return(new BsJsonResult(
                           new Dictionary <string, object> {
                    { "Errors", ModelState.GetErrors() }
                },
                           BsResponseStatus.ValidationError));
            }

            model.IndexHtml = indexHtml;
            _articleService.Update(model);
            //TODO: remove (temporary for output cache)
            MemoryCacheHelper.ArticlesUpdateTime = DateTime.Now;
            if (customUrl != null)
            {
                _customUrlService.CreateOrUpdate(customUrl);
            }

            return(new BsJsonResult(new { Status = BsResponseStatus.Success }));
        }
Esempio n. 3
0
        private void InitViewModel(DraftVm vm)
        {
            vm.Sections = new SelectList(_sectionService.GetActiveSections(), "Id", "Name");

            var customUrl = _customUrlService.GetAll().FirstOrDefault(x => x.ContentId == vm.Id && x.ContentType == ContentType.Article);

            if (customUrl != null)
            {
                vm.SeoUrl = customUrl.Url;
            }
        }
Esempio n. 4
0
        public ActionResult Draft(int id)
        {
            Article model = _articleService.GetById((int)id);

            if (model.AuthorId != User.Identity.GetUserId())
            {
                throw new SecurityException("User is not authorized to open this record");
            }


            DraftVm vm = Mapper.Map <Article, DraftVm>(model);

            InitViewModel(vm);

            var options = new Dictionary <string, string>
            {
                { "saveDraftUrl", Url.Action("SaveDraft") },
                { "postUrl", Url.Action("PostDraft") },
                { "successUrl", Url.Action("PostSuccess") },
                { "returnUrl", Url.Action("ReturnDraft") },
                { "submitUrl", Url.Action("PublishDraft") },
                { "changesUrl", Url.Action("ProposeChanges") }
            };

            RequireJsOptions.Add("index", options);

            if (_articleService.IsDraft(model) || model.ArticleState == ArticleState.New)
            {
                ViewBag.SuccessText = "Черновик был успешно сохранен";
            }
            else if (_articleService.IsPublished(model))
            {
                ViewBag.SuccessText = "Публикация успешно изменена";
            }
            else if (_articleService.IsPosted(model))
            {
                ViewBag.SuccessText = "Успешно!";
            }

            return(View(vm));
        }
Esempio n. 5
0
        private CustomUrl CreateOrUpdateCustomUrl(DraftVm draft)
        {
            var customUrl = _customUrlService.GetAll().FirstOrDefault(x => x.ContentId == draft.Id && x.ContentType == ContentType.Article);

            if (customUrl == null && !string.IsNullOrEmpty(draft.SeoUrl))
            {
                customUrl = new CustomUrl();
            }

            if (customUrl != null && customUrl.Url != draft.SeoUrl)
            {
                if (!_customUrlService.IsUniquePath(draft.SeoUrl))
                {
                    ModelState.AddModelError("SeoUrl", "Путь не уникален");
                    return(null);
                }
                customUrl.Url         = draft.SeoUrl;
                customUrl.ContentType = ContentType.Article;
                customUrl.ContentId   = draft.Id;
            }

            return(customUrl);
        }
Esempio n. 6
0
 public BsJsonResult ProposeChanges(DraftVm draft)
 {
     throw new NotImplementedException();
 }