public IActionResult Create(CreateViewModel model) { if (ModelState.IsValid) { string uniqueFileName = null; if (model.Photo != null) { string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); model.Photo.CopyTo(new FileStream(filePath, FileMode.Create)); } Employee newEmployee = new Employee { Name = model.Name, Email = model.Email, Department = model.Department, PhotoPath = uniqueFileName }; _employeeRepository.ADD(newEmployee); return(RedirectToAction("Details", new { id = newEmployee.Id })); } return(View()); }