public async Task <IActionResult> DeleteComment(int id) { // string currentUserId = _userManager.GetUserId(User); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //CommentRecord comment = await _context.Comment.SingleOrDefaultAsync(m => m.Id == id); // CommentRecord comment = await _commentRepository.FindAsync(id); // var notification = _context.Notification.Where(m => m.CommentId == id);//delete commment notifications // if (comment == null) // { // return NotFound(); // } var record = await _commentRepository.FindByIdAsync(id); // _context.Comment.Remove(comment); await _commentRepository.DeleteAsync(record); // if (notification != null) // { // _context.Notification.RemoveRange(notification); // } // CreateTransaction(comment, currentUserId, CommentTransactionType.Delete); // await _context.SaveChangesAsync(); return(Ok(id)); }
public async Task <IActionResult> BulkEdit(BulkAction bulkAction, PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Intelli.Comments.Permissions.ManageComments)) { return(Unauthorized()); } var viewModel = new CommentsIndexViewModel { Comments = new List <CommentRecord>(), Options = new SearchIndexOptions() }; if (!(await TryUpdateModelAsync(viewModel))) { return(View(viewModel)); } //todo create viewmodel with ischecked property var checkedEntries = viewModel.Comments.Take(1); // viewModel.Comments.Where(t => t.IsChecked); switch (bulkAction) { case BulkAction.None: break; case BulkAction.Delete: foreach (var entry in checkedEntries) { var commentRecord = await _commentsRepository.FindByIdAsync(entry.Id); if (commentRecord != null) { await _commentsRepository.DeleteAsync(commentRecord); _notifier.Success(H["Comment {0} has been deleted.", commentRecord.Content]); } } break; default: throw new ArgumentOutOfRangeException(); } return(RedirectToAction("Index", new { page = pagerParameters.Page, pageSize = pagerParameters.PageSize })); }