public IActionResult ImportExcel(IList <IFormFile> files, int categoryId) { if (files != null && files.Count > 0) { var file = files[0]; var filename = ContentDispositionHeaderValue .Parse(file.ContentDisposition) .FileName .Trim('"'); string folder = _hostingEnvironment.WebRootPath + $@"\uploaded\excels"; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string filePath = Path.Combine(folder, filename); using (FileStream fs = System.IO.File.Create(filePath)) { file.CopyTo(fs); fs.Flush(); } var request = new CreatExel() { FilePath = filePath, CategoryId = categoryId }; _productConnectAPI.ImportExcel(request); return(new OkObjectResult(filePath)); } return(new NoContentResult()); }
public async void ImportExcel(CreatExel request) { var json = JsonConvert.SerializeObject(request); var jsonstring = new StringContent(json, Encoding.UTF8, "application/json"); var creat = _httpClientFactory.CreateClient(); creat.BaseAddress = new Uri(_configuration["URLAPI:Url"]); await creat.PostAsync("api/Product/ImportEx", jsonstring); }
public IActionResult ImportExcel([FromBody] CreatExel request) { _productSerVice.ImportExcel(request.FilePath, request.CategoryId); return(Ok()); }