Пример #1
0
        public ActionResult Index(OgrenciViewModel p)
        {
            if (ModelState.IsValid)
            {
                try {
                    string[] iban;
                    string[] tel;
                    iban = p.ogrenci.ogrenciIBAN.Split(' ');
                    tel  = p.ogrenci.ogrenciTelNo.Split(' ');
                    p.ogrenci.ogrenciIBAN  = "";
                    p.ogrenci.ogrenciTelNo = "";
                    foreach (var item in iban)
                    {
                        p.ogrenci.ogrenciIBAN += item;
                    }
                    foreach (var item in tel)
                    {
                        p.ogrenci.ogrenciTelNo += item;
                    }
                    p.kullanici.kullaniciGuncellemeTarihi = DateTime.Now;
                    p.ogrenci.ogrenciGuncellemeTarih      = DateTime.Now;
                    p.ogrenci.Okul            = db.Okul.Find(p.ogrenci.okulID);
                    p.kullanici.kullaniciMail = p.kullanici.kullaniciMail.Trim();
                    p.ogrenci.ogrenciMail     = p.ogrenci.ogrenciMail.Trim();
                    p.ogrenci.ogrenciTelNo    = p.ogrenci.ogrenciTelNo.Trim();
                    p.ogrenci.ogrenciIBAN     = p.ogrenci.ogrenciIBAN.Trim();
                    p.ogrenci.ogrenciNumara   = p.ogrenci.ogrenciNumara.Trim();

                    db.Entry(p.kullanici).State = EntityState.Modified;
                    db.Entry(p.ogrenci).State   = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Response.Write(string.Format("Entity türü \"{0}\" şu hatalara sahip \"{1}\" Geçerlilik hataları:", eve.Entry.Entity.GetType().Name, eve.Entry.State));
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Response.Write(string.Format("- Özellik: \"{0}\", Hata: \"{1}\"", ve.PropertyName, ve.ErrorMessage));
                        }
                        Response.End();
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
Пример #2
0
 public ActionResult Index(List <AnketViewModel> model)
 {
     foreach (var item in model)
     {
         if (item.cevap.anketSecenekID != 0)
         {
             if (item.cevap.anketCevapID == 0)
             {
                 db.AnketCevap.Add(item.cevap);
             }
             else
             {
                 db.Entry(item.cevap).State = EntityState.Modified;
             }
         }
     }
     db.SaveChanges();
     return(RedirectToAction("Index", "Ogrenci"));
 }