Exemplo n.º 1
0
        public ActionResult Edit(UpdateArticleModel model, int id)
        {
            if (ModelState.IsValid)
            {
                var img = FileManage.UploadOneFile();

                var r = YunClient.Instance.Execute(new UpdateArchiveRequest
                {
                    Id         = id,
                    Title      = model.Title,
                    Detail     = model.Detail,
                    Sort       = model.Sort,
                    CategoryId = model.Categoryid.TryTo(0),
                    Tags       = model.Tags,
                    PostMeta   = string.IsNullOrEmpty(model.Summary) ? null : string.Format("summary:{0}", model.Summary),
                    Status     = model.Status,
                    Image      = string.IsNullOrEmpty(img) ? model.Image : img,
                    PostTime   = model.PostTime.ToUnix()
                }, Token);

                if (r.Result)
                {
                    TempData["success"] = "文章保存成功";
                    return(RedirectToAction("Index"));
                }
            }

            TempData["error"] = "修改文章失败";
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <Article> UpdateArticle(UpdateArticleModel updateArticle, string slug, string token)
        {
            var user = ServiceProvider.GetRequiredService <UserService>().GetCurrentUser(token);

            if (user == null)
            {
                throw new ApplicationException("Not logged in.");
            }

            var existing = Context.FullArticles
                           .FirstOrDefault(a => a.Slug == slug);

            if (existing == null)
            {
                throw new ApplicationException("Not found.");
            }

            existing.Body        = updateArticle.Body ?? existing.Body;
            existing.Title       = updateArticle.Title ?? existing.Title;
            existing.Description = updateArticle.Description ?? existing.Description;
            existing.UpdatedAt   = DateTime.UtcNow;
            existing.Slug        = HttpUtility.UrlEncode($"{user.Username}_{existing.Title}");

            Context.Update(existing);

            var count = await Context.SaveChangesAsync();

            return(count == 1
                ? existing
                : null);
        }
Exemplo n.º 3
0
        private void PrepareArticleEdition()
        {
            var article = _articleService.GetArticleById(Id);

            UpdateArticleModel = new UpdateArticleModel
            {
                Title             = article.Title,
                Content           = article.Content,
                ArticleCategoryId = article.ArticleCategoryId
            };
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Update(Guid id, UpdateArticleModel model)
        {
            var command = new UpdateArticleCommand
            {
                ArticleId = id,
                Title     = model.Title,
                Text      = model.Text
            };

            await _mediator.Send(command);

            return(NoContent());
        }
Exemplo n.º 5
0
        public async Task UpdateArticle(UpdateArticleModel updateModel)
        {
            var article = _db.Article.SingleOrDefault(a => a.ArticleId == updateModel.ArticleId);

            if (article == null)
            {
                throw new ArgumentNullException();
            }

            article.Title             = updateModel.Title;
            article.Content           = updateModel.Content;
            article.ArticleCategoryId = updateModel.ArticleCategoryId;

            await _db.SaveChangesAsync();
        }
Exemplo n.º 6
0
        public async Task UpdateArticle(int articleId, UpdateArticleModel articleUpdateModel)
        {
            var article = context.Articles.FirstOrDefault(x => x.Id == articleId);

            article.Body       = articleUpdateModel.Body;
            article.Header     = articleUpdateModel.Header;
            article.TeaserText = articleUpdateModel.TeaserText;
            article.AuthorId   = articleUpdateModel.AuthorId;
            article.EditedDate = DateTime.Now;

            var entry = context.Entry(article);

            entry.State = EntityState.Modified;
            await context.SaveChangesAsync();
        }
Exemplo n.º 7
0
        public async Task <TResult> UpdateAsync <TResult>(UpdateArticleModel model)
        {
            var updatedEntity = this.mapper.Map <Article>(model);

            updatedEntity.ModifiedDateTime = DateTime.Now;

            this.articleRepository.Update(updatedEntity);
            await this.articleRepository.SaveAsync();

            var existedTags = await this.articleTagRepository.GetMany(x => x.ArticleId == model.Id).ToListAsync();

            this.articleTagRepository.DeleteRange(existedTags);

            //foreach (var tag in model.Tags)
            //{
            //    await this.articleTagRepository.AddAsync(new ArticleTag { ArticleId = model.Id, Tag = tag });
            //}

            return(await GetAsync <TResult>(updatedEntity.Id));
        }
        public ActionResult Update(UpdateArticleModel article)
        {
            if (!checkSession())
            {
                return(RedirectToAction("login", "users"));
            }
            ArticleDAO articleDAO = new ArticleDAO();

            if (articleDAO.UpdateArticle(article))
            {
                return(Json(new
                {
                    MESSAGE = "1"
                }));
            }
            else
            {
                return(Json(new
                {
                    MESSAGE = "0"
                }));
            }
            //return View();
        }
        public Task <Option <ArticleModel, Error> > UpdateAsync(string updatingUserId, string articleSlug, UpdateArticleModel model) =>
        GetUserByIdOrError(updatingUserId).FlatMapAsync(user =>
                                                        GetArticleBySlug(articleSlug)
                                                        .FilterAsync(async a => a.Author.Id == user.Id, "You must be the author in order to update an article.")
                                                        .FlatMapAsync(async article =>
        {
            Mapper.Map(model, article);

            article.TagList   = FromTagListToDbCollection(article, model.TagList);
            article.UpdatedAt = DateTime.UtcNow;
            DbContext.Update(article);

            await DbContext.SaveChangesAsync();

            return(await GetBySlugAsync(user.Id.Some(), articleSlug));
        }));