private string FotoYukle(OgrenciOlusturViewModel model) { string uniqFileName = null; if (model.Foto != null) { string yuklenenDosyalar = Path.Combine(hostingEnvironment.WebRootPath, "images"); uniqFileName = Guid.NewGuid().ToString() + "_" + model.Foto.FileName; string dosyaYolu = Path.Combine(yuklenenDosyalar, uniqFileName); using (var fileStream = new FileStream(dosyaYolu, FileMode.Create)) { model.Foto.CopyTo(fileStream); } } return(uniqFileName); }
public IActionResult Olustur(OgrenciOlusturViewModel model) { if (ModelState.IsValid) { string uniqFileName = FotoYukle(model); Ogrenci newOgrenci = new Ogrenci { Ad = model.Ad, Soyad = model.Soyad, Email = model.Email, Sifre = model.Sifre, Sinif = model.Sinif, FotoPath = uniqFileName }; _ogrenciRepository.Olustur(newOgrenci); return(RedirectToAction("Ogrenciler", new { id = newOgrenci.Id })); } return(View()); }