Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid || StartDate > EndDate)
            {
                ExceptionMessage = "Wystąpił błąd w zapytaniu";
                return(Page());
            }

            try
            {
                AdescomCTM    atmanCTMWithProxyClasses = new AdescomCTM(_configuration);
                List <Client> client = (await atmanCTMWithProxyClasses.GetClientsAsyncWithTimeout(true, ClientId));
                ClientBilling = (await atmanCTMWithProxyClasses.GetBillingForClientsAsyncWithTimeout(client, StartDate, EndDate)).FirstOrDefault();
                return(Page());
            }
            catch (Exception ex)
            {
                ExceptionMessage = ex.Message;
                return(Page());
            }
        }
        public async Task <IActionResult> OnGet()
        {
            if (!ModelState.IsValid)
            {
                ExceptionMessage = "Wystąpił błąd w zapytaniu";
                return(Page());
            }

            try
            {
                AdescomCTM atmanCTMWithProxyClasses = new AdescomCTM(_configuration);
                Clients = (await atmanCTMWithProxyClasses.GetClientsAsyncWithTimeout(false, null))
                          .OrderBy(o => o.Name)
                          .ToList();

                return(Page());
            }
            catch (Exception ex)
            {
                ExceptionMessage = ex.Message;
                return(Page());
            }
        }
        public async Task <IActionResult> OnPostExportAsync()
        {
            if (!ModelState.IsValid || StartDate > EndDate)
            {
                ExceptionMessage = "Wystąpił błąd w zapytaniu";
                return(Page());
            }

            try
            {
                AdescomCTM atmanCTMWithProxyClasses = new AdescomCTM(_configuration);
                string     temporaryPDFDirectory    = _hostingEnvironment.ContentRootPath + "/Temp/PDF/";
                string     temporaryZIPDirectory    = _hostingEnvironment.ContentRootPath + "/Temp/ZIP/";
                string     temporaryZIPFile         = "Billingi - " + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".zip";

                Clients = await atmanCTMWithProxyClasses.GetClientsAsyncWithTimeout(true, null);

                List <ClientBilling> clientsBillings = await atmanCTMWithProxyClasses.GetBillingForClientsAsyncWithTimeout(Clients, StartDate, EndDate);

                await Task.Run(() =>
                {
                    _exportService.FlushOrCreateDirectory(temporaryPDFDirectory);
                    _exportService.FlushOrCreateDirectory(temporaryZIPDirectory);
                    _exportService.ExportBillingsToPdfs(clientsBillings, temporaryPDFDirectory);
                    _exportService.ExportBillingsToSummaryPdf(clientsBillings, temporaryPDFDirectory);
                    _exportService.CreateZipArchive(temporaryPDFDirectory, temporaryZIPDirectory + temporaryZIPFile);
                });

                return(PhysicalFile(temporaryZIPDirectory + temporaryZIPFile, "application/zip", temporaryZIPFile));
            }
            catch (Exception ex)
            {
                ExceptionMessage = ex.Message;
                return(Page());
            }
        }