public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            try
            {
                var comment = await _commentsService.FindAsync(id.Value);

                if (comment != null && !comment.AuthorId.Equals(User.Identity.GetUserId()))
                {
                    return(RedirectToAction("Show/" + comment.PostId, "Posts"));
                }

                if (comment != null)
                {
                    await _commentsService.DeleteAsync(comment);
                }

                if (comment != null)
                {
                    return(RedirectToAction("Show/" + comment.PostId, "Posts"));
                }
            }
            catch
            {
                //ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }

            return(RedirectToAction("Index", "Posts"));
        }
        public async Task <IActionResult> Delete([FromRoute] long id, string slug)
        {
            Comment comment = await _commentService.FetchCommentByIdAsync(id);

            if (comment == null)
            {
                return(StatusCodeAndDtoWrapper.BuildGenericNotFound());
            }

            var result = await _authorizationService.AuthorizeAsync(User, comment,
                                                                    _configService.GetDeleteCommentPolicyName());

            if (result.Succeeded)
            {
                if ((await _commentService.DeleteAsync(id)) > 0)
                {
                    return(StatusCodeAndDtoWrapper.BuildSuccess("Comment deleted successfully"));
                }
                else
                {
                    return(StatusCodeAndDtoWrapper.BuildErrorResponse("An error occured, try later"));
                }
            }
            else
            {
                throw new PermissionDeniedException();
            }
        }
Example #3
0
        public async Task <ActionResult <IEnumerable <Comment> > > DeleteAsync([FromRoute] string id)
        {
            if (await commentService.GetByIdAsync(id) == null)
            {
                return(NotFound());
            }

            await commentService.DeleteAsync(id);

            return(Ok());
        }
 public virtual async Task <ActionResult> Delete(int[] keys)
 {
     try
     {
         foreach (var key in keys)
         {
             await _commentsService.DeleteAsync(key);
         }
         return(Content("OK"));
     }
     catch (Exception e)
     {
         var errorCode = ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Error(e, System.Web.HttpContext.Current));
         return(Content(string.Format(_localizationService.GetResource("ErrorOnOperation"), e.Message, errorCode)));
     }
 }
Example #5
0
        public async Task <IActionResult> DeleteAsync([FromRoute] int id)
        {
            var comment = await _commentService.GetCommentAsync(id);

            if (comment == null)
            {
                return(NotFound());
            }

            await _commentService.DeleteAsync(comment);

            var response = new CreatedResponse <int> {
                Id = id
            };

            return(Ok(response));
        }
Example #6
0
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            try
            {
                await _commentsService.DeleteAsync(id.Value);

                return(RedirectToAction("Index"));
            }
            catch
            {
                //ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }
            return(RedirectToAction("Index"));
        }
Example #7
0
        public async Task <IActionResult> Delete(CommentModifyInputModel modifiedModel, string onSubmitAction)
        {
            if (onSubmitAction.IsNullOrEmpty() || onSubmitAction == "Cancel")
            {
                return(RedirectToAction(nameof(All)));
            }

            if (!ModelState.IsValid)
            {
                return(View(modifiedModel));
            }

            try
            {
                await _commentsService.DeleteAsync(modifiedModel.Id);
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"An exception occured during comment DELETE operation for commentId: {modifiedModel.Id}.");
                return(RedirectToAction("Error", "Home"));
            }

            return(RedirectToAction(nameof(All)));
        }
Example #8
0
        /// <inheritdoc cref="IUploadFromFileService"/>
        public async Task <ResultDto> UploadCommentsFromExcel(Stream inputStream, string currentUserId)
        {
            var resultDto = new ResultDto();

            var commentsToCreate = new List <Comment>();
            var commentsToEdit   = new List <Comment>();
            var commentsToDelete = new List <Comment>();

            var posts = await _postsService.GetAllAsync();

            var comments = await _commentsService.GetAllAsync();

            var workSheet = WorkSheetUsedRows(inputStream, "Comments");

            if (!workSheet.Success)
            {
                resultDto.ExceptionMessage = workSheet.ExceptionMessage;

                return(resultDto);
            }

            foreach (var row in workSheet.Rows)
            {
                var item = new CommentDto(row);

                var post = posts.FirstOrDefault(x => x.Title.ToLower().Equals(item.PostTitle.ToLower()));
                int postId;
                if (post == null)
                {
                    continue;
                }

                postId = post.Id;
                var comment = comments.FirstOrDefault(x =>
                                                      x.CommentBody.ToLower().Equals(item.CommentBody) && x.PostId == postId);


                if (row.Cell(3).Value.ToString().TrimStart(' ').TrimEnd(' ').ToLower().Equals("edit") && comment != null)
                {
                    comment.CommentBody = item.CommentBody;
                    commentsToEdit.Add(comment);
                }
                else if (row.Cell(7).Value.ToString().TrimStart(' ').TrimEnd(' ').ToLower().Equals("delete") &&
                         comment != null)
                {
                    commentsToDelete.Add(comment);
                }
                else
                {
                    var newComment = _mapper.Map <CommentDto, Comment>(item);
                    newComment.AuthorId = currentUserId;
                    newComment.PostId   = postId;
                    commentsToCreate.Add(newComment);
                }
            }

            if (commentsToCreate.Count > 0)
            {
                await _commentsService.InsertAsync(commentsToCreate);
            }

            if (commentsToEdit.Count > 0)
            {
                await _commentsService.UpdateAsync(commentsToEdit);
            }

            if (commentsToDelete.Count > 0)
            {
                await _commentsService.DeleteAsync(commentsToDelete);
            }

            resultDto.Success = true;

            return(resultDto);
        }
 public async Task Delete(int id)
 {
     await _commentsService.DeleteAsync(id);
 }
 public async Task Delete(Guid id)
 {
     await service.DeleteAsync(id);
 }
Example #11
0
        public virtual async Task <ActionResult> DeleteComment(int commentId)
        {
            await _commentsService.DeleteAsync(commentId);

            return(Json(new { response = "OK" }));
        }