Exemplo n.º 1
0
        public void Validator_rejects_missing_FromDate()
        {
            var model = new ApplicationDownloadViewModel
            {
                FromDate = null,
                ToDate   = DateTime.UtcNow
            };

            var result = _validator.Validate(model);

            Assert.IsFalse(result.IsValid);
            Assert.IsTrue(result.Errors.First().PropertyName == nameof(model.FromDate));
        }
Exemplo n.º 2
0
        public void Validator_rejects_missing_FromDate_and_ToDate()
        {
            var model = new ApplicationDownloadViewModel
            {
                FromDate = null,
                ToDate   = null
            };

            var result = _validator.Validate(model);

            Assert.IsFalse(result.IsValid);
            Assert.IsNotNull(result.Errors.FirstOrDefault(x => x.PropertyName == nameof(model.FromDate)));
            Assert.IsNotNull(result.Errors.FirstOrDefault(x => x.PropertyName == nameof(model.ToDate)));
        }
        public async Task <IActionResult> ApplicationDownloadCsv(ApplicationDownloadViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("~/Views/Roatp/ApplicationDownload.cshtml"));
            }

            var applications = await _applyApiClient.GetApplicationOversightDetailsForDownload(viewModel.FromDate.Value, viewModel.ToDate.Value);

            var exportModel = Mapper.Map <List <RoatpOversightOutcomeExportViewModel> >(applications);

            var bytearray = _csvExportService
                            .WriteCsvToByteArray <RoatpOversightOutcomeExportViewModel, RoatpOversightOutcomeExportCsvMap>(exportModel);

            var fileName = $"outcomes_{viewModel.FromDate:ddMMyy}_to_{viewModel.ToDate.Value:ddMMyy}.csv";

            return(File(bytearray, "text/csv", fileName));
        }