public async Task <FileRepsonseDto> UploadFileAsync(IFormFileCollection files) { var rsp = new FileRepsonseDto(); foreach (IFormFile f in files) { var rst = await UploadFileAsync(f); rsp.Message = "File Uploaded Successfully"; rsp.Status = StatusEnum.Success; } return(rsp); }
private async Task <FileRepsonseDto> SaveFile(IFormFile file, FileRepsonseDto resp) { try { var newFile = new dbo.File(); var path = Path.Combine(Directory.GetCurrentDirectory(), "Files", file.FileName); var stream = new FileStream(path, FileMode.Create); await file.CopyToAsync(stream); newFile.Name = file.Name; newFile.Path = path; _fileRepository.Add(newFile); _fileRepository.Commit(); resp.Message = "File Uploaded successfully"; resp.Status = StatusEnum.Success; } catch (Exception e) { resp.Status = StatusEnum.Error; resp.Message = e.Message; } return(resp); }
public async Task <FileRepsonseDto> UploadFileAsync(IFormFile file) { var resp = new FileRepsonseDto(); return(await SaveFile(file, resp)); }