Exemplo n.º 1
0
        public async Task <IActionResult> Upload([CanBeNull] IFormFile uploadedFile)
        {
            if (uploadedFile == null)
            {
                return(this.ErrorView(Error.Create("EmptyFile", "File is required")));
            }

            using (var binaryReader = new BinaryReader(uploadedFile.OpenReadStream()))
            {
                var viewModel = new UploadDataFileViewModel
                {
                    Name    = uploadedFile.FileName,
                    Content = binaryReader.ReadBytes((int)uploadedFile.Length)
                };
                var(dataFile, errors) = await dataFilesStore.SaveAsync(viewModel).ConfigureAwait(false);

                if (errors != Error.NoError)
                {
                    return(this.ErrorView(errors));
                }

                DataFileProcessor.Enqueue(dataFile.Id);
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult FetchProcessDataFiles([Bind(Include = "Id,CampaignId,OrderNumber")] CampaignTestingVm campaignTestingVm)
        {
            try
            {
                var campaign = Db.Campaigns
                               .Include(x => x.Assets)
                               .Include(x => x.Segments)
                               .Include(x => x.Testing)
                               .FirstOrDefault(x => x.Id == campaignTestingVm.CampaignId);

                if (string.IsNullOrEmpty(campaign.Assets.ZipCodeFile))
                {
                    throw new AdsException("ZipCodeFile is not provided, Please upload one.");
                }

                if (campaign.Segments.Count == 0)
                {
                    throw new AdsException("There are no Multi data segments.");
                }

                if (campaign.Testing.DataFileQuantity == 0)
                {
                    throw new AdsException("DataFileQuantity is Zero.");
                }

                BackgroundJob.Enqueue(() => DataFileProcessor.FetchSqlDataFile(UploadPath, IsNxs, campaign.Id, campaign.OrderNumber, campaign.Assets.ZipCodeFile, campaign.Testing.DataFileQuantity));

                TempData["Success"] = "SQL Data is being fetched and processed, please wait about 5m ...";
            }
            catch (Exception ex)
            {
                TempData["Error"] = ex.Message;
            }
            return(RedirectToAction("EditTesting", new { id = campaignTestingVm.Id }));
        }