コード例 #1
0
        public async Task <IActionResult> UpdateCommentaryAsync([Required] CommentaryEditinigModel model)
        {
            if (ModelState.IsValid)
            {
                var currentUser = await S.UserManager.GetUserAsync(User);

                var commentary = await S.Db.Commentaries
                                 .Include(c => c.Post)
                                 .FirstOrDefaultAsync(c => c.Id == model.CommentaryId);

                await S.Permissions.ValidateEditCommentaryAsync(commentary);

                var user = await S.UserManager.GetUserAsync(User);

                commentary.Body = model.Body;
                commentary.Edits.Add(new CommentaryEdit(user, model.Reason, DateTime.UtcNow));
                await S.Repository.AddUserActionAsync(currentUser, new UserAction(ActionType.COMMENTARY_EDIT, commentary));

                await S.Db.SaveChangesAsync();

                await S.CacheManager.ResetPostPageCacheAsync(commentary.Post.Id);
            }
            else
            {
                if (model.Reason == null)
                {
                    LayoutModel.AddMessage("Edit reason is required");
                }
                else if (model.Body == null)
                {
                    LayoutModel.AddMessage("Commentary body is required");
                }
                else
                {
                    throw new Exception();
                }
            }

            return(Redirect(S.History.GetLastURL()));
        }
コード例 #2
0
        public async Task <IActionResult> GetCommentaryEditAsync([Required] int id)
        {
            if (ModelState.IsValid)
            {
                var commentary = await S.Db.Commentaries.AsNoTracking()
                                 .Include(c => c.Author)
                                 .FirstOrDefaultAsync(c => c.Id == id);

                var model = new CommentaryEditinigModel()
                {
                    Author       = commentary.Author.UserName,
                    AuthorId     = commentary.Author.Id,
                    Body         = commentary.Body,
                    CommentaryId = commentary.Id,
                };

                return(PartialView(Partials.COMMENTARY_EDIT, model));
            }
            else
            {
                throw new Exception();
            }
        }