public ActionResult UploadEmployeeFile([FromForm] EmployeeFileDTO employeeFileDTO) { Employee employee = _employeeService.GetById(employeeFileDTO.EmployeeId); if (employee == null) { throw new AppException("Employee not found"); } var files = employeeFileDTO.Files; string path = Path.Combine("Employees", employee.Id.ToString(), employeeFileDTO.Folder); foreach (var file in files) { _fileService.Create(file, path); EmployeeFile employeeFile = new EmployeeFile { Name = file.FileName, Path = Path.Combine(path, file.FileName), EmployeeId = employee.Id, Employee = employee }; _employeeService.CreateFile(employeeFile); } return(Ok()); }
public void DeleteFile(int id) { EmployeeFile file = GetFile(id); if (file == null) { throw new AppException("File not found in database."); } _context.EmployeeFiles.Remove(file); _context.SaveChanges(); }
async public Task <ActionResult> DownloadEmployeeFile(int id, string token) { if (!_customAuthService.CheckToken(token)) { return(Unauthorized()); } EmployeeFile file = _employeeService.GetFile(id); if (file == null) { throw new AppException("File not found in database."); } string fileName = file.Name; string filePath = file.Path; var provider = new FileExtensionContentTypeProvider(); string contentType; if (!provider.TryGetContentType(fileName, out contentType)) { contentType = "application/octet-stream"; } string fullPath = _fileService.getFullPath(filePath); var memory = new MemoryStream(); using (var stream = new FileStream(fullPath, FileMode.Open)) { await stream.CopyToAsync(memory); } memory.Position = 0; return(File(memory, contentType)); }
public void CreateFile(EmployeeFile employeeFile) { _context.EmployeeFiles.Add(employeeFile); _context.SaveChanges(); }
internal IEnumerable <Employee> GetEmployeeData() { return(EmployeeFile.GetData()); }
internal async Task <IEnumerable <Employee> > GetEmployeeDataAsync() { return(await EmployeeFile.GetDataAsync()); }