private string ProcessUploadedFile(LekarzCreateViewModel model) { string uniqueFileName = null; if (model.Foto != null) { string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Foto.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.Foto.CopyTo(fileStream); } } return(uniqueFileName); }
public IActionResult Create(LekarzCreateViewModel model) { if (ModelState.IsValid) { string uniqueFileName = ProcessUploadedFile(model); Lekarz newLekarz = new Lekarz { Imie = model.Imie, Nazwisko = model.Nazwisko, Specjalizacja = model.Specjalizacja, Email = model.Email, Opis = model.Opis, PhotoPath = uniqueFileName }; _lekarzRepository.Add(newLekarz); return(RedirectToAction("details", new { id = newLekarz.LekarzID })); } return(View()); }