Esempio n. 1
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 }));
        }
Esempio n. 2
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var actionParamentr = filterContext.ActionParameters.SingleOrDefault(p => p.Key == "id").Value.ToString();

            if (string.IsNullOrEmpty(actionParamentr))
            {
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {
                    { "controller", "Ticket" }, { "action", "AllTickets" }
                });
            }

            int ticketId       = Convert.ToInt32(actionParamentr);
            var userId         = HttpContext.Current.User.Identity.GetUserId();
            var isSubmitter    = HttpContext.Current.User.IsInRole("Submitter");
            var isDeveloper    = HttpContext.Current.User.IsInRole("Developer");
            var isAdminManager = HttpContext.Current.User.IsInRole("Admin") ||
                                 HttpContext.Current.User.IsInRole("ProjectManager");
            var ticket = bugTrackerHelper.GetCurrentTicketById(ticketId);

            if (ticket == null)
            {
                filterContext.Result = new ViewResult()
                {
                    ViewName = "ItemError"
                };
            }
            else
            {
                if (!isAdminManager)
                {
                    if ((ticket.AssignedToUserId != null && isDeveloper) || isDeveloper && (ticket.AssignedToUserId != userId))
                    {
                        filterContext.Result = new ViewResult()
                        {
                            ViewName = "AutorizationError"
                        }
                    }
                    ;

                    if (isSubmitter && (ticket.OwnerUserId != userId))
                    {
                        filterContext.Result = new ViewResult()
                        {
                            ViewName = "AutorizationError"
                        }
                    }
                    ;
                }
            }
        }
    }
}
Esempio n. 3
0
        private ActionResult SaveAttachment(int?id, int?attachmentId, CreateEditAttachmentViewModel formData)
        {
            if (formData.Media == null && attachmentId == null)
            {
                ModelState.AddModelError("FileURL", "Please upload file");
                return(View());
            }

            if (!ModelState.IsValid || !id.HasValue)
            {
                return(RedirectToAction("AllTickets", "Ticket"));
            }

            TicketAttachment attachment = new TicketAttachment();
            var ticket  = bugTrackerHelper.GetCurrentTicketById(id.Value);
            var message = notificationHelper.CreateAttachmentNotification(ticket.Title);

            if (attachmentId == null)
            {
                attachment.DateCreated = DateTime.Now;
                attachment.TicketId    = id.Value;
                attachment.UserId      = User.Identity.GetUserId();
                DbContext.TicketAttachments.Add(attachment);
                notificationHelper.SendNotification(ticket, message, false);
            }
            else
            {
                attachment = bugTrackerHelper.GetAttachmentById(attachmentId.Value);
            }

            attachment.Description = formData.Description;

            if (formData.Media.ContentLength > 2029152)
            {
                ModelState.AddModelError("IsMaxRequestExceededException", "The file's size cannot exсeed 2Mb");

                return(View());
            }

            FileUpload(attachment, formData);
            DbContext.SaveChanges();

            return(RedirectToAction("TicketDetails", "Ticket", new { id = attachment.TicketId }));
        }
        public ActionResult Alltickets(int?id, int?sendNotification)
        {
            var userId       = User.Identity.GetUserId();
            var ticket       = bugTrackerHelper.GetCurrentTicketById(id.Value);
            var notification = notificationHelper.GetNotificationByTicketUserIds(ticket.Id, userId);

            if (notification == null && sendNotification != null)
            {
                var ticketNotification = new TicketNotification();

                ticketNotification.TicketId = ticket.Id;
                ticketNotification.UserId   = userId;
                DbContext.TicketNotifications.Add(ticketNotification);
            }

            if (notification != null && sendNotification == null)
            {
                DbContext.TicketNotifications.Remove(notification);
            }

            DbContext.SaveChanges();

            return(RedirectToAction("AllTickets", "Ticket"));
        }