Beispiel #1
0
        public ActionResult GridViewPartialUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] Testiranje2.Models.Student item)
        {
            var model = db.Students;

            if (ModelState.IsValid)
            {
                try
                {
                    string BI = item.BI;

                    using (StudentEntities se = new StudentEntities())
                    {
                        se.Entry(item).State = EntityState.Modified;
                        se.SaveChanges();
                    }

                    // var modelItem = model.FirstOrDefault(it => it.BI == item.BI);
                    // if (modelItem != null)
                    // {
                    //   System.Diagnostics.Debug.WriteLine(item.Ime + item.Prezime+ item.BI);
                    //   this.UpdateModel(item);
                    // db.Entry((Models.Student)item).State = EntityState.Modified;
                    //db.Entry(item).State = System.Data.Entity.EntityState.Modified; bilo zakomentarisano
                    //this.UpdateModel(item); bilo zakomentarisano
                    // db.SaveChanges();
                    // }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            return(PartialView("_GridViewPartial", model.ToList()));
        }
Beispiel #2
0
        public ActionResult GridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Testiranje2.Models.Student item)
        {
            var model = db.Students;

            item.Ime = "David";
            if (ModelState.IsValid)
            {
                try
                {
                    model.Add(item);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            return(PartialView("_GridViewPartial", model.ToList()));
        }