private string UploadedFile(SopstvenikVM model) { string uniqueFileName = null; if (model.ProfilePicture != null) { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.ProfilePicture.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.ProfilePicture.CopyTo(fileStream); } } return(uniqueFileName); }
public async Task <IActionResult> CreateSopstvenik(SopstvenikVM model) { if (ModelState.IsValid) { string uniqueFileName = UploadedFile(model); Sopstvenik sopstvenik = new Sopstvenik { ImePrezime = model.ImePrezime, ImeMilenik = model.ImeMilenik, Email = model.Email, Grad = model.Grad, ProfilePicture = uniqueFileName, }; _context.Add(sopstvenik); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(IndexSopstvenik))); } return(View(model)); }