public Report GetFilteredTicketsReportBulk(Filters filters) { using (var scope = _scopeFactory.CreateScope()) { var db = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); List <TicketReportDTO> ticketReportDTOs = new List <TicketReportDTO>(); var tickets = (from ticket in db.Ticket where ticket.CreateTime.CompareTo(filters.Period.startTime) > 0 && ticket.CreateTime.CompareTo(filters.Period.endTime) < 0 select ticket) .Include(ticket => ticket.TicketState) .Include(ticket => ticket.Queue) .Include(ticket => ticket.TicketPriority) .ToList().Where(t => !t.Queue.Name.Equals("Trash")); var ttsDynamicFields = GetTTDynamicFieldsBulk((from ticket in tickets select ticket.Id).ToList()); FilteringItems filteringItems = new FilteringItems(); var zones = ttsDynamicFields.Select(p => p.Value).ToList().SelectValues("Zone").Distinct().ToList(); var types = ttsDynamicFields.Select(p => p.Value).ToList().SelectValues("Type").Distinct().ToList(); var direction = ttsDynamicFields.Select(p => p.Value).ToList().SelectValues("Direction").Distinct().ToList(); var natInt = ttsDynamicFields.Select(p => p.Value).ToList().SelectValues("NatInt").Distinct().ToList(); var initiator = ttsDynamicFields.Select(p => p.Value).ToList().SelectValues("Initiator").Distinct().ToList(); var category = ttsDynamicFields.Select(p => p.Value).ToList().SelectValues("Category").Distinct().ToList(); var problemSide = ttsDynamicFields.Select(p => p.Value).ToList().SelectValues("ProblemSide").Distinct().ToList(); filteringItems.States = tickets.Select(ticket => ticket.TicketState.Name).Distinct().OrderByDescending(state => state).toSelectItems(); filteringItems.TicketPriorities = tickets.Select(ticket => ticket.TicketPriority.Name).Distinct().OrderByDescending(ticketPriority => ticketPriority).toSelectItems(); filteringItems.Zones = zones.Count > 0 ? zones.toSelectItems() : null; filteringItems.Types = types.Count > 0 ? types.toSelectItems() : null; filteringItems.Directions = direction.Count > 0 ? direction.toSelectItems() : null; filteringItems.NatInts = natInt.Count > 0 ? natInt.toSelectItems() : null; filteringItems.Initiators = initiator.Count > 0 ? initiator.toSelectItems() : null; filteringItems.Categories = category.Count > 0 ? category.toSelectItems() : null; filteringItems.ProblemSides = problemSide.Count > 0 ? problemSide.toSelectItems() : null; foreach (var ticket in tickets) { TicketReportDTO ticketReportDTO = new TicketReportDTO(); ticketReportDTO.TN = ticket.Tn; ticketReportDTO.State = ticket.TicketState.Name; ticketReportDTO.CreateTime = ticket.CreateTime; ticketReportDTO.Client = ticket.CustomerId; ticketReportDTO.TicketPriority = ticket.TicketPriority.Name; var dFields = ttsDynamicFields[ticket.Id]; if (dFields.Count > 0) { foreach (var field in dFields) { typeof(TicketReportDTO).GetProperty(field.Key)?.SetValue(ticketReportDTO, !field.Key.Equals("CloseTime") ? field.Value : DateTime.Parse(field.Value)); } } if (IsTicketDTOValid(ticketReportDTO, filters)) { ticketReportDTOs.Add(ticketReportDTO); } } return(new Report() { ticketReportDTOs = ticketReportDTOs.OrderByDescending(ticket => ticket.CreateTime), filteringItems = filteringItems }); } }
//Category public FilteringItems GetFilteringItems(Period period) { using (var scope = _scopeFactory.CreateScope()) { var db = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); List <TicketReportDTO> ticketReportDTOs = new List <TicketReportDTO>(); var tickets = (from ticket in db.Ticket where ticket.CreateTime.CompareTo(period.startTime.ToLocalTime()) > 0 && ticket.CreateTime.CompareTo(period.endTime.ToLocalTime()) < 0 select ticket) .Include(ticket => ticket.TicketState) .Include(ticket => ticket.Queue) .Include(ticket => ticket.TicketPriority) .ToList(); var states = tickets.Select(ticket => ticket.TicketState.Name).Distinct().OrderByDescending(state => state).toSelectItems(); var priorities = tickets.Select(ticket => ticket.TicketPriority.Name).Distinct().OrderByDescending(ticketPriority => ticketPriority).toSelectItems(); var zones = new List <string>(); var types = new List <string>(); var directions = new List <string>(); var natInts = new List <string>(); var initiators = new List <string>(); var categories = new List <string>(); var problemSides = new List <string>(); foreach (var ticket in tickets) { var dfields = GetTTDynamicFields(ticket.Id); if (dfields.Count > 0) { if (dfields.ContainsKey("Zone") && !String.IsNullOrEmpty(dfields["Zone"])) { zones.Add(dfields["Zone"]); } if (dfields.ContainsKey("Type") && !String.IsNullOrEmpty(dfields["Type"])) { types.Add(dfields["Type"]); } if (dfields.ContainsKey("Direction") && !String.IsNullOrEmpty(dfields["Direction"])) { directions.Add(dfields["Direction"]); } if (dfields.ContainsKey("NatInt") && !String.IsNullOrEmpty(dfields["NatInt"])) { natInts.Add(dfields["NatInt"]); } if (dfields.ContainsKey("Initiator") && !String.IsNullOrEmpty(dfields["Initiator"])) { initiators.Add(dfields["Initiator"]); } if (dfields.ContainsKey("Category") && !String.IsNullOrEmpty(dfields["Category"])) { initiators.Add(dfields["Category"]); } if (dfields.ContainsKey("ProblemSide") && !String.IsNullOrEmpty(dfields["ProblemSide"])) { initiators.Add(dfields["ProblemSide"]); } } } var filteringItems = new FilteringItems() { Directions = directions.Distinct().OrderByDescending(name => name).toSelectItems(), Initiators = initiators.Distinct().OrderByDescending(name => name).toSelectItems(), Types = types.Distinct().OrderByDescending(name => name).toSelectItems(), Zones = zones.Distinct().OrderByDescending(name => name).toSelectItems(), NatInts = natInts.Distinct().OrderByDescending(name => name).toSelectItems(), States = states, TicketPriorities = priorities, Categories = categories.Distinct().OrderByDescending(name => name).toSelectItems(), ProblemSides = problemSides.Distinct().OrderByDescending(name => name).toSelectItems() }; return(filteringItems); } }