Пример #1
0
        public async Task <ActionResult> GetByCustomers(ExportCustomerRequest request)
        {
            if (!ModelState.IsValid)
            { // re-render the view when validation failed.
                return(BadRequest(ModelState));
            }
            await _exportServerUseCase.Handle(new ExportServerRequest(request.FromDate, request.ToDate, request.Guids), _exportServerPresenter);

            return(_exportServerPresenter.ContentResult);
        }
        public async Task <bool> Handle(ExportCustomerRequest message, IOutputPort <ExportCustomerResponse> outputPort)
        {
            ExportCSVByCustomerResponse response;

            response = await _customerRepository.GetByCustomers(message);

            outputPort.Handle(response.Success ? new ExportCustomerResponse(response.ResponsedRequest, true) :
                              new ExportCustomerResponse(response.Errors.Select(e => e.Description)));
            return(response.Success);
        }
        public async Task <ExportCSVByCustomerResponse> GetByCustomers(ExportCustomerRequest request)
        {
            var response = await _context.Server.AsNoTracking()
                           .Where(s => s.CustomerServer.Any(cs => request.Guids.Contains(cs.Customer.Id)))
                           .Where(s => s.Request.Any(r => (r.EndDate <= request.ToDate && r.StartDate >= request.FromDate && r.ApprovedBy != null)))
                           .Select(s => new {
                Request = s.Request
                          .Where(r => r.ApprovedBy != null)
                          .Select(r => new { s.Name, s.IpAddress, r.Title, startDate = string.Format("{0:dd/MM/yyyy}", r.StartDate),
                                             endDate = string.Format("{0:dd/MM/yyyy}", r.EndDate), Requester = r.CreatedByNavigation.Email, Approver = r.ApprovedByNavigation.Email })
            })
                           .ToListAsync();

            return(new ExportCSVByCustomerResponse(response, true, null));
        }