Beispiel #1
0
        public ActionResult GenerateExcelResult(GenerateExcelModel model)
        {
            DateTimeOffset start          = model.StartDate.ToSwedishDateTime();
            DateTimeOffset end            = model.EndDate.ToSwedishDateTime();
            var            brokerId       = User.TryGetBrokerId();
            var            organisationId = User.TryGetCustomerOrganisationId();
            var            customerUnits  = User.IsInRole(Roles.CentralAdministrator) ? null : User.TryGetLocalAdminCustomerUnits();

            switch (model.SelectedReportType)
            {
            case ReportType.OrdersForCustomer:
                var orders = _statService.GetOrders(start, end, organisationId, customerUnits);
                return(CreateExcelFile(StatisticsService.GetOrderExcelFileRows(orders, model.SelectedReportType), orders.OrderRequests.First().CustomerName, model.SelectedReportType));

            case ReportType.DeliveredOrdersCustomer:
                var deliveredOrders = _statService.GetDeliveredOrders(start, end, organisationId, customerUnits);
                return(CreateExcelFile(StatisticsService.GetOrderExcelFileRows(deliveredOrders, model.SelectedReportType), deliveredOrders.OrderRequests.First().CustomerName, model.SelectedReportType));

            case ReportType.DeliveredOrdersBrokers:
                var deliveredOrdersBrokers = _statService.GetDeliveredRequestsForBroker(start, end, brokerId.Value);
                return(CreateExcelFile(StatisticsService.GetOrderExcelFileRows(deliveredOrdersBrokers, model.SelectedReportType), deliveredOrdersBrokers.OrderRequests.First().BrokerName, model.SelectedReportType));

            case ReportType.RequestsForBrokers:
                var requestsForBrokers = _statService.GetRequestsForBroker(start, end, brokerId.Value);
                return(CreateExcelFile(StatisticsService.GetOrderExcelFileRows(requestsForBrokers, model.SelectedReportType), requestsForBrokers.OrderRequests.First().BrokerName, model.SelectedReportType));

            case ReportType.OrdersForSystemAdministrator:
                var ordersForSystemAdministrator = _statService.GetOrders(start, end, organisationId);
                return(CreateExcelFile(StatisticsService.GetOrderExcelFileRows(ordersForSystemAdministrator, model.SelectedReportType), string.Empty, model.SelectedReportType));

            case ReportType.DeliveredOrdersSystemAdministrator:
                var deliveredOrdersForSystemAdministrator = _statService.GetDeliveredOrders(start, end, organisationId);
                return(CreateExcelFile(StatisticsService.GetOrderExcelFileRows(deliveredOrdersForSystemAdministrator, model.SelectedReportType), string.Empty, model.SelectedReportType));

            case ReportType.RequisitionsForSystemAdministrator:
                var requisitionsForSystemAdministrator = _statService.GetRequisitions(start, end, organisationId);
                return(CreateExcelFile(StatisticsService.GetRequisitionsExcelFileRows(requisitionsForSystemAdministrator, model.SelectedReportType), string.Empty, model.SelectedReportType));

            case ReportType.RequisitionsForBroker:
                var requisitionsForBroker = _statService.GetRequisitions(start, end, null, null, brokerId.Value);
                return(CreateExcelFile(StatisticsService.GetRequisitionsExcelFileRows(requisitionsForBroker, model.SelectedReportType), requisitionsForBroker.Requisitions.First().BrokerName, model.SelectedReportType));

            case ReportType.RequisitionsForCustomer:
                var requisitionsForCustomer = _statService.GetRequisitions(start, end, organisationId, customerUnits);
                return(CreateExcelFile(StatisticsService.GetRequisitionsExcelFileRows(requisitionsForCustomer, model.SelectedReportType), requisitionsForCustomer.Requisitions.First().CustomerName, model.SelectedReportType));

            case ReportType.ComplaintsForSystemAdministrator:
                var complaintsForSystemAdministrator = _statService.GetComplaints(start, end, organisationId);
                return(CreateExcelFile(StatisticsService.GetComplaintsExcelFileRows(complaintsForSystemAdministrator, model.SelectedReportType), string.Empty, model.SelectedReportType));

            case ReportType.ComplaintsForBroker:
                var complaintsForBroker = _statService.GetComplaints(start, end, null, null, brokerId.Value);
                return(CreateExcelFile(StatisticsService.GetComplaintsExcelFileRows(complaintsForBroker, model.SelectedReportType), complaintsForBroker.Complaints.First().BrokerName, model.SelectedReportType));

            case ReportType.ComplaintsForCustomer:
                var complaintsForCustomer = _statService.GetComplaints(start, end, organisationId, customerUnits);
                return(CreateExcelFile(StatisticsService.GetComplaintsExcelFileRows(complaintsForCustomer, model.SelectedReportType), complaintsForCustomer.Complaints.First().CustomerName, model.SelectedReportType));
            }
            return(RedirectToAction(nameof(List)));
        }