Пример #1
0
        public async Task <IActionResult> EditComment(UpdateCommentViewModel comment)
        {
            var commentDto = await _commentManager.GetComment(comment.Id);

            if (commentDto == null)
            {
                return(NotFound());
            }
            var model = Mapper.Map <UpdateCommentViewModel>(commentDto);

            return(View(model));
        }
        public async Task <ActionResult> Comment(NewIssueCommentVM model, string Connection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.CommentBody = HttpUtility.HtmlEncode(model.CommentBody);
                    var comment = new CommentVM
                    {
                        CommentBody = model.CommentBody,
                        IssueId     = model.IssueID,
                        Author      = new UserDto {
                            Id = UserID
                        }
                    };

                    var commentId = commentManager.SaveComment(comment);

                    var newCommentVm = commentManager.GetComment(commentId);
                    var context      = GlobalHost.ConnectionManager.GetHubContext <IssuesHub>();

                    //Send to all other users except the Author.
                    newCommentVm.IsOwner = false;
                    string[] excludedConn = new string[] { Connection };
                    context.Clients.Groups(new string[] { TeamID.ToString() }, excludedConn).addNewComment(newCommentVm);

                    //For Sending to the author
                    newCommentVm.IsOwner = true;

                    await commentManager.SendEmailNotificaionForNewComment(comment);

                    return(Json(new { Status = "Success", Data = newCommentVm }));
                }
                return(Json(new { Status = "Error" }));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(Json(new { Status = "Error" }));
            }
        }
        public async Task <HttpResponseMessage> DeleteComment(int id)
        {
            try
            {
                var comment = commentManager.GetComment(id);
                if (comment != null && userSessionHelper.UserId == comment.Author.Id)
                {
                    await commentManager.Delete(id);

                    return(Request.CreateResponse(HttpStatusCode.OK, new
                    {
                        Status = "Success"
                    }));
                }
            }
            catch (Exception ex)
            {
                ErrorStore.LogException(ex, System.Web.HttpContext.Current);
            }
            return(Request.CreateResponse(HttpStatusCode.OK, new
            {
                Status = "Error"
            }));
        }