Exemplo n.º 1
0
        public async Task <ActionResult> Index()
        {
            var viewModel = new GovernorsBulkUpdateViewModel
            {
                TemplateUri = await _governorsReadService.GetGovernorBulkUpdateTemplateUri(User)
            };

            return(View(viewModel));
        }
        public async Task <ActionResult> ProcessBulkUpdate(GovernorsBulkUpdateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var fileName = FileHelper.GetTempFileName(Path.GetExtension(viewModel.BulkFile.FileName));
                viewModel.BulkFile.SaveAs(fileName);

                if (new FileInfo(fileName).Length > 1000000)
                {
                    ModelState.AddModelError("BulkFile", "The file size is too large. Please use a file size smaller than 1MB");
                }
                else
                {
                    var result = await _governorsWriteService.BulkUpdateValidateAsync(fileName, User);

                    if (result.Success.GetValueOrDefault())
                    {
                        var apiResponse = await _governorsWriteService.BulkUpdateProcessRequestAsync(result.Id, User);

                        viewModel.WasSuccessful = apiResponse.Success;
                        if (apiResponse.HasErrors)
                        {
                            ModelState.AddModelError("BulkFile", apiResponse.Errors[0].Message);
                        }
                    }
                    else
                    {
                        if (result.Errors != null && result.Errors.Any())
                        {
                            ModelState.AddModelError("BulkFile", result.Errors[0].Message);
                        }
                        else
                        {
                            ModelState.AddModelError("error-log", "Please download the error log to correct your data before resubmitting");
                            viewModel.ErrorLogDownload = result.ErrorLogFile;
                        }
                    }
                    System.IO.File.Delete(fileName);
                }
            }
            else
            {
                viewModel.BadFileType = true;
            }

            TempData["ProcessBulkUpdate"] = viewModel;
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> ProcessBulkUpdate(GovernorsBulkUpdateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var fileName = FileHelper.GetTempFileName(Path.GetExtension(viewModel.BulkFile.FileName));
                viewModel.BulkFile.SaveAs(fileName);

                var result = await _governorsWriteService.BulkUpdateValidateAsync(fileName, User);

                if (result.Success.GetValueOrDefault())
                {
                    var apiResponse = await _governorsWriteService.BulkUpdateProcessRequestAsync(result.Id, User);

                    viewModel.WasSuccessful = apiResponse.Success;
                    if (apiResponse.HasErrors)
                    {
                        ModelState.AddModelError("", apiResponse.Errors[0].Message);
                    }
                }
                else
                {
                    if (result.Errors != null && result.Errors.Any())
                    {
                        ModelState.AddModelError("", result.Errors[0].Message);
                    }
                    else
                    {
                        ModelState.AddModelError("", "Please download the error log to correct your data before resubmitting");
                    }
                    viewModel.ErrorLogDownload = result.ErrorLogFile;
                }

                System.IO.File.Delete(fileName);
            }
            else
            {
                viewModel.BadFileType = true;
            }

            return(View("Index", viewModel));
        }