Ejemplo n.º 1
0
        public async Task <ActionResult> DownloadErrorsAndWarnings(Guid pcsId, Guid dataReturnUploadId)
        {
            SchemePublicInfo scheme = await cache.FetchSchemePublicInfo(pcsId);

            DataReturnForSubmission dataReturn = await FetchDataReturnUpload(pcsId, dataReturnUploadId);

            CsvWriter <IErrorOrWarning> csvWriter = csvWriterFactory.Create <IErrorOrWarning>();

            csvWriter.DefineColumn("Type", e => e.TypeName);
            csvWriter.DefineColumn("Description", e => e.Description);

            List <IErrorOrWarning> errorsAndWarnings = new List <IErrorOrWarning>();

            errorsAndWarnings.AddRange(dataReturn.Errors);
            errorsAndWarnings.AddRange(dataReturn.Warnings);

            string csv = csvWriter.Write(errorsAndWarnings);

            string filename = string.Format(
                "{0}_{1}{2}_data_return_errors_and_warnings_{3}.csv",
                scheme.ApprovalNo,
                dataReturn.Year,
                dataReturn.Quarter,
                DateTime.Now.ToString("ddMMyyyy_HHmm"));

            byte[] fileContent = Encoding.UTF8.GetBytes(csv);

            return(File(fileContent, "text/csv", CsvFilenameFormat.FormatFileName(filename)));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> DownloadSchemeObligationDataCsv(int complianceYear)
        {
            using (var client = apiClient())
            {
                var schemeObligationCsvData = await client.SendAsync(User.GetAccessToken(),
                                                                     new GetSchemeObligationDataCsv(complianceYear));

                var data = new UTF8Encoding().GetBytes(schemeObligationCsvData.FileContent);
                return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(schemeObligationCsvData.FileName)));
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> GetProducerCSV(Guid pcsId, int complianceYear)
        {
            using (var client = apiClient())
            {
                var producerCSVData = await client.SendAsync(User.GetAccessToken(),
                                                             new GetProducerCSV(pcsId, complianceYear));

                byte[] data = new UTF8Encoding().GetBytes(producerCSVData.FileContent);
                return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(producerCSVData.FileName)));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> DownloadProducerPublicRegisterCsv(int complianceYear)
        {
            using (var client = apiClient())
            {
                var membersDetailsCsvData = await client.SendAsync(User.GetAccessToken(),
                                                                   new GetProducerPublicRegisterCSV(complianceYear));

                var data = new UTF8Encoding().GetBytes(membersDetailsCsvData.FileContent);
                return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(membersDetailsCsvData.FileName)));
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> DownloadProducerEeeDataHistoryCsv(string registrationNumber)
        {
            using (IWeeeClient client = apiClient())
            {
                var producerEeeDataHistoryCsv = await client.SendAsync(User.GetAccessToken(),
                                                                       new GetProducerEeeDataHistoryCsv(registrationNumber));

                byte[] data = new UTF8Encoding().GetBytes(producerEeeDataHistoryCsv.FileContent);
                return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(producerEeeDataHistoryCsv.FileName)));
            }
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> DownloadAatfNonObligatedDataCsv(int complianceYear, string aatfName)
        {
            using (var client = apiClient())
            {
                var request = new GetUkNonObligatedWeeeReceivedAtAatfsDataCsv(complianceYear, aatfName);

                var fileData = await client.SendAsync(User.GetAccessToken(), request);

                var data = new UTF8Encoding().GetBytes(fileData.FileContent);
                return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(fileData.FileName)));
            }
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> DownloadAatfObligatedDataCsv(int complianceYear, int columnType,
                                                                      string obligationType, string aatfName, Guid?authorityId, Guid?panArea)
        {
            using (var client = apiClient())
            {
                var request  = new GetAllAatfObligatedDataCsv(complianceYear, columnType, obligationType, aatfName, authorityId, panArea);
                var fileData = await client.SendAsync(User.GetAccessToken(), request);

                var data = new UTF8Encoding().GetBytes(fileData.FileContent);
                return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(fileData.FileName)));
            }
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> DownloadEeeWeeeData(Guid pcsId, int complianceYear)
        {
            FileInfo file;

            using (IWeeeClient client = apiClient())
            {
                FetchSummaryCsv fetchSummaryCsv = new FetchSummaryCsv(pcsId, complianceYear);
                file = await client.SendAsync(User.GetAccessToken(), fetchSummaryCsv);
            }

            return(File(file.Data, "text/csv", CsvFilenameFormat.FormatFileName(file.FileName)));
        }
        public async Task <ActionResult> DownloadDataReturnSubmissionEeeChanges(Guid currentSubmission, Guid previousSubmission)
        {
            CSVFileData csvFileData;

            using (IWeeeClient client = apiClient())
            {
                var request = new GetDataReturnSubmissionEeeChangesCsv(currentSubmission, previousSubmission);
                csvFileData = await client.SendAsync(User.GetAccessToken(), request);
            }

            byte[] data = new UTF8Encoding().GetBytes(csvFileData.FileContent);
            return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(csvFileData.FileName)));
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> GetProducerCsv(Guid orgId, int complianceYear, string approvalNumber)
        {
            using (var client = apiClient())
            {
                var csvFileName = approvalNumber + "_fullmemberlist_" + complianceYear + "_" + DateTime.Now.ToString("ddMMyyyy_HHmm") + ".csv";

                var producerCSVData = await client.SendAsync(User.GetAccessToken(),
                                                             new GetProducerCSV(orgId, complianceYear));

                byte[] data = new UTF8Encoding().GetBytes(producerCSVData.FileContent);
                return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(csvFileName)));
            }
        }
Ejemplo n.º 11
0
        public async Task <ActionResult> DownloadChargeBreakdown(Guid id)
        {
            CSVFileData csvFileData;

            using (IWeeeClient client = weeeClient())
            {
                var request = new FetchInvoiceRunCsv(id);
                csvFileData = await client.SendAsync(User.GetAccessToken(), request);
            }

            byte[] data = new UTF8Encoding().GetBytes(csvFileData.FileContent);
            return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(csvFileData.FileName)));
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> Download(Guid returnId, int complianceYear, int quarter, Guid aatfId)
        {
            CSVFileData fileData;

            using (var client = apiClient())
            {
                fileData = await client.SendAsync(User.GetAccessToken(), new GetAatfObligatedData(complianceYear, quarter, returnId, aatfId));
            }

            var data = new UTF8Encoding().GetBytes(fileData.FileContent);

            return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(fileData.FileName)));
        }
Ejemplo n.º 13
0
        public async Task <ActionResult> DownloadAatfReuseSitesCsv(int complianceYear, Guid?authorityId, Guid?panArea)
        {
            CSVFileData fileData;

            var request = new GetAllAatfReuseSitesCsv(complianceYear, authorityId, panArea);

            using (var client = apiClient())
            {
                fileData = await client.SendAsync(User.GetAccessToken(), request);
            }

            var data = new UTF8Encoding().GetBytes(fileData.FileContent);

            return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(fileData.FileName)));
        }
Ejemplo n.º 14
0
        public async Task <ActionResult> DownloadAatfAeDataCsv(int complianceYear,
                                                               int quarter, FacilityType facilityType, ReportReturnStatus?submissionStatus, Guid?authority, Guid?pat, Guid?localArea, bool includeResubmissions)
        {
            using (var client = apiClient())
            {
                var aatfDataUrl = AatfDataUrl();

                var request = new GetAatfAeReturnDataCsv(complianceYear, quarter, facilityType, submissionStatus, authority, pat, localArea, aatfDataUrl, includeResubmissions);

                var fileData = await client.SendAsync(User.GetAccessToken(), request);

                var data = new UTF8Encoding().GetBytes(fileData.FileContent);
                return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(fileData.FileName)));
            }
        }
Ejemplo n.º 15
0
        public async Task <ActionResult> DownloadProducerEeeDataCsv(int complianceYear, Guid?schemeId, ObligationType obligationType)
        {
            CSVFileData fileData;

            var request = new GetProducerEeeDataCsv(complianceYear, schemeId, obligationType);

            using (var client = apiClient())
            {
                fileData = await client.SendAsync(User.GetAccessToken(), request);
            }

            var data = new UTF8Encoding().GetBytes(fileData.FileContent);

            return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(fileData.FileName)));
        }
Ejemplo n.º 16
0
        public async Task <ActionResult> DownloadAatfAeDetailsCsv(int complianceYear,
                                                                  ReportFacilityType?facilityType, Guid?authorityId, Guid?panAreaId, Guid?localAreaId)
        {
            CSVFileData fileData;

            var request = new GetAatfAeDetailsCsv(complianceYear, facilityType, authorityId, panAreaId, localAreaId, false);

            using (var client = apiClient())
            {
                fileData = await client.SendAsync(User.GetAccessToken(), request);
            }

            var data = new UTF8Encoding().GetBytes(fileData.FileContent);

            return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(fileData.FileName)));
        }
Ejemplo n.º 17
0
        public async Task <ActionResult> DownloadPcsAatfDataDifference(int complianceYear, int?quarter,
                                                                       string obligationType)
        {
            CSVFileData fileData;

            var request = new GetPcsAatfComparisonData(complianceYear, quarter, obligationType);

            using (var client = apiClient())
            {
                fileData = await client.SendAsync(User.GetAccessToken(), request);
            }

            var data = new UTF8Encoding().GetBytes(fileData.FileContent);

            return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(fileData.FileName)));
        }
Ejemplo n.º 18
0
        public async Task GetDownloadPcsAatfDataDifferenceCsv_GivenActionParameters_CsvShouldBeReturned()
        {
            var complianceYear = fixture.Create <int>();
            var quarter        = fixture.Create <int>();
            var obligation     = fixture.Create <string>();

            var fileData = fixture.Create <CSVFileData>();

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetPcsAatfComparisonData> .That.Matches(g =>
                                                                                                          g.ComplianceYear.Equals(complianceYear) && g.Quarter.Equals(quarter) &&
                                                                                                          g.ObligationType.Equals(obligation)))).Returns(fileData);

            var result = await controller.DownloadPcsAatfDataDifference(complianceYear, quarter, obligation) as FileContentResult;

            result.FileContents.Should().Contain(new UTF8Encoding().GetBytes(fileData.FileContent));
            result.FileDownloadName.Should().Be(CsvFilenameFormat.FormatFileName(fileData.FileName));
            result.ContentType.Should().Be("text/csv");
        }
Ejemplo n.º 19
0
        public async Task <ActionResult> DownloadProducerDetailsCsv(int complianceYear, Guid?schemeId, Guid?authorityId,
                                                                    bool includeRemovedProducers, bool includeBrandNames)
        {
            var fileName = new StringBuilder();

            fileName.AppendFormat("{0:D4}", complianceYear);

            if (schemeId != null)
            {
                using (var client = apiClient())
                {
                    var requestScheme = new GetSchemeById(schemeId.Value);
                    var scheme        = await client.SendAsync(User.GetAccessToken(), requestScheme);

                    fileName.AppendFormat("_{0}", scheme.ApprovalName);
                }
            }

            if (authorityId != null)
            {
                using (var client = apiClient())
                {
                    var requestAuthority = new GetUKCompetentAuthorityById(authorityId.Value);
                    var authorityData    = await client.SendAsync(User.GetAccessToken(), requestAuthority);

                    fileName.AppendFormat("_{0}", authorityData.Abbreviation);
                }
            }

            fileName.AppendFormat("_producerdetails_{0:ddMMyyyy_HHmm}.csv", SystemTime.UtcNow);

            CSVFileData membersDetailsCsvData;

            using (var client = apiClient())
            {
                var request =
                    new GetMemberDetailsCsv(complianceYear, includeRemovedProducers, schemeId, authorityId, includeBrandNames);
                membersDetailsCsvData = await client.SendAsync(User.GetAccessToken(), request);
            }

            var data = new UTF8Encoding().GetBytes(membersDetailsCsvData.FileContent);

            return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(fileName.ToString())));
        }
Ejemplo n.º 20
0
        public virtual async Task <ActionResult> Download(Guid returnId, bool obligated)
        {
            using (var client = apiClient())
            {
                CSVFileData fileData;
                if (obligated)
                {
                    fileData = await client.SendAsync(User.GetAccessToken(), new GetReturnObligatedCsv(returnId));
                }
                else
                {
                    fileData = await client.SendAsync(User.GetAccessToken(), new GetReturnNonObligatedCsv(returnId));
                }

                var data = new UTF8Encoding().GetBytes(fileData.FileContent);

                return(File(data, "text/csv", CsvFilenameFormat.FormatFileName(fileData.FileName)));
            }
        }
Ejemplo n.º 21
0
        public async Task GetDownloadAatfAeDetailsCsv_GivenActionParameters_CsvShouldBeReturned()
        {
            var complianceYear = fixture.Create <int>();
            var facilityType   = fixture.Create <ReportFacilityType>();
            var authority      = fixture.Create <Guid?>();
            var pat            = fixture.Create <Guid?>();
            var area           = fixture.Create <Guid?>();

            var fileData = fixture.Create <CSVFileData>();

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetAatfAeDetailsCsv> .That.Matches(g =>
                                                                                                     g.ComplianceYear.Equals(complianceYear) && g.FacilityType.Equals(facilityType) &&
                                                                                                     g.AuthorityId.Equals(authority)))).Returns(fileData);

            var result = await controller.DownloadAatfAeDetailsCsv(complianceYear, facilityType, authority, pat, area) as FileContentResult;

            result.FileContents.Should().Contain(new UTF8Encoding().GetBytes(fileData.FileContent));
            result.FileDownloadName.Should().Be(CsvFilenameFormat.FormatFileName(fileData.FileName));
            result.ContentType.Should().Be("text/csv");
        }
        public async Task <ActionResult> DownloadCSV(Guid schemeId, int year, Guid memberUploadId, DateTime submissionDateTime)
        {
            using (var client = apiClient())
            {
                IEnumerable <ErrorData> errors =
                    (await client.SendAsync(User.GetAccessToken(), new GetMemberUploadData(schemeId, memberUploadId)))
                    .OrderByDescending(e => e.ErrorLevel);

                CsvWriter <ErrorData> csvWriter = csvWriterFactory.Create <ErrorData>();
                csvWriter.DefineColumn("Description", e => e.Description);

                var schemePublicInfo = await cache.FetchSchemePublicInfo(schemeId);

                var csvFileName = string.Format("{0}_memberregistration_{1}_warnings_{2}.csv", schemePublicInfo.ApprovalNo, year, submissionDateTime.ToString("ddMMyyyy_HHmm"));

                string csv         = csvWriter.Write(errors);
                byte[] fileContent = new UTF8Encoding().GetBytes(csv);
                return(File(fileContent, "text/csv", CsvFilenameFormat.FormatFileName(csvFileName)));
            }
        }