/// <summary> /// 更新组用户权限 /// </summary> /// <param name="funcList"></param> /// <returns></returns> public async Task <ServiceResponse> UpdateGroupFunc(tb_Group group, List <View_GroupUser> userList, List <tb_GroupFunc> funcList) { try { using (var db = new ZFSConfig()) { if (group.isid.Equals(0)) { db.tb_Group.Add(group); } else { var Group = db.tb_Group.FirstOrDefault(t => t.isid.Equals(group.isid)); Group.GroupName = group.GroupName; DbEntityEntry dbEntity = db.Entry <tb_Group>(Group); dbEntity.State = System.Data.Entity.EntityState.Modified; } //2.更新组用户 var GroupUsers = db.tb_GroupUser.Where(t => t.GroupCode.Equals(group.GroupCode)).ToList(); foreach (var item in GroupUsers) { db.tb_GroupUser.Remove(item); } userList.ForEach(t => { db.tb_GroupUser.Add(new tb_GroupUser() { Account = t.Account, GroupCode = group.GroupCode //组编号 }); }); //3.更新组权限 var groupList = db.tb_GroupFunc.Where(t => t.GroupCode.Equals(group.GroupCode)).ToList(); foreach (var item in groupList) { db.tb_GroupFunc.Remove(item); } funcList.ForEach(t => { db.tb_GroupFunc.Add(t); }); 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 }); } }
/// <summary> /// 登出 /// </summary> /// <param name="account"></param> public async Task <ServiceResponse> Logout(string account) { try { using (var db = new ZFSConfig()) { var model = db.tb_User.FirstOrDefault(t => t.Account.Equals(account)); model.FlagOnline = "0"; DbEntityEntry dbEntity = db.Entry <tb_User>(model); dbEntity.State = System.Data.Entity.EntityState.Modified; 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 }); } }
/// <summary> /// 删除 /// </summary> /// <param name="entity"></param> /// <returns></returns> public async Task <ServiceResponse> DeleteEntity(T entity) { try { Db.Entry <T>(entity).State = EntityState.Deleted; 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 }); } }
/// <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 }); } }