public ActionResult AllTickets()
        {
            userId = User.Identity.GetUserId();

            var isSubmitter    = User.IsInRole("Submitter");
            var isDeveloper    = User.IsInRole("Developer");
            var isAdminManager = User.IsInRole("Admin") || User.IsInRole("ProjectManager");
            var model          = new List <AllTicketsViewModel>();

            if (isAdminManager)
            {
                model = bugTrackerHelper.ActiveTickets().ProjectTo <AllTicketsViewModel>().ToList();
                model.ForEach(t => t.EditAvailable = true);

                foreach (var ticket in model)
                {
                    ticket.OffNotification = notificationHelper.GetNotificationByTicketUserIds(ticket.Id, userId) != null;
                }

                return(View(model));
            }

            if (isDeveloper && isSubmitter)
            {
                model = bugTrackerHelper.GetTicketsForDevSubmitters(userId).ProjectTo <AllTicketsViewModel>().ToList();
                model.ForEach(t => t.EditAvailable = bugTrackerHelper.IsAssigned(t, userId) ||
                                                     bugTrackerHelper.IsOwned(t, userId));

                return(View(model));
            }

            if (isDeveloper)
            {
                model = bugTrackerHelper.GetTicketsForDeveloper(userId).ProjectTo <AllTicketsViewModel>().ToList();
                model.ForEach(t => t.EditAvailable = bugTrackerHelper.IsAssigned(t, userId));

                return(View(model));
            }

            if (isSubmitter)
            {
                model = bugTrackerHelper.GetTicketsForSubmitters(userId).ProjectTo <AllTicketsViewModel>().ToList();
                model.ForEach(t => t.EditAvailable = bugTrackerHelper.IsOwned(t, userId));

                return(View(model));
            }

            return(View());
        }
Example #2
0
        public ActionResult Index()
        {
            var model  = new DashboardViewModel();
            var userId = User.Identity.GetUserId();

            if (User.IsInRole("Admin") || User.IsInRole("ProjectManager"))
            {
                model.NumberProjects        = bugTrackerHelper.GetNumberProject();
                model.NumberOpenTickets     = bugTrackerHelper.GetListTicketsByStatus("Open");
                model.NumberRejectedTickets = bugTrackerHelper.GetListTicketsByStatus("Rejected");
                model.NumberResolvedTickets = bugTrackerHelper.GetListTicketsByStatus("Resolved");
                model.NumberTickets         = bugTrackerHelper.ActiveTickets().Count();

                return(View(model));
            }

            model.NumberProjects = bugTrackerHelper.GetUserProjectsById(userId).Count();

            if (User.IsInRole("Developer"))
            {
                model.NumberTicketsAssigned = bugTrackerHelper.NumberTicketsUserAssigned(userId);
                model.NumberTickets         = bugTrackerHelper.GetTicketsForDeveloper(userId).Count();
            }

            if (User.IsInRole("Submitter"))
            {
                model.NumberTicketsOwned = bugTrackerHelper.NumberTicketsUserOwned(userId);
                model.NumberTickets      = bugTrackerHelper.GetTicketsForSubmitters(userId).Count();
            }

            if (User.IsInRole("Submitter") && User.IsInRole("Developer"))
            {
                model.NumberTicketsAssigned = bugTrackerHelper.NumberTicketsUserAssigned(userId);
                model.NumberTicketsOwned    = bugTrackerHelper.NumberTicketsUserOwned(userId);
                model.NumberTickets         = bugTrackerHelper.GetTicketsForDevSubmitters(userId).Count();
            }

            return(View(model));
        }