Ejemplo n.º 1
0
        public OperationResult Edit(EditArticleVM command)
        {
            OperationResult result = new OperationResult();

            var article = _articleRepository.Get(command.Id);

            if (article == null)
            {
                return(result.Failed(ValidateMessage.IsExist));
            }

            if (_articleRepository.IsExist(a => a.Title == command.Title && a.Id != command.Id))
            {
                return(result.Failed(ValidateMessage.IsDuplicated));
            }

            var slug         = command.Slug.Slugify();
            var categorySlug = _categoryRepository.GetCategorySlugBy(command.CategoryId);
            var path         = $"{categorySlug}/{slug}";
            var pictureName  = Uploader.ImageUploader(command.PictureName, path, article.PictureName);

            article.Edit(command.Title, command.CategoryId, pictureName, command.PictureAlt,
                         command.PictureTitle, command.PublishDate.ToGeorgianDateTime(), command.ShortDescription,
                         command.Description, slug, command.Keywords, command.MetaDescription, command.CanonicalUrl);
            _articleRepository.SaveChanges();

            return(result.Succeeded());
        }
Ejemplo n.º 2
0
        public ActionResult Edit(EditArticleVM model)
        {
            if (ModelState.IsValid)
            {
                var dict = new Dictionary <string, string>();
                dict.Add(ArticlesFields.ThemeID, Convert.ToString(model.ThemeID));
                dict.Add(ArticlesFields.Title, Convert.ToString(model.Title));
                dict.Add(ArticlesFields.Content, Convert.ToString(model.Content));
                this.repos.UpdateArticles(dict, model.ArticleID);
                return(View("Index", "Article", model.ArticleID));
            }

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 3
0
        public IActionResult OnPost(EditArticleVM model)
        {
            Categories = new SelectList(_categoryApplication.GetAllForSearch(), "Id", "Name");
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var result = _articleApplication.Edit(model);

            if (result.IsSucceeded)
            {
                return(RedirectToPage("Index"));
            }

            return(Page());
        }