Пример #1
0
 public static T Find(params object[] keyValues)
 {
     using (MVCDemoDBEntities db = new MVCDemoDBEntities())
     {
         return(db.Set <T>().Find(keyValues));
     }
 }
Пример #2
0
 public List <T> FindAll()
 {
     using (MVCDemoDBEntities db = new MVCDemoDBEntities())
     {
         return(db.Set <T>().ToList());
     }
 }
Пример #3
0
 public static void Delete(T model)
 {
     using (MVCDemoDBEntities db = new MVCDemoDBEntities())
     {
         db.Set <T>().Remove(model);
         db.SaveChanges();
     }
 }
Пример #4
0
 public static void AddAdmin(Admin admin)
 {
     using (MVCDemoDBEntities db = new MVCDemoDBEntities())
     {
         db.Admin.Add(admin);
         db.SaveChanges();
     }
 }
Пример #5
0
 public static List <T> Search <TKey>(Expression <Func <T, bool> > expression, Expression <Func <T, TKey> > orderBy, int pageIndex, int pageSize, out int totalCount)
 {
     using (MVCDemoDBEntities db = new MVCDemoDBEntities())
     {
         totalCount = db.Set <T>().Where(expression).Count();
         return(db.Set <T>().Where(expression).OrderByDescending(orderBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList());
     }
 }
Пример #6
0
 public static List <Admin> SearchByConditions(Expression <Func <Admin, bool> > expression, int pageIndex, int pageSize, out int totalCount)
 {
     using (MVCDemoDBEntities db = new MVCDemoDBEntities())
     {
         totalCount = db.Admin.Where(expression).Count();
         return(db.Admin.Where(expression).OrderByDescending(i => i.CreatedTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList());
     }
 }
Пример #7
0
 public static T Add(T model)
 {
     using (MVCDemoDBEntities db = new MVCDemoDBEntities())
     {
         db.Set <T>().Add(model);
         db.SaveChanges();
     }
     return(model);
 }
Пример #8
0
 public static void EditAdmin(Admin admin)
 {
     using (MVCDemoDBEntities db = new MVCDemoDBEntities())
     {
         db.Set <Admin>().Attach(admin);
         db.Entry <Admin>(admin).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Пример #9
0
        public static Admin GetAdminByID(int id)
        {
            Admin admin;

            using (MVCDemoDBEntities db = new MVCDemoDBEntities())
            {
                admin = db.Admin.Find(id);
            }
            return(admin);
        }
Пример #10
0
 /// <summary>
 /// 根据类型查询字典
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static List <Dictionary> GetDictionaryByType(string type)
 {
     if (!string.IsNullOrEmpty(type))
     {
         using (MVCDemoDBEntities db = new MVCDemoDBEntities())
         {
             List <Dictionary> dictionarys = db.Dictionary.Where(m => m.Type == type && m.IsDeleted == false).ToList();
             return(dictionarys);
         }
     }
     return(null);
 }
Пример #11
0
 public static void Delete(params object[] keyValues)
 {
     using (MVCDemoDBEntities db = new MVCDemoDBEntities())
     {
         T model = db.Set <T>().Find(keyValues);
         if (model != null)
         {
             db.Set <T>().Remove(model);
             db.SaveChanges();
         }
     }
 }
Пример #12
0
 public static void DeleteLogical(int id)
 {
     using (MVCDemoDBEntities db = new MVCDemoDBEntities())
     {
         Role role = db.Role.Find(id);
         if (role != null)
         {
             role.IsDeleted = true;
             db.SaveChanges();
         }
     }
 }
Пример #13
0
 public static void DeleteAdmin(int id)
 {
     using (MVCDemoDBEntities db = new MVCDemoDBEntities())
     {
         Admin admin = db.Admin.Find(id);
         if (admin != null)
         {
             admin.IsDeleted = true;
         }
         db.SaveChanges();
     }
 }
Пример #14
0
 public static T Update(T model)
 {
     using (MVCDemoDBEntities db = new MVCDemoDBEntities())
     {
         if (db.Entry <T>(model).State == EntityState.Modified)
         {
             db.SaveChanges();
         }
         else if (db.Entry <T>(model).State == EntityState.Detached)
         {
             db.Set <T>().Attach(model);
             db.Entry <T>(model).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     return(model);
 }