public ActionResult Create() { using (OIDbEntities db = new OIDbEntities()) { OgrenciVM ogrenci = new OgrenciVM() { Bolumler = db.Bolumlers.ToList(), Cinsiyetlers = db.Cinsiyetlers.ToList(), Sehirlers = db.Sehirlers.ToList(), Sınıflars = db.Sınıflar.ToList(), Uyruklars = db.Uyruklars.ToList() }; return(View(ogrenci)); } }
public ActionResult Update(int ID, HttpPostedFileBase Foto, OgrenciVM model) { using (OIDbEntities db = new OIDbEntities()) { if (!ModelState.IsValid) { OgrenciVM ogr = new OgrenciVM() { Uyruklars = db.Uyruklars.ToList(), Bolumler = db.Bolumlers.ToList(), Cinsiyetlers = db.Cinsiyetlers.ToList(), Ogrenciler = model.Ogrenciler, Sehirlers = db.Sehirlers.ToList(), Sınıflars = db.Sınıflar.ToList() }; return(View(ogr)); } var ogrenci = db.Ogrencilers.Where(x => x.ID == ID).SingleOrDefault(); if (Foto != null) { if (System.IO.File.Exists(Server.MapPath(ogrenci.Fotograf))) { System.IO.File.Delete(Server.MapPath(ogrenci.Fotograf)); } WebImage img = new WebImage(Foto.InputStream); FileInfo info = new FileInfo(Foto.FileName); string newFoto = Guid.NewGuid().ToString() + info.Extension; img.Resize(300, 150); img.Save("~/OgrenciFoto/" + newFoto); ogrenci.Fotograf = "/OgrenciFoto/" + newFoto; } ogrenci.Adsoyad = model.Ogrenciler.Adsoyad; ogrenci.Adres = model.Ogrenciler.Adres; ogrenci.CinsiyetID = model.Ogrenciler.CinsiyetID; ogrenci.BolumID = model.Ogrenciler.BolumID; ogrenci.DogumTarihi = model.Ogrenciler.DogumTarihi; ogrenci.Mail = model.Ogrenciler.Mail; ogrenci.Sınıf = model.Ogrenciler.Sınıf; ogrenci.TCNo = model.Ogrenciler.TCNo; ogrenci.TelNo = model.Ogrenciler.TelNo; ogrenci.UyrukID = model.Ogrenciler.UyrukID; ogrenci.DogumYeri = model.Ogrenciler.DogumYeri; db.SaveChanges(); return(RedirectToAction("List")); } }
public ActionResult Update(int ID) { using (OIDbEntities db = new OIDbEntities()) { OgrenciVM ogrenci = new OgrenciVM() { Bolumler = db.Bolumlers.ToList(), Cinsiyetlers = db.Cinsiyetlers.ToList(), Ogrenciler = db.Ogrencilers.Find(ID), Sehirlers = db.Sehirlers.ToList(), Sınıflars = db.Sınıflar.ToList(), Uyruklars = db.Uyruklars.ToList() }; if (ogrenci.Ogrenciler == null) { return(HttpNotFound()); } return(View(ogrenci)); } }
public ActionResult Create(OgrenciVM model, HttpPostedFileBase txtFoto) { using (OIDbEntities db = new OIDbEntities()) { if (!ModelState.IsValid) { OgrenciVM ogr = new OgrenciVM() { Bolumler = db.Bolumlers.ToList(), Cinsiyetlers = db.Cinsiyetlers.ToList(), Ogrenciler = model.Ogrenciler, Sehirlers = db.Sehirlers.ToList(), Sınıflars = db.Sınıflar.ToList(), Uyruklars = db.Uyruklars.ToList(), }; return(View(ogr)); } if (model.Ogrenciler.ID == 0) { if (txtFoto != null) { WebImage img = new WebImage(txtFoto.InputStream); FileInfo info = new FileInfo(txtFoto.FileName); string newFoto = Guid.NewGuid().ToString() + info.Extension; img.Resize(150, 350); img.Save("~/OgrenciFoto/" + newFoto); model.Ogrenciler.Fotograf = "/OgrenciFoto/" + newFoto; } db.Ogrencilers.Add(model.Ogrenciler); } else { db.Entry(model).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("List")); } }