public async Task <IActionResult> Create(Employee employee, IList <IFormFile> EmployeeFiles) { if (!ModelState.IsValid) { return(View(employee)); } _Employee.Create(employee); // Write files to the hosting if (EmployeeFiles.Count != 0) { var UploadsDirectory = Path.Combine(_hostingEnvironment.ContentRootPath, "EmployeeFiles"); foreach (var item in EmployeeFiles) { Files newFile; if (item.Length > 0) { var FilePath = Path.Combine(UploadsDirectory, item.FileName.Replace(" ", "").Replace("-", "_")); using (var FileWritter = new FileStream(FilePath, FileMode.Create)) { await item.CopyToAsync(FileWritter); newFile = new Files(); // Note : the business logic doing in the files repository not here and Here we just pass the values to the repository newFile.FileName = item.FileName; newFile.Description = FilePath; newFile.FileExtension = Path.GetExtension(item.FileName); newFile.EmployeeID = employee.Id; newFile.OwnerType = OwnerTypes.Empolyee; _File.Create(newFile); } } } } return(RedirectToAction(nameof(Index))); }