Esempio n. 1
0
        public async Task <IActionResult> PutComment(int id, CommentRecordViewModel comment)
        {
            // var currentUserId = _userManager.GetUserId(User);

            comment.Modified = DateTime.Now;
            ModelState.Remove("Modified");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // CommentRecord commentModel = await _context.Comment.SingleOrDefaultAsync(c => c.Id == comment.Id);
            var commentModel = await _commentRepository.FindByIdAsync(id);

            if (id != comment.Id || commentModel == null)
            {
                return(BadRequest());
            }

            commentModel.Content    = comment.Content;
            commentModel.UpdatedUtc = DateTime.Now;
            commentModel.Pings      = comment.Pings != null?string.Join(",", comment.Pings) : null;

            //  _context.Entry(commentModel).State = EntityState.Modified;
            // CreateTransaction(comment, currentUserId, CommentTransactionType.Edit);

            try
            {
                //await _context.SaveChangesAsync();
                await _commentRepository.UpdateAsync(commentModel);
            }
            catch (Exception)
            {
                if (!(await CommentExists(id)))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(comment));
        }
        public async Task <IActionResult> Edit(CommentRecordViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Intelli.Comments.Permissions.ManageComments))
            {
                return(Unauthorized());
            }

            var commentRecord = await _commentsRepository.FindByIdAsync(model.Id);

            commentRecord.Content = model.Content;

            await _commentsRepository.UpdateAsync(commentRecord);

            //  await _session.CommitAsync();
            _notifier.Success(H["Comment has been saved."]);
            return(RedirectToAction(nameof(Edit), new { id = model.Id }));
        }