public int Add(T o)
 {
     if (!isExits(o))
     {
         objectDbSet.Add(o);
         int res = db.SaveChanges();
         if (res > 0)
         {
             objectBindingList.Add(o);
         }
         return(res);
     }
     else
     {
         return(-1);
     }
 }
Пример #2
0
        public int Update(Student stu)
        {
            Student old_stu = entity.Students.FirstOrDefault(n => n.ID == stu.ID);

            old_stu.Name    = stu.Name;
            old_stu.Phone   = stu.Phone;
            old_stu.Address = stu.Address;

            entity.Entry(old_stu).State = System.Data.Entity.EntityState.Modified;
            int num = entity.SaveChanges();

            if (num > 0)
            {
                ob_BindingList[currentIndex] = old_stu;
                ob_BindingList.ResetCurrentItem();
            }
            return(num);
        }