Exemple #1
0
        // GET: Tickets/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ticket ticket = db.Tickets.Find(id);

            if (ticket == null)
            {
                return(HttpNotFound());
            }
            var userId = User.Identity.GetUserId();

            if (!URManager.UserIsInRole(userId, "Administrator"))
            {
                if (!(ticket.Project.InChargeOfId == userId))
                {
                    if (!(ticket.AssignedToId == userId))
                    {
                        if (!(ticket.SubmitterId == userId))
                        {
                            return(RedirectToAction("Login", "Account"));
                        }
                    }
                }
            }

            if (ticket.TicketStatus.Name == "Resolved" && !User.IsInRole("Administrator"))
            {
                return(RedirectToAction("Login", "Account"));
            }

            ViewBag.NumberOfComments = ticket.TicketComments.Count;

            //definitely a better way to do this part. doesn't need to be stored in a database
            RelativeTime relativeTime = new RelativeTime();

            if (ticket.TicketComments != null && ticket.TicketComments.Any())
            {
                foreach (var comment in ticket.TicketComments)
                {
                    comment.TimeSincePosted = relativeTime.TimeAgo(comment.Created);
                    db.Entry(comment).Property("TimeSincePosted").IsModified = true;
                    db.SaveChanges();
                }
            }

            ViewBag.NumberOfAttachments = ticket.TicketAttachments.Count;

            if (ticket.TicketAttachments != null && ticket.TicketAttachments.Any())
            {
                foreach (var attachment in ticket.TicketAttachments)
                {
                    attachment.TimeSincePosted = relativeTime.TimeAgo(attachment.Created);
                    db.Entry(attachment).Property("TimeSincePosted").IsModified = true;
                    db.SaveChanges();
                }
            }

            ViewBag.NumberOfChanges = ticket.TicketHistoryEvents.Count - 4;

            TicketHistoryViewModel vm = new TicketHistoryViewModel();

            vm.Ticket             = ticket;
            vm.CreatedBy          = db.Users.Find(ticket.TicketHistoryEvents.ToList()[0].UserId);
            vm.CreatedId          = ticket.TicketHistoryEvents.ToList()[0].NewValue;
            vm.CreatedDescription = ticket.TicketHistoryEvents.ToList()[1].NewValue;
            vm.CreatedPriority    = ticket.TicketHistoryEvents.ToList()[2].NewValue;
            vm.CreatedStatus      = ticket.TicketHistoryEvents.ToList()[3].NewValue;

            return(View(vm));
        }
        public ActionResult SubmitterDashboard()
        {
            if (User.IsInRole("Administrator"))
            {
                return(RedirectToAction("AdminDashboard"));
            }
            if (User.IsInRole("Project Manager"))
            {
                return(RedirectToAction("PMDashboard"));
            }
            if (User.IsInRole("Developer"))
            {
                return(RedirectToAction("DeveloperDashboard"));
            }

            var currentUserId = User.Identity.GetUserId();
            var currentUser   = db.Users.Find(currentUserId);

            //Finding tickets this user has access to
            var permissionTickets = new List <Ticket>();

            permissionTickets = db.Tickets.Where(t => t.SubmitterId == currentUserId && t.TicketStatus.Name != "Resolved").ToList();

            //Start ViewBags for Dashboard Count Values
            ViewBag.HighPriorityTicketsCount = permissionTickets.Where(t => t.TicketPriority.Name == "High").Count();

            var changeCount = 0;

            foreach (var ticket in permissionTickets.ToList())
            {
                changeCount += ticket.TicketHistoryEvents.Where(th => th.ChangedDate > DateTimeOffset.Now.AddDays(-7)).ToList().Count();
            }
            ViewBag.RecentChangesCount = changeCount;

            //Start ViewModel
            DashboardViewModel model = new DashboardViewModel();

            //Start Tickets for ViewModel
            model.Tickets = permissionTickets.Where(t => t.TicketPriority.Name == "High").ToList();

            //Start Projects for ViewModel
            model.Projects = currentUser.Projects.ToList();

            //Start TicketComments for ViewModel
            var pt = permissionTickets.Select(t => t.Id).AsEnumerable();
            var permissionComments = db.TicketComments.Where(tc => pt.Contains(tc.TicketId)).ToList();

            model.TicketComments = permissionComments.Where(tc => tc.Created > DateTimeOffset.Now.AddDays(-2)).ToList();

            RelativeTime relativeTime = new RelativeTime();

            if (model.TicketComments != null && model.TicketComments.Any())
            {
                foreach (var comment in model.TicketComments)
                {
                    comment.TimeSincePosted = relativeTime.TimeAgo(comment.Created);
                    db.Entry(comment).Property("TimeSincePosted").IsModified = true;
                    db.SaveChanges();
                }
            }

            //Start TicketAttachments for ViewModel
            var permissionAttachments = db.TicketAttachments.Where(ta => pt.Contains(ta.TicketId)).ToList();

            model.TicketAttachments = permissionAttachments.Where(ta => ta.Created > DateTimeOffset.Now.AddDays(-2)).ToList();

            if (model.TicketAttachments != null && model.TicketAttachments.Any())
            {
                foreach (var attachment in model.TicketAttachments)
                {
                    attachment.TimeSincePosted = relativeTime.TimeAgo(attachment.Created);
                    db.Entry(attachment).Property("TimeSincePosted").IsModified = true;
                    db.SaveChanges();
                }
            }

            return(View(model));
        }
        public ActionResult AdminDashboard()
        {
            var currentUserId = User.Identity.GetUserId();
            var currentUser   = db.Users.Find(currentUserId);

            //Start ViewBags for Dashboard Count Values
            ViewBag.HighPriorityTicketsCount = db.Tickets.Where(t => t.TicketPriority.Name == "High").Count();

            var resolvedTickets = db.Tickets.Where(t => t.TicketStatus.Name == "Resolved");
            var resolvedCount   = 0;

            foreach (var ticket in resolvedTickets.ToList())
            {
                var mostRecentHistory = ticket.TicketHistoryEvents.Reverse().FirstOrDefault(th => th.NewValue == "Resolved");
                var timeComparison    = DateTimeOffset.Compare(mostRecentHistory.ChangedDate, DateTimeOffset.Now.AddDays(-7));
                if (timeComparison > 0)
                {
                    resolvedCount++;
                }
            }
            ViewBag.RecentlyResolvedCount = resolvedCount;

            var changeCount = 0;

            foreach (var ticket in db.Tickets.ToList())
            {
                changeCount += ticket.TicketHistoryEvents.Where(th => th.ChangedDate > DateTimeOffset.Now.AddDays(-7)).ToList().Count();
            }
            ViewBag.RecentChangesCount = changeCount;

            var assignedTickets = db.Tickets.Where(t => t.TicketStatus.Name == "Assigned");
            var assignCount     = 0;

            foreach (var ticket in assignedTickets)
            {
                var mostRecentAssignment = ticket.TicketHistoryEvents.Reverse().FirstOrDefault(th => th.NewValue == "Assigned");
                var timeComparison       = DateTimeOffset.Compare(mostRecentAssignment.ChangedDate, DateTimeOffset.Now.AddDays(-7));
                if (timeComparison > 0)
                {
                    assignCount++;
                }
            }
            ViewBag.RecentlyAssignedTicketsCount = assignCount;

            //Start ViewModel
            DashboardViewModel model = new DashboardViewModel();

            //Start Tickets for ViewModel
            model.Tickets = db.Tickets.Where(t => t.TicketStatus.Name == "Unassigned").ToList();

            //Start Projects for ViewModel
            model.Projects = currentUser.Projects.ToList();

            //Start TicketComments for ViewModel
            model.TicketComments = db.TicketComments.ToList().Where(tc => tc.Created > DateTimeOffset.Now.AddDays(-2)).ToList();

            RelativeTime relativeTime = new RelativeTime();

            if (model.TicketComments != null && model.TicketComments.Any())
            {
                foreach (var comment in model.TicketComments)
                {
                    comment.TimeSincePosted = relativeTime.TimeAgo(comment.Created);
                    db.Entry(comment).Property("TimeSincePosted").IsModified = true;
                    db.SaveChanges();
                }
            }

            //Start TicketAttachments for ViewModel
            model.TicketAttachments = db.TicketAttachments.ToList().Where(ta => ta.Created > DateTimeOffset.Now.AddDays(-2)).ToList();

            if (model.TicketAttachments != null && model.TicketAttachments.Any())
            {
                foreach (var attachment in model.TicketAttachments)
                {
                    attachment.TimeSincePosted = relativeTime.TimeAgo(attachment.Created);
                    db.Entry(attachment).Property("TimeSincePosted").IsModified = true;
                    db.SaveChanges();
                }
            }

            return(View(model));
        }
        public ActionResult PMDashboard()
        {
            if (User.IsInRole("Administrator"))
            {
                return(RedirectToAction("AdminDashboard"));
            }

            var currentUserId = User.Identity.GetUserId();
            var currentUser   = db.Users.Find(currentUserId);

            //Finding tickets this user has access to
            var projects          = db.Projects.Where(p => p.InChargeOfId == currentUser.Id).Select(p => p.Id).AsEnumerable();
            var permissionTickets = db.Tickets.Where(t => (projects.Contains(t.ProjectId) || t.AssignedToId == currentUserId || t.SubmitterId == currentUserId) && t.TicketStatus.Name != "Resolved").ToList();

            //Start ViewBags for Dashboard Count Values
            ViewBag.HighPriorityTicketsCount = permissionTickets.Where(t => t.TicketPriority.Name == "High").Count();

            var changeCount = 0;

            foreach (var ticket in permissionTickets.ToList())
            {
                changeCount += ticket.TicketHistoryEvents.Where(th => th.ChangedDate > DateTimeOffset.Now.AddDays(-7)).ToList().Count();
            }
            ViewBag.RecentChangesCount = changeCount;

            var inChargeOfTickets = permissionTickets.Where(t => projects.Contains(t.ProjectId)).ToList();
            var assignedTickets   = inChargeOfTickets.Where(t => t.TicketStatus.Name == "Assigned");
            var assignCount       = 0;

            foreach (var ticket in assignedTickets)
            {
                var mostRecentAssignment = ticket.TicketHistoryEvents.Reverse().FirstOrDefault(th => th.NewValue == "Assigned");
                var timeComparison       = DateTimeOffset.Compare(mostRecentAssignment.ChangedDate, DateTimeOffset.Now.AddDays(-7));
                if (timeComparison > 0)
                {
                    assignCount++;
                }
            }
            ViewBag.RecentlyAssignedTicketsCount = assignCount;

            //Start ViewModel
            DashboardViewModel model = new DashboardViewModel();

            //Start Tickets for ViewModel
            model.Tickets = inChargeOfTickets.Where(t => t.TicketStatus.Name == "Unassigned").ToList();

            //Start Projects for ViewModel
            model.Projects = currentUser.Projects.ToList();

            //Start TicketComments for ViewModel
            var pt = permissionTickets.Select(t => t.Id).AsEnumerable();
            var permissionComments = db.TicketComments.Where(tc => pt.Contains(tc.TicketId)).ToList();

            model.TicketComments = permissionComments.Where(tc => tc.Created > DateTimeOffset.Now.AddDays(-2)).ToList();

            RelativeTime relativeTime = new RelativeTime();

            if (model.TicketComments != null && model.TicketComments.Any())
            {
                foreach (var comment in model.TicketComments)
                {
                    comment.TimeSincePosted = relativeTime.TimeAgo(comment.Created);
                    db.Entry(comment).Property("TimeSincePosted").IsModified = true;
                    db.SaveChanges();
                }
            }

            //Start TicketAttachments for ViewModel
            var permissionAttachments = db.TicketAttachments.Where(ta => pt.Contains(ta.TicketId)).ToList();

            model.TicketAttachments = permissionAttachments.Where(ta => ta.Created > DateTimeOffset.Now.AddDays(-2)).ToList();

            if (model.TicketAttachments != null && model.TicketAttachments.Any())
            {
                foreach (var attachment in model.TicketAttachments)
                {
                    attachment.TimeSincePosted = relativeTime.TimeAgo(attachment.Created);
                    db.Entry(attachment).Property("TimeSincePosted").IsModified = true;
                    db.SaveChanges();
                }
            }

            return(View(model));
        }