Пример #1
0
        public FileResult Post([FromBody] RipsGenerationData ripsGenerationData)
        {
            var rootPath   = Path.Combine(_hostingEnvironment.WebRootPath, "Temp");
            var folderPath = _ripsDomainService.GenerateRips(rootPath, ripsGenerationData);
            var fileName   = string.Format("{0}/{1}.zip", Path.Combine(_hostingEnvironment.WebRootPath, "Temp"), "Test");
            var zipPath    = Path.Combine(folderPath, fileName);

            if (System.IO.File.Exists(zipPath))
            {
                System.IO.File.Delete(zipPath);
            }

            ZipFile.CreateFromDirectory(folderPath, zipPath);


            var response = new HttpResponseMessage(HttpStatusCode.OK);
            var bytes    = System.IO.File.ReadAllBytes(zipPath);

            response.Content = new ByteArrayContent(bytes);
            response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
            response.Content.Headers.ContentType                 = new MediaTypeHeaderValue("application/zip");
            response.Content.Headers.ContentDisposition.FileName = "RipsFolder";
            return(File(bytes, "application/zip", "test.zip"));

            //return response;
        }
Пример #2
0
        public string GenerateRips(string rootPath, RipsGenerationData ripsGenerationData)
        {
            var consecutive = _ripsRepository.InsertRipsControl(ripsGenerationData.RipsFilter.InvoiceNumber);

            rootPath = string.Format(@"{0}\{1}", rootPath, consecutive);
            if (!Directory.Exists(rootPath))
            {
                Directory.CreateDirectory(rootPath);
            }
            var firstRip = ripsGenerationData.Rips.FirstOrDefault();

            if (firstRip == null)
            {
                return(rootPath);
            }
            var groups  = ripsGenerationData.Rips.GroupBy(x => x.PatientDocument).Select(group => @group.First());
            var ripsAf  = ripsGenerationData.Rips.GroupBy(x => x.InvoiceNumber).Select(group => group.First());
            var afCount = _ripsGenerator.GenerateAfFile(rootPath, ripsGenerationData.RipsFilter, ripsAf);
            var usCount = _ripsGenerator.GenerateUsFile(rootPath, groups);
            var apCount = _ripsGenerator.GenerateApFile(rootPath, ripsGenerationData.RipsFilter, ripsGenerationData.Rips);
            var acCount = _ripsGenerator.GenerateAcFile(rootPath, ripsGenerationData.RipsFilter, ripsGenerationData.Rips);
            var atCount = _ripsGenerator.GenerateAtFile(rootPath, ripsGenerationData.RipsFilter, ripsGenerationData.Rips);

            _ripsGenerator.GenerateCtFile(rootPath, firstRip.ProviderCode, afCount, usCount, apCount,
                                          acCount, atCount);
            UpdateServiceInvoices(ripsGenerationData.Rips, ripsGenerationData.RipsFilter.InvoiceNumber);

            return(rootPath);
        }