Exemplo n.º 1
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }


            var result = await _csvService.GetById(id);

            if (result == null)
            {
                return(NotFound());
            }
            CSVViewModel csv = new CSVViewModel
            {
                Id          = result.Id,
                Name        = result.Name,
                DateofBirth = result.DateofBirth,
                IsMarried   = result.IsMarried,
                Phone       = result.Phone,
                Salary      = result.Salary
            };

            return(View(csv));
        }
Exemplo n.º 2
0
 public IActionResult OutputCSV(CSVViewModel model)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         StreamWriter writer = new StreamWriter(stream);
         using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
         {
             csv.WriteRecords(model.items);
         }
         return(File(stream.ToArray(), "text/plain", "EPIC_results.csv"));
     }
 }
Exemplo n.º 3
0
        public async Task <IActionResult> Index(List <CSVViewModel> CSVList)
        {
            for (int i = CSVList.Count - 1; i >= 0; i--)     //I'm so clever. If I iterate backwards, I can modify the list while I'm iterating.
            {
                CSVViewModel file = CSVList[i];
                if (file.ShouldBeDeleted)
                {
                    CloudBlockBlob blob = await GlobalCache.GetCSVBlob(file.Name);

                    await blob.DeleteIfExistsAsync();

                    CSVList.RemoveAt(i);
                }
            }
            return(View(CSVList));
        }
Exemplo n.º 4
0
 public IActionResult UploadViaCSV(CSVViewModel model)
 {
     try
     {
         var path       = ProcessUploadFile(model);
         var resultData = new CarService().ReadCSVFile(path);
         foreach (var item in resultData)
         {
             _car.Add(item);
         }
         return(RedirectToAction("index"));
     }
     catch (Exception)
     {
         return(RedirectToAction("Error", "Error", new { }));
     }
 }
Exemplo n.º 5
0
        private string ProcessUploadFile(CSVViewModel filePath)
        {
            string uniqueFileName = null;

            if (filePath.filePath != null)
            {
                string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "csv");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + filePath.filePath.FileName;

                string filePath2 = Path.Combine(uploadsFolder, uniqueFileName);

                using (var fileStream = new FileStream(filePath2, FileMode.Create))
                {
                    filePath.filePath.CopyTo(fileStream);
                }

                uniqueFileName = filePath2;
            }

            return(uniqueFileName);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> EditPost(int?id, CSVViewModel model)
        {
            if (id == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var csv = new CSVDto
                {
                    Id          = id,
                    Name        = model.Name,
                    DateofBirth = model.DateofBirth,
                    IsMarried   = model.IsMarried,
                    Phone       = model.Phone,
                    Salary      = model.Salary
                };
                await _csvService.Update(csv);

                return(RedirectToAction("Index", "Home"));
            }
            return(View(model));
        }