private string ProcessPhotos(EmployerCreateViewModel model) { string profilePhotoFileName = null; if (model.Photo != null) { string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Images\\Employers"); profilePhotoFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName; string filePath = Path.Combine(uploadsFolder, profilePhotoFileName); using (FileStream fileStream = new FileStream(filePath, FileMode.Create)) { model.Photo.CopyTo(fileStream); } } return(profilePhotoFileName); }
public IActionResult Create(EmployerCreateViewModel model) { if (ModelState.IsValid) { string uniqueFileName; uniqueFileName = ProcessPhotos(model); Employer newEmployer = new Employer() { CompanyName = model.CompanyName, Description = model.Description, CompanyPhotoPath = uniqueFileName, }; _repo.AddEmployer(newEmployer); return(RedirectToAction("Details", new { id = newEmployer.Id })); } return(View()); }