Esempio n. 1
0
 public List <T> GetListForPaging(Expression <Func <T, bool> > exp, int page, int pagesize, out int totalcount, out string msg, Func <IQueryable <T>, IOrderedQueryable <T> > orderBy)
 {
     if (page <= 0 || pagesize <= 0)
     {
         page = 1; pagesize = 10;
     }
     msg        = string.Empty;
     totalcount = 0;
     try
     {
         using (L_Sys context = new L_Sys())
         {
             var iquerableresult = context.Set <T>().Where(exp);
             totalcount = iquerableresult.Count();
             var result      = orderBy(iquerableresult).Skip((page - 1) * pagesize).Take(pagesize);
             var result_list = result.ToList();
             return(result_list);
         }
     }
     catch (DbEntityValidationException ex)
     {
         foreach (var item1 in ex.EntityValidationErrors)
         {
             foreach (var item2 in item1.ValidationErrors)
             {
                 msg += item2.ErrorMessage + "<br />";
             }
         }
         return(null);
     }
 }
Esempio n. 2
0
 public int ExecuteSql(string sql, out string msg, params SqlParameter[] param)
 {
     msg = string.Empty;
     try
     {
         using (L_Sys context = new L_Sys())
         {
             var result = context.Database.ExecuteSqlCommand(sql, param);
             return(result);
         }
     }
     catch (Exception ex)
     {
         msg += ex.Message + "\r\n" + ex.StackTrace;
         return(0);
     }
 }
Esempio n. 3
0
 public IPagedList <T> GetPagedList(Expression <Func <T, bool> > exp, int page, int pagesize, out string msg, Func <IQueryable <T>, IOrderedQueryable <T> > orderBy)
 {
     if (page <= 0 || pagesize <= 0)
     {
         page = 1; pagesize = 10;
     }
     msg = string.Empty;
     try
     {
         using (L_Sys context = new L_Sys())
         {
             var iquerableresult = context.Set <T>().Where(exp);
             var result          = orderBy(iquerableresult).ToPagedList <T>(page, pagesize);
             return(result);
         }
     }
     catch (Exception ex)
     {
         msg += ex.Message + "<br />" + ex.StackTrace + "<br />";
         return(null);
     }
 }
Esempio n. 4
0
 public bool RemoveRange(List <T> list, out string msg)
 {
     msg = string.Empty;
     try
     {
         using (L_Sys context = new L_Sys())
         {
             context.Set <T>().RemoveRange(list);
             return(context.SaveChanges() > 0);
         }
     }
     catch (DbEntityValidationException ex)
     {
         foreach (var item1 in ex.EntityValidationErrors)
         {
             foreach (var item2 in item1.ValidationErrors)
             {
                 msg += item2.ErrorMessage + "<br />";
             }
         }
         return(false);
     }
 }
Esempio n. 5
0
 public T Find(Expression <Func <T, bool> > exp, out string msg)
 {
     msg = string.Empty;
     try
     {
         using (L_Sys context = new L_Sys())
         {
             var result = context.Set <T>().FirstOrDefault(exp);
             return(result);
         }
     }
     catch (DbEntityValidationException ex)
     {
         foreach (var item1 in ex.EntityValidationErrors)
         {
             foreach (var item2 in item1.ValidationErrors)
             {
                 msg += item2.ErrorMessage + "<br />";
             }
         }
         return(null);
     }
 }
Esempio n. 6
0
        public List <T> GetListWithSql(string sql, out string msg, params SqlParameter[] param)
        {
            msg = string.Empty;
            try
            {
                using (L_Sys context = new L_Sys())
                {
                    var result = context.Database.SqlQuery <T>(sql, param).ToList <T>();

                    return(result);
                }
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var item1 in ex.EntityValidationErrors)
                {
                    foreach (var item2 in item1.ValidationErrors)
                    {
                        msg += item2.ErrorMessage + "<br />";
                    }
                }
                return(null);
            }
        }
Esempio n. 7
0
 public List <T> GetList(Expression <Func <T, bool> > exp, out string msg)
 {
     msg = string.Empty;
     try
     {
         using (L_Sys context = new L_Sys())
         {
             var result      = context.Set <T>().Where(exp);
             var result_list = result.ToList();
             return(result_list);
         }
     }
     catch (DbEntityValidationException ex)
     {
         foreach (var item1 in ex.EntityValidationErrors)
         {
             foreach (var item2 in item1.ValidationErrors)
             {
                 msg += item2.ErrorMessage + "<br />";
             }
         }
         return(null);
     }
 }
Esempio n. 8
0
 public bool Exist(Expression <Func <T, bool> > exp, out string msg)
 {
     msg = string.Empty;
     try
     {
         using (L_Sys context = new L_Sys())
         {
             var    result     = context.Set <T>().Any(exp);
             string result_str = result.ToString();
             return(result);
         }
     }
     catch (DbEntityValidationException ex)
     {
         foreach (var item1 in ex.EntityValidationErrors)
         {
             foreach (var item2 in item1.ValidationErrors)
             {
                 msg += item2.ErrorMessage + "<br />";
             }
         }
         return(false);
     }
 }
Esempio n. 9
0
 public bool Update(T entity, out string msg)
 {
     msg = string.Empty;
     try
     {
         using (L_Sys context = new L_Sys())
         {
             context.Set <T>().Attach(entity);
             context.Entry <T>(entity).State = EntityState.Modified;
             return(context.SaveChanges() > 0);
         }
     }
     catch (DbEntityValidationException ex)
     {
         foreach (var item1 in ex.EntityValidationErrors)
         {
             foreach (var item2 in item1.ValidationErrors)
             {
                 msg += item2.ErrorMessage + "<br />";
             }
         }
         return(false);
     }
 }