Example #1
0
        private async Task <IEnumerable <WorkOrder> > GetHistoricalWorkOrders()
        {
            var searchParams = new WorkOrderSearchParameters
            {
                StartDate = DateTime.Today.AddDays(1),
                EndDate   = DateTime.Today.AddDays(30),
                PageSize  = 0
            };

            var workOrders = await _listWorkOrdersUseCase.Execute(searchParams);

            return(workOrders
                   .Where(wo => wo.StatusCode != WorkStatusCode.Complete)
                   .Where(wo => !wo.HasManuallyAssignedOperatives())
                   .OrderBy(wo => wo.Appointments.Min(appt => appt.StartTime)));
        }
Example #2
0
        public async Task <IEnumerable <OperativeWorkOrderListItem> > Execute(OperativeWorkOrderSearch opSearch)
        {
            var loggedInUser = _currentUserService.GetUser();

            if (!string.Equals(loggedInUser.PayrollNumber(), opSearch.PayrollNumber, StringComparison.CurrentCultureIgnoreCase))
            {
                ThrowHelper.ThrowUnauthorizedAccessException("Only the operative can retrieve their list of work orders.");
            }

            var operativeDashActiveStatusCodes = Enum.GetValues(typeof(WorkStatusCode)).Cast <int>().ToList();

            operativeDashActiveStatusCodes.RemoveAll(c => c == (int)WorkStatusCode.Canceled ||
                                                     c == (int)WorkStatusCode.PendingApproval);

            _logger.LogInformation($"Searching for operative number {opSearch.PayrollNumber} work orders with statuses {string.Join(", ", operativeDashActiveStatusCodes.Select(x => x.ToString()))}");

            var searchParams = new WorkOrderSearchParameters
            {
                StartDate     = DateTime.Today,
                EndDate       = DateTime.Today.AddDays(1),
                OperativePRNs = new List <string>
                {
                    opSearch.PayrollNumber
                },
                StatusCode = operativeDashActiveStatusCodes,
                PageSize   = opSearch.PageSize
            };
            var workOrders = await _listWorkOrdersUseCase.Execute(searchParams);

            if (!workOrders.Any())
            {
                _logger.LogWarning($"Search for work orders for operative {opSearch.PayrollNumber} did not find anything");
            }
            else
            {
                _logger.LogInformation($"{workOrders.Count()} work orders for operative {opSearch.PayrollNumber}: [${string.Join(", ", workOrders.Select(w => w.Id.ToString()))}]");
            }

            DateTime earliestAppointementDate = GetEarliestAppointmentFromWorkOrders(workOrders);

            var excludedWorkOrders = workOrders.Where(wo =>
                                                      (wo.StatusCode == WorkStatusCode.Complete && wo.ClosedDate.Value.Date < earliestAppointementDate.Date ||
                                                       wo.StatusCode == WorkStatusCode.NoAccess && wo.ClosedDate.Value.Date < earliestAppointementDate.Date
                                                      ));

            workOrders = workOrders
                         .Except(excludedWorkOrders);

            workOrders = workOrders.OrderBy(wo => wo.Appointments.Min(a => a.StartTime));

            return(workOrders.Select(wo => wo.ToOperativeListItem()));
        }
Example #3
0
        public async Task <IActionResult> GetList([FromQuery] WorkOrderSearchParameters parameters)
        {
            var workOrders = await _listWorkOrdersUseCase.Execute(parameters);

            return(Ok(workOrders.Select(wo => wo.ToListItem()).ToList()));
        }