コード例 #1
0
        public async Task <ActionResult> Download(ChangeHistoryViewModel viewModel)
        {
            if (!viewModel.DownloadFormat.HasValue)
            {
                return(View("Download", viewModel));
            }

            if (viewModel.IsEstablishmentSearch)
            {
                if (viewModel.SearchType == eSearchType.Text)
                {
                    var result = await TryGetEstablishment(viewModel);

                    var payload = new EstablishmentChangeHistoryDownloadFilters
                    {
                        ApprovedBy    = viewModel.ApprovedBy,
                        FieldsUpdated = viewModel.SelectedEstablishmentFields.Any() ? viewModel.SelectedEstablishmentFields.ToArray() : null,
                        FileFormat    = viewModel.DownloadFormat == eFileFormat.CSV ? DownloadType.csv : DownloadType.xlsx,
                        SuggestedBy   = viewModel.SuggestedBy
                    };

                    if (viewModel.DateFilterMode == ChangeHistoryViewModel.DATE_FILTER_MODE_APPLIED)
                    {
                        payload.DateAppliedFrom = viewModel.DateFilterFrom?.ToDateTime();
                        payload.DateAppliedTo   = viewModel.DateFilterTo?.ToDateTime();
                    }
                    else if (viewModel.DateFilterMode == ChangeHistoryViewModel.DATE_FILTER_MODE_APPROVED)
                    {
                        payload.DateApprovedFrom = viewModel.DateFilterFrom?.ToDateTime();
                        payload.DateApprovedTo   = viewModel.DateFilterTo?.ToDateTime();
                    }
                    else if (viewModel.DateFilterMode == ChangeHistoryViewModel.DATE_FILTER_MODE_EFFECTIVE)
                    {
                        payload.DateEffectiveFrom = viewModel.DateFilterFrom?.ToDateTime();
                        payload.DateEffectiveTo   = viewModel.DateFilterTo?.ToDateTime();
                    }

                    var progress = await _establishmentReadService.GetChangeHistoryDownloadAsync(result.Item1, payload, User);

                    return(View("ReadyToDownload",
                                new Tuple <ProgressDto, ChangeHistoryViewModel>(
                                    new ProgressDto
                    {
                        FileLocationUri = progress.Url,
                        FileSizeInBytes = progress.FileSizeInBytes
                    }, viewModel)));
                }
                else
                {
                    var payload = PopulatePayload(viewModel,
                                                  new SearchChangeHistoryDownloadPayload(viewModel.DownloadFormat.Value));
                    var progress = await _svc.SearchWithDownloadGenerationAsync(payload, User);

                    return(Redirect(string.Concat(Url.RouteUrl("ChangeHistoryDownload", new { id = progress.Id }),
                                                  "?", Request.QueryString)));
                }
            }

            if (viewModel.SearchType == eSearchType.Group)
            {
                var groupInfo = await TryGetGoupUid(viewModel);

                var progress = await _groupDownloadService.DownloadGroupHistory(groupInfo.Item1,
                                                                                viewModel.DownloadFormat == eFileFormat.CSV?DownloadType.csv : DownloadType.xlsx,
                                                                                viewModel.DateFilterFrom?.ToDateTime(), viewModel.DateFilterTo?.ToDateTime(),
                                                                                viewModel.SuggestedBy, User);

                return(View("ReadyToDownload",
                            new Tuple <ProgressDto, ChangeHistoryViewModel>(
                                new ProgressDto
                {
                    FileLocationUri = progress.Url,
                    FileSizeInBytes = progress.FileSizeInBytes
                }, viewModel)));
            }

            var payloadAll = PopulatePayload(viewModel,
                                             new SearchChangeHistoryDownloadPayload(viewModel.DownloadFormat.Value));
            var progressAll = await _svc.SearchWithDownloadGenerationAsync(payloadAll, User);

            return(Redirect(string.Concat(Url.RouteUrl("ChangeHistoryDownload", new { id = progressAll.Id }),
                                          "?", Request.QueryString)));
        }