Esempio n. 1
0
 /// <summary>
 /// 查询过滤
 /// </summary>
 /// <param name="whereLambda"></param>
 /// <returns></returns>
 public async Task <ServiceResponse> GetModels(Expression <Func <T, bool> > whereLambda)
 {
     try
     {
         var Task = Db.Set <T>().Where <T>(whereLambda).ToListAsync();
         var List = await Task;
         return(new ServiceResponse()
         {
             Success = true, Results = List
         });
     }
     catch (Exception ex)
     {
         LoggerHelper.WriteLog("查询数据", ex);
         return(new ServiceResponse()
         {
             Success = false, ErrorCode = ex.Message
         });
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 新增更新模块信息
        /// </summary>
        /// <param name="tb_Menus"></param>
        /// <returns></returns>
        public async Task <ServiceResponse> UpdateMenus(List <tb_Menu> tb_Menus)
        {
            try
            {
                using (var db = new ZFSConfig())
                {
                    tb_Menus.ForEach(q =>
                    {
                        var row = db.tb_Menu.FirstOrDefault(x => x.MenuCode.Equals(q.MenuCode));
                        if (row != null)
                        {
                            row.MenuName           = q.MenuName;;
                            row.MenuNameSpace      = q.MenuNameSpace;
                            row.MenuCaption        = q.MenuCaption;
                            row.MenuAuthorities    = q.MenuAuthorities;
                            DbEntityEntry dbEntity = db.Entry <tb_Menu>(row);
                            dbEntity.State         = System.Data.Entity.EntityState.Modified;
                        }
                        else
                        {
                            db.Set <tb_Menu>().Add(q);
                        }
                    });
                    var task = await db.SaveChangesAsync();

                    bool result = task > 0 ? true : false;
                    return(new ServiceResponse()
                    {
                        Success = result
                    });
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.WriteLog("批量更新", ex);
                return(new ServiceResponse()
                {
                    Success = false, ErrorCode = ex.Message
                });
            }
        }