public ActionResult Index(int?ticketId)
        {
            var user            = _userRepository.GetUserByName(HttpContext.User.Identity.Name);
            var userDepartments = _userDepartmentRepository.GetListByUserId(user.Id);

            var model = _ticketService.GetTicketsModelForStaff(userDepartments, user);

            ViewBag.tickets = model;

            ViewBag.userDepartments = userDepartments;

            return(View());
        }
Esempio n. 2
0
        public IList <RootMenuItem> GetMenuItems(string username, bool isAdmin)
        {
            var user = _userRepository.GetUserByName(username);


            List <UserDepartment> userDepartments;

            if (!isAdmin)
            {
                userDepartments = _userDepartmentRepository.GetListByUserId(user.Id).ToList();
            }
            else
            {
                userDepartments = _departmentRepository.GetList()
                                  .Select(
                    rec =>
                    new UserDepartment
                {
                    Department = new Department {
                        Id = rec.Id, Name = rec.Name
                    },
                    DepartmentRole = new DepartmentRole {
                        Id = DepartmentRoleId.DepartmentManager
                    }
                }).ToList();
            }


            var model = new List <RootMenuItem>();

            int opened = 0, closed = 0, assignedToMe = 0, unassigned = 0, all = 0;

            foreach (var userDepartment in userDepartments)
            {
                var departmentIds = new List <int>
                {
                    userDepartment.Department.Id
                };
                var openedTickets = _ticketRepository.GetTicketsByDepartmentIdAndStatuses(
                    departmentIds, new List <TicketStatusId> {
                    TicketStatusId.Open
                }).Count;

                var ticketsAssignedToMe = _ticketRepository.GetTicketsByDepartmentIdAndAssignee(
                    departmentIds, user.Id).Count;

                var ticketsUnassigned = _ticketRepository.GetTicketsByDepartmentIdAndAssignee(
                    departmentIds, null).Count;

                var closedTickets = _ticketRepository.GetTicketsByDepartmentIdAndStatuses(
                    departmentIds,
                    new List <TicketStatusId>
                {
                    TicketStatusId.ClosedByUser,
                    TicketStatusId.ClosedDidNotHaveAnyIssues,
                    TicketStatusId.ClosedIrrelevantAnymore,
                    TicketStatusId.ClosedIssueWasResolved
                }).Count;

                var allTickets = _ticketRepository.GetTicketsByDepartmentId(departmentIds).Count();

                if (userDepartment.DepartmentRole.Id == DepartmentRoleId.Staff)
                {
                    model.Add(new RootMenuItem
                    {
                        Url      = null,
                        Title    = userDepartment.Department.Name,
                        Count    = openedTickets + ticketsAssignedToMe + ticketsUnassigned,
                        Subitems = new List <MenuItem>
                        {
                            new MenuItem
                            {
                                Title      = "Opened Tickets",
                                Count      = openedTickets,
                                Parameters = new
                                {
                                    Status       = "open",
                                    DepartmentId = userDepartment.Department.Id
                                }
                            },
                            new MenuItem
                            {
                                Title      = "Assigned to me",
                                Count      = ticketsAssignedToMe,
                                Parameters = new
                                {
                                    DepartmentId = userDepartment.Department.Id,
                                    Assignee     = "assignedtome"
                                }
                            },
                            new MenuItem
                            {
                                Title      = "Unassigned",
                                Count      = ticketsUnassigned,
                                Parameters = new
                                {
                                    DepartmentId = userDepartment.Department.Id,
                                    Assignee     = "unassigned"
                                }
                            }
                        }
                    });

                    opened       += openedTickets;
                    assignedToMe += ticketsAssignedToMe;
                    unassigned   += ticketsUnassigned;
                    closed       += closedTickets;
                    all          += allTickets;
                }
                else
                //if Department Mananeger
                {
                    model.Add(new RootMenuItem
                    {
                        Url      = null,
                        Title    = userDepartment.Department.Name,
                        Count    = allTickets,//openedTickets + ticketsAssignedToMe + ticketsUnassigned ,
                        Subitems = new List <MenuItem>
                        {
                            new MenuItem
                            {
                                Title      = "All Tickets",
                                Count      = allTickets,
                                Parameters = new
                                {
                                    DepartmentId = userDepartment.Department.Id
                                }
                            },

                            new MenuItem
                            {
                                Title      = "Opened Tickets",
                                Count      = openedTickets,
                                Parameters = new
                                {
                                    Status       = "open",
                                    DepartmentId = userDepartment.Department.Id
                                }
                            },
                            new MenuItem
                            {
                                Title      = "Finished Tickets",
                                Count      = closedTickets,
                                Parameters = new
                                {
                                    DepartmentId = userDepartment.Department.Id,
                                    Status       = "closed"
                                }
                            },
                            new MenuItem
                            {
                                Title      = "Assigned to me",
                                Count      = ticketsAssignedToMe,
                                Parameters = new
                                {
                                    DepartmentId = userDepartment.Department.Id,
                                    Assignee     = "assignedtome"
                                }
                            },
                            new MenuItem
                            {
                                Title      = "Unassigned",
                                Count      = ticketsUnassigned,
                                Parameters = new
                                {
                                    DepartmentId = userDepartment.Department.Id,
                                    Assignee     = "unassigned"
                                }
                            }
                        }
                    });


                    opened       += openedTickets;
                    assignedToMe += ticketsAssignedToMe;
                    unassigned   += ticketsUnassigned;
                    closed       += closedTickets;
                    all          += allTickets;
                }
            }

            model.Insert(0, new RootMenuItem
            {
                Url      = null,
                Title    = "All departments",
                Count    = all,//openedTickets + ticketsAssignedToMe + ticketsUnassigned ,
                Subitems = new List <MenuItem>
                {
                    new MenuItem
                    {
                        Title      = "All Tickets",
                        Count      = all,
                        Parameters = new
                        {
                        }
                    },

                    new MenuItem
                    {
                        Title      = "Opened Tickets",
                        Count      = opened,
                        Parameters = new
                        {
                            Status = "open"
                        }
                    },
                    new MenuItem
                    {
                        Title      = "Finished Tickets",
                        Count      = closed,
                        Parameters = new
                        {
                            Status = "closed"
                        }
                    },
                    new MenuItem
                    {
                        Title      = "Assigned to me",
                        Count      = assignedToMe,
                        Parameters = new
                        {
                            Assignee = "assignedtome"
                        }
                    },
                    new MenuItem
                    {
                        Title      = "Unassigned",
                        Count      = unassigned,
                        Parameters = new
                        {
                            Assignee = "unassigned"
                        }
                    }
                }
            });

            return(model);
        }
        public IList <TicketModel> GetTicketsModelByFilters(int?departmentId, string status, string assignee, bool isAdmin)
        {
            IList <TicketModel> result;

            var user = _userRepository.GetUserByName(HttpContext.Current.User.Identity.Name);

            List <UserDepartment> userDepartments;

            if (!isAdmin)
            {
                userDepartments = _userDepartmentRepository.GetListByUserId(user.Id).ToList();
            }
            else
            {
                userDepartments = _departmentRepository.GetList()
                                  .Select(
                    rec =>
                    new UserDepartment
                {
                    Department = new Department {
                        Id = rec.Id, Name = rec.Name
                    },
                    DepartmentRole = new DepartmentRole {
                        Id = DepartmentRoleId.DepartmentManager
                    }
                }).ToList();
            }


            var departmentIds = departmentId.HasValue
                ? new List <int> {
                departmentId.Value
            }
                : userDepartments.Select(d => d.Department.Id).ToList();

            if (HttpContext.Current.User.IsInRole(TicRoles.CustomerContact))
            {
                result = _ticketRepository.GetTicketsForCustomer(user.Id);

                return(result);
            }

            if (status == "open")
            {
                result = _ticketRepository.GetTicketsByDepartmentIdAndStatuses(
                    departmentIds, new List <TicketStatusId> {
                    TicketStatusId.Open
                });
            }
            else if (status == "closed")
            {
                result = _ticketRepository.GetTicketsByDepartmentIdAndStatuses(
                    departmentIds,
                    new List <TicketStatusId>
                {
                    TicketStatusId.ClosedByUser,
                    TicketStatusId.ClosedDidNotHaveAnyIssues,
                    TicketStatusId.ClosedIrrelevantAnymore,
                    TicketStatusId.ClosedIssueWasResolved
                });
            }
            else if (assignee == "unassigned")
            {
                result = _ticketRepository.GetTicketsByDepartmentIdAndAssignee(
                    departmentIds,
                    null);
            }
            else if (assignee == "assignedtome")
            {
                result = _ticketRepository.GetTicketsByDepartmentIdAndAssignee(
                    departmentIds,
                    user.Id);
            }
            else
            {
                result = _ticketRepository.GetTicketsByDepartmentId(
                    departmentIds);
            }

            return(result);
        }
        public JsonResult ActionResultListForUser(string userId)
        {
            var list = _userDepartmentRepository.GetListByUserId(userId);

            return(Json(list, JsonRequestBehavior.AllowGet));
        }