public async Task <ActionResult> _EditComment(CreateEditCommentViewModel formData)
        {
            if (formData == null)
            {
                return(RedirectToAction("AllTickets", "Tickets"));
            }

            var comment       = DbContext.Comments.FirstOrDefault(p => p.Id == formData.CommentId);
            var ticket        = DbContext.Tickets.FirstOrDefault(p => p.Id == formData.TicketId);
            var currentUserId = User.Identity.GetUserId();
            var currentUser   = DbContext.Users.FirstOrDefault(p => p.Id == currentUserId);

            if (comment == null || ticket == null || ticket.Project.Archived == true || formData.CommentData == null || (comment.CommentCreatorId != currentUserId && !User.IsInRole("Admin") && !User.IsInRole("Project Manager")))
            {
                return(RedirectToAction("AllTickets", "Tickets"));
            }

            comment.CommentData = formData.CommentData;
            comment.DateUpdated = DateTime.Now;

            DbContext.SaveChanges();

            await RolesAndUsersHelper.MassEmailSender(ticket.Id, "Modify");

            return(RedirectToAction("ViewTicket", "Tickets", new { id = ticket.Id }));
        }
        public ActionResult _EditComment(string commentId)
        {
            if (commentId == null)
            {
                return(RedirectToAction("AllTickets", "Tickets"));
            }

            var currentUserId = User.Identity.GetUserId();
            var currentUser   = DbContext.Users.FirstOrDefault(p => p.Id == currentUserId);
            var comment       = DbContext.Comments.FirstOrDefault(p => p.Id == commentId);
            var ticket        = DbContext.Tickets.FirstOrDefault(p => p.Comments.Any(r => r.Id == comment.Id));

            if (currentUser == null || comment == null || ticket == null || ticket.Project.Archived == true || (comment.CommentCreatorId != currentUserId && !User.IsInRole("Admin") && !User.IsInRole("Project Manager")))
            {
                return(RedirectToAction("AllTickets", "Tickets"));
            }

            var model = new CreateEditCommentViewModel();

            model.CommentData = comment.CommentData;
            model.CommentId   = comment.Id;
            model.TicketId    = ticket.Id;

            return(View(model));
        }
Example #3
0
        private ActionResult SaveComment(int?id, int?commentId, CreateEditCommentViewModel formData)
        {
            if (!ModelState.IsValid || !id.HasValue)
            {
                return(RedirectToAction("AllTickets", "Ticket"));
            }

            TicketComment comment = new TicketComment();
            var           ticket  = bugTrackerHelper.GetCurrentTicketById(id.Value);
            var           message = notificationHelper.CreateCommentNotification(ticket.Title);

            if (commentId == null)
            {
                comment.DateCreated = DateTime.Now;
                comment.TicketId    = id.Value;
                comment.UserId      = User.Identity.GetUserId();
                DbContext.TicketComments.Add(comment);
                notificationHelper.SendNotification(ticket, message, false);
            }
            else
            {
                comment = bugTrackerHelper.GetCommentById(commentId.Value);
            }

            comment.Comment = formData.Comment;
            DbContext.SaveChanges();

            return(RedirectToAction("TicketDetails", "Ticket", new { id = comment.TicketId }));
        }
Example #4
0
        public ActionResult EditComment(int?id, int?commentId)
        {
            var model   = new CreateEditCommentViewModel();
            var comment = bugTrackerHelper.GetCommentById(commentId.Value);

            model = Mapper.Map <CreateEditCommentViewModel>(comment);

            return(View(model));
        }
Example #5
0
        public async Task <IActionResult> PostComment(CreateEditCommentViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var response = await _commentService.CreatePost(vm);

                if (response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync();

                    var model = json.JsonToObj <CommentViewModel>();

                    return(PartialView("~/Views/Memory/_MemoryComment.cshtml", model));
                }

                return(Json(response.GetErrors()));
            }

            return(BadRequest(ModelState));
        }
Example #6
0
 public ActionResult EditComment(int?id, int?commentId, CreateEditCommentViewModel formData)
 {
     return(SaveComment(id, commentId, formData));
 }
Example #7
0
 public ActionResult CreateComment(int?id, CreateEditCommentViewModel formData)
 {
     return(SaveComment(id, null, formData));
 }
Example #8
0
 public async Task <HttpResponseMessage> CreatePost(CreateEditCommentViewModel vm)
 {
     return(await _oppJarProxy.PostAsJsonAsync(CREATE_COMMENT, vm));
 }
Example #9
0
        public virtual async Task OnGetAsync()
        {
            var dto = await _service.GetAsync(Id);

            ViewModel = ObjectMapper.Map <CommentDto, CreateEditCommentViewModel>(dto);
        }