Ejemplo n.º 1
0
        public async Task <IActionResult> GetList()
        {
            try
            {
                List <SalesViewModel> salesVm = SalesViewModel.ConvertToViewModel(_salesBusiness.GetSalesList());

                return(Ok(new { salesVm }));
            } catch (Exception ex)
            {
                return(BadRequest("Something bad happened during the reading of the file."));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UploadFile(List <IFormFile> files)
        {
            if (files.Count == 0)
            {
                return(BadRequest("No file was uploaded."));
            }

            IFormFile file = files.First();

            if (file.Length == 0)
            {
                return(BadRequest("The file was empty."));
            }

            // full path to file in temp location
            string filePath = Path.GetTempFileName();

            var  sales       = _salesBusiness.ConvertCSVToSales(file.OpenReadStream());
            bool isPersisted = await _salesBusiness.PersistSales(sales);

            var salesVm = SalesViewModel.ConvertToViewModel(sales);

            return(Ok(new { salesVm }));
        }