/// <summary> /// 分页查询 /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <PagedList <QueryAdPlaceItem> > PagedQueryAdPlaces(ServRequest <PagedQueryAdPlaceDto> request) { var page = request.Data.Page ?? 1; var pageSize = request.Data.PageSize ?? 20; using (var client = DbFactory.GetClient()) { var total = 0; var list = client.Queryable <AdPlace>() .WhereIF(!request.Data.Keyword.IsNullOrEmpty(), t => t.Title.Contains(request.Data.Keyword)) .Select(t => new QueryAdPlaceItem() { Id = t.Id, Title = t.Title, Code = t.Code, Desc = t.Desc, AddTime = t.Addtime, }) .OrderBy("id DESC") .ToPageList(page, pageSize, ref total); return(new PagedList <QueryAdPlaceItem> { List = list, Page = page, PageSize = pageSize, TotalCount = total }); } }
/// <summary> /// 分页查询 /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <PagedList <QueryAdItem> > PagedQueryAds(ServRequest <PagedQueryAdsDto> request) { var page = request.Data.Page ?? 1; var pageSize = request.Data.PageSize ?? 20; using (var client = DbFactory.GetClient()) { var total = 0; var list = client.Queryable <Ad>() .Where(it => it.AdPlaceId == request.Data.AdPlaceId) .WhereIF(!request.Data.Keyword.IsNullOrEmpty(), it => it.Title.Contains(request.Data.Keyword)) .Select(t => new QueryAdItem() { Id = t.Id, AdPlaceId = t.AdPlaceId, Title = t.Title, ImagePath = t.ImagePath, TargetUrl = t.TargetUrl, Order = t.OrderIndex, IsShow = t.IsShow, }) .OrderBy("order_index ASC,id DESC") .ToPageList(page, pageSize, ref total); return(new PagedList <QueryAdItem> { List = list, Page = page, PageSize = pageSize, TotalCount = total }); } }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <GetMenusByRoleApo> GetMenusByRole(ServRequest <GetMenusByRoleDto> request) { using (var client = DbFactory.GetClient()) { var list = client.Queryable <RoleMenu, AdminMenu>((rm, m) => new object[] { JoinType.Left, rm.MenuId == m.Id }) .Where((rm, m) => rm.RoleId == request.Data.RoleId) .Select((rm, m) => new AdminMenu() { Icon = m.Icon, Id = m.Id, IsSystem = m.IsSystem, Link = m.Link, Name = m.Name, OrderIndex = m.OrderIndex, ParentId = m.ParentId }) .OrderBy("order_index ASC, id ASC") .ToList(); return(new GetMenusByRoleApo() { Menus = list }); } }
/// <summary> /// 分页查询 /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <PagedList <QueryRoleItem> > PagedQueryRoles(ServRequest <PagedQueryRoleDto> request) { var page = request.Data.Page ?? 1; var pageSize = request.Data.PageSize ?? 20; using (var client = DbFactory.GetClient()) { var total = 0; var list = client.Queryable <Role>() .WhereIF(!string.IsNullOrEmpty(request.Data.Keyword), t => t.Name.Contains(request.Data.Keyword)) .Select(t => new QueryRoleItem() { Id = t.Id, Name = t.Name, IsActive = t.IsActive, Code = t.Code, IsAdmin = t.IsAdmin, IsSystem = t.IsSystem, }) .OrderBy("id ASC") .ToPageList(page, pageSize, ref total); return(new PagedList <QueryRoleItem> { List = list, Page = page, PageSize = pageSize, TotalCount = total }); } }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <GetPermissionsByRoleApo> GetPermissionsByRole(ServRequest <GetPermissionsByRoleDto> request) { using (var client = DbFactory.GetClient()) { var list = client.Queryable <RolePermission, Permission>((rp, p) => new object[] { JoinType.Left, rp.PermissionId == p.Id }) .Where((rp, p) => rp.RoleId == request.Data.RoleId) .Select((rp, p) => new Permission() { Code = p.Code, Id = p.Id, IsActive = p.IsActive, Name = p.Name, ParentId = p.ParentId }) .OrderBy("order_index ASC, id ASC") .ToList(); return(new GetPermissionsByRoleApo() { Permissions = list }); } }
/// <summary> /// 更新 /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult UpdateRole(ServRequest <UpdateRoleDto> request) { Role role = null; using (var client = DbFactory.GetClient()) { role = client.Queryable <Role>().InSingle(request.Data.Id); if (role == null) { return(Error("找不到该条信息")); } if (role.IsSystem) { return(Error("内置用户不能修改")); } role.Name = request.Data.Name; role.IsActive = request.Data.IsActive; role.Code = request.Data.Code; role.IsAdmin = request.Data.IsAdmin; client.Updateable(role).ExecuteCommand(); } _distributedCache.Remove(PermissionService.CACHE_ROLE_PERMISSION_ALL_KEY); _distributedCache.Remove(CACHE_ROLE_ALL_KEY); _eventPublisher.EntityUpdated(role); return(Ok()); }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult SetIsAdmin(ServRequest <SetIsAdminRoleDto> request) { using (var client = DbFactory.GetClient()) { var role = client.Queryable <Role>().InSingle(request.Data.Id); if (role == null) { return(Error("找不到该条信息")); } if (role.IsSystem) { return(Error("内置用户不能删除")); } client.Updateable <Role>() .SetColumns(it => new Role() { IsAdmin = !it.IsAdmin }) .Where(it => it.Id == request.Data.Id) .ExecuteCommand(); } _distributedCache.Remove(PermissionService.CACHE_ROLE_PERMISSION_ALL_KEY); _distributedCache.Remove(CACHE_ROLE_ALL_KEY); return(Ok()); }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <ScheduleTaskDetailApo> GetScheduleTaskDetail(ServRequest <GetScheduleTaskDetailDto> request) { using (var client = DbFactory.GetClient()) { var scheduleTask = client.Queryable <ScheduleTask>().InSingle(request.Data.Id); if (scheduleTask == null) { return(Error("找不到该数据")); } var resp = new ScheduleTaskDetailApo(); resp.Id = scheduleTask.Id; resp.Name = scheduleTask.Name; resp.Status = scheduleTask.Status; resp.StatusDesc = scheduleTask.StatusDesc; resp.JobKey = scheduleTask.JobKey; resp.JobGroup = scheduleTask.JobGroup; resp.TriggerKey = scheduleTask.TriggerKey; resp.TriggerGroup = scheduleTask.TriggerGroup; resp.IsEnable = scheduleTask.IsEnable; resp.Type = scheduleTask.Type; resp.Cron = scheduleTask.Cron; resp.Interval = scheduleTask.Interval; resp.LastStartTime = scheduleTask.LastStartTime; resp.LastEndTime = scheduleTask.LastEndTime; resp.LastSuccessTime = scheduleTask.LastSuccessTime; return(resp); } }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult CreateScheduleTask(ServRequest <CreateScheduleTaskDto> request) { using (var client = DbFactory.GetClient()) { var scheduleTask = new ScheduleTask { Name = request.Data.Name, Status = TaskRunningStatus.Pending, StatusDesc = "", JobKey = Guid.NewGuid().ToString("N"), JobGroup = Guid.NewGuid().ToString("N"), TriggerKey = Guid.NewGuid().ToString("N"), TriggerGroup = Guid.NewGuid().ToString("N"), IsEnable = false, Type = request.Data.Type, Cron = request.Data.Cron, Interval = null, LastStartTime = null, LastEndTime = null, LastSuccessTime = null }; scheduleTask.Id = client.Insertable(scheduleTask).ExecuteReturnBigIdentity(); _eventPublisher.EntityCreated(scheduleTask); return(Ok()); } }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult UpdateScheduleTask(ServRequest <UpdateScheduleTaskDto> request) { using (var client = DbFactory.GetClient()) { var scheduleTask = client.Queryable <ScheduleTask>().InSingle(request.Data.Id); if (scheduleTask == null) { return(Error("找不到该条信息")); } if (scheduleTask.IsEnable) { return(Error("请先关闭定时任务再删除")); } scheduleTask.Name = request.Data.Name; scheduleTask.Cron = request.Data.Cron; client.Updateable(scheduleTask).UpdateColumns(t => new { t.Name, t.Cron }).ExecuteCommand(); _eventPublisher.EntityUpdated(scheduleTask); return(Ok()); } }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> /// <exception cref="MozException"></exception> public ServResult UpdateAdminMenu(ServRequest <UpdateAdminMenuDto> request) { AdminMenu adminMenu; using (var client = DbFactory.GetClient()) { adminMenu = client.Queryable <AdminMenu>().InSingle(request.Data.Id); if (adminMenu == null) { return(Error("找不到该条信息")); } if (adminMenu.IsSystem) { return(Error("不能编辑内置菜单")); } adminMenu.Name = request.Data.Name; adminMenu.ParentId = request.Data.ParentId; adminMenu.Link = request.Data.Link; adminMenu.OrderIndex = request.Data.OrderIndex; adminMenu.Icon = request.Data.Icon; client.Updateable(adminMenu).ExecuteCommand(); } _eventPublisher.EntityUpdated(adminMenu); return(Ok()); }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <PagedList <QueryAdminMenuItem> > PagedQueryAdminMenus(ServRequest <PagedQueryAdminMenusDto> request) { var page = request.Data.Page ?? 1; var pageSize = request.Data.PageSize ?? 20; using (var client = DbFactory.GetClient()) { var total = 0; var list = client.Queryable <AdminMenu>() .WhereIF(!request.Data.Keyword.IsNullOrEmpty(), t => t.Name.Contains(request.Data.Keyword)) .Select(t => new QueryAdminMenuItem() { Id = t.Id, Name = t.Name, ParentId = t.ParentId, Link = t.Link, OrderIndex = t.OrderIndex, Icon = t.Icon, IsSystem = t.IsSystem }) .OrderBy("order_index ASC, id ASC") .ToPageList(page, pageSize, ref total); return(new PagedList <QueryAdminMenuItem> { List = list, Page = page, PageSize = pageSize, TotalCount = total }); } }
/// <summary> /// 获取详细 /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <RoleDetailApo> GetRoleDetail(ServRequest <GetRoleDetailDto> request) { Role role = null; using (var client = DbFactory.GetClient()) { role = client.Queryable <Role>().InSingle(request.Data.Id); } if (role == null) { return(Error("找不到数据")); } var res = new RoleDetailApo { Id = role.Id, Name = role.Name, IsActive = role.IsActive, Code = role.Code, IsAdmin = role.IsAdmin, IsSystem = role.IsSystem }; return(res); }
/* * /// <summary> * /// 批量删除 * /// </summary> * /// <param name="request"></param> * /// <returns></returns> * public ServResult BulkDeleteCategories(ServRequest<BulkDeleteCategoriesDto> request) * { * using (var client = DbFactory.GetClient()) * { * client.Deleteable<Category>().In(request.Data.Ids).ExecuteCommand(); * } * _eventPublisher.EntitiesDeleted<Category>(request.Data.Ids); * return Ok(); * } */ /// <summary> /// 分页查询 /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <PagedList <QueryCategoryItem> > PagedQueryCategories(ServRequest <PagedQueryCategoryDto> request) { var page = request.Data.Page ?? 1; var pageSize = request.Data.PageSize ?? 1000; using (var client = DbFactory.GetClient()) { var total = 0; var list = client.Queryable <Category>() //.WhereIF(!request.Keyword.IsNullOrEmpty(), t => t.Name.Contains(request.Keyword)) .Select(t => new QueryCategoryItem() { Id = t.Id, Name = t.Name, Alias = t.Alias, Desciption = t.Description, OrderIndex = t.OrderIndex, ParentId = t.ParentId, Path = t.Path, }) .OrderBy("order_index ASC, id DESC") .ToPageList(page, pageSize, ref total); return(new PagedList <QueryCategoryItem> { List = list, Page = page, PageSize = pageSize, TotalCount = total }); } }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <GetAdsByCodeApo> GetAdsByCode(ServRequest <GetAdsByCodeDto> request) { using (var client = DbFactory.GetClient()) { var list = client.Queryable <Ad, AdPlace>((ad, place) => new object[] { JoinType.Left, ad.AdPlaceId == place.Id }) .Where((ad, place) => ad.IsShow && place.Code.Equals(request.Data.Code, StringComparison.OrdinalIgnoreCase)) .Select((ad, place) => new { Id = ad.Id, Title = ad.Title, ImagePath = ad.ImagePath, TargetUrl = ad.TargetUrl, }) .OrderBy("order_index ASC,id DESC") .ToList(); return(new GetAdsByCodeApo() { Ads = list.Select(it => new GetAdsByCodeItem { Id = it.Id, Title = it.Title, ImagePath = it.ImagePath.GetFullPath(), TargetUrl = it.TargetUrl }).ToList() }); } }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> /// <exception cref="MozException"></exception> public ServResult ChangePassword(ServRequest <ChangePasswordDto> request) { using (var db = DbFactory.GetClient()) { var member = db.Queryable <Member>().InSingle(request.Data.MemberId); if (member == null) { return(Error("找不到该用户")); } var inputEncryptOldPassword = _encryptionService.CreatePasswordHash(request.Data.OldPassword, member.PasswordSalt, _memberSettings.HashedPasswordFormat); if (!inputEncryptOldPassword.Equals(member.Password, StringComparison.OrdinalIgnoreCase)) { return(Error("原密码不正确")); } var saltKey = _encryptionService.CreateSaltKey(6); var newPassword = _encryptionService.CreatePasswordHash(request.Data.NewPassword, saltKey, _memberSettings.HashedPasswordFormat); member.Password = newPassword; member.PasswordSalt = saltKey; db.Updateable(member).UpdateColumns(it => new { it.Password, it.PasswordSalt }).ExecuteCommand(); } return(Ok()); }
/// <summary> /// 更新 /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult UpdatePermission(ServRequest <UpdatePermissionDto> request) { Permission permission = null; using (var client = DbFactory.GetClient()) { permission = client.Queryable <Permission>().InSingle(request.Data.Id); if (permission == null) { return(Error("找不到该条信息")); } if (permission.IsSystem) { return(Error("内置信息不能修改")); } permission.Name = request.Data.Name; permission.Code = request.Data.Code; permission.IsActive = request.Data.IsActive; permission.ParentId = request.Data.ParentId; client.Updateable(permission).ExecuteCommand(); } _distributedCache.Remove(CACHE_ROLE_PERMISSION_ALL_KEY); _distributedCache.Remove(CACHE_PERMISSION_ALL_KEY); _eventPublisher.EntityUpdated(permission); return(Ok()); }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult ResetPassword(ServRequest <ResetPasswordDto> request) { using (var db = DbFactory.GetClient()) { var members = db.Queryable <Member>() .Select(it => new Member { Id = it.Id, Password = it.Password, PasswordSalt = it.PasswordSalt }) .Where(it => request.Data.MemberIds.Contains(it.Id)) .ToList(); var saltKey = _encryptionService.CreateSaltKey(6); var newPassword = _encryptionService .CreatePasswordHash(request.Data.NewPassword, saltKey, _memberSettings.HashedPasswordFormat); members.ForEach(it => { it.Password = newPassword; it.PasswordSalt = saltKey; }); db.Updateable(members) .UpdateColumns(it => new { it.Password, it.PasswordSalt }) .ExecuteCommand(); return(Ok()); } }
/// <summary> /// 获取详细 /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <PermissionDetailApo> GetPermissionDetail(ServRequest <GetPermissionDetailDto> request) { Permission permission = null; using (var client = DbFactory.GetClient()) { permission = client.Queryable <Permission>().InSingle(request.Data.Id); } if (permission == null) { return(null); } var res = new PermissionDetailApo { Id = permission.Id, Name = permission.Name, Code = permission.Code, IsActive = permission.IsActive, ParentId = permission.ParentId, OrderIndex = permission.OrderIndex, IsSystem = permission.IsSystem }; return(res); }
/// <summary> /// 分页查询 /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <PagedList <QueryPermissionItem> > PagedQueryPermissions(ServRequest <PagedQueryPermissionDto> request) { var page = request.Data.Page ?? 1; var pageSize = request.Data.PageSize ?? 20; using (var client = DbFactory.GetClient()) { var total = 0; var list = client.Queryable <Permission>() //.WhereIF(!request.Keyword.IsNullOrEmpty(), t => t.Name.Contains(request.Keyword)) .Select(t => new QueryPermissionItem() { Id = t.Id, Name = t.Name, Code = t.Code, IsActive = t.IsActive, ParentId = t.ParentId, OrderIndex = t.OrderIndex, IsSystem = t.IsSystem, }) .OrderBy("order_index ASC,id ASC") .ToPageList(page, pageSize, ref total); return(new PagedList <QueryPermissionItem> { List = list, Page = page, PageSize = pageSize, TotalCount = total }); } }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult SetIsActive(ServRequest <SetIsActivePermissionDto> request) { Permission permission = null; using (var client = DbFactory.GetClient()) { permission = client.Queryable <Permission>().InSingle(request.Data.Id); if (permission == null) { return(Error("找不到该条信息")); } if (permission.IsSystem) { return(Error("内置信息不能修改")); } client.Updateable <Permission>().SetColumns(it => new Permission { IsActive = !it.IsActive }).Where(it => it.Id == request.Data.Id).ExecuteCommand(); } _distributedCache.Remove(CACHE_ROLE_PERMISSION_ALL_KEY); _distributedCache.Remove(CACHE_PERMISSION_ALL_KEY); _eventPublisher.EntityDeleted(permission); return(Ok()); }
/// <summary> /// 批量删除 /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult BulkDeleteAdPlaces(ServRequest <BulkDeleteAdPlacesDto> request) { using (var client = DbFactory.GetClient()) { client.Deleteable <AdPlace>().In(request.Data.Ids).ExecuteCommand(); _eventPublisher.EntitiesDeleted <AdPlace>(request.Data.Ids); return(Ok()); } }
/// <summary> /// 根据别名获取路径 /// </summary> /// <param name="request"></param> /// <returns></returns> public ServRequest <string> GetCategoryPathByAlias(ServRequest <string> request) { if (request.Data.IsNullOrEmpty()) { return(null); } var list = GetCategoriesListCached(); return(list.FirstOrDefault(it => it.Alias.Equals(request.Data, StringComparison.OrdinalIgnoreCase)) ?.Path); }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult SetOrderIndex(ServRequest <SetOrderIndexDto> request) { using (var client = DbFactory.GetClient()) { client.Updateable <Category>().SetColumns(it => new Category { OrderIndex = request.Data.OrderIndex }).Where(it => it.Id == request.Data.Id).ExecuteCommand(); } return(Ok()); }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <QueryChildrenByParentIdApo> QueryChildrenByParentId(ServRequest <QueryChildrenByParentIdDto> request) { using (var client = DbFactory.GetClient()) { var list = client.Queryable <AdminMenu>().ToList(); var menus = GetAllSubAdminMenus(list, request.Data.ParentId); return(new QueryChildrenByParentIdApo() { AllSubs = menus }); } }
/// <summary> /// 获取详细 /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult <GetMemberDetailApo> GetMemberDetail(ServRequest <GetMemberDetailDto> request) { using (var client = DbFactory.GetClient()) { var member = client.Queryable <Member>().InSingle(request.Data.Id); if (member == null) { return(Error("找不着信息")); } var roles = client.Queryable <MemberRole>() .Where(it => it.MemberId == request.Data.Id) .Select(it => new { it.RoleId }) .ToList() .Select(it => it.RoleId).ToArray(); var resp = new GetMemberDetailApo { Id = member.Id, Username = member.Username, Email = member.Email, Mobile = member.Mobile, Avatar = member.Avatar, Gender = member.Gender, Birthday = member.Birthday, RegisterIp = member.RegisterIp, RegisterDatetime = member.RegisterDatetime, LoginCount = member.LoginCount, LastLoginIp = member.LastLoginIp, LastLoginDatetime = member.LastLoginDatetime, CannotLoginUntilDate = member.CannotLoginUntilDate, LastActiveDatetime = member.LastActiveDatetime, FailedLoginAttempts = member.FailedLoginAttempts, OnlineTimeCount = member.OnlineTimeCount, Address = member.Address, RegionCode = member.RegionCode, Lng = member.Lng, Lat = member.Lat, Geohash = member.Geohash, IsActive = member.IsActive, IsDelete = member.IsDelete, IsEmailValid = member.IsEmailValid, IsMobileValid = member.IsMobileValid, Nickname = member.Nickname, Roles = roles }; return(resp); } }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> /// <exception cref="MozException"></exception> public ServResult SetAdminMenuOrderIndex(ServRequest <SetAdminMenuOrderIndexDto> request) { using (var client = DbFactory.GetClient()) { var menu = client.Queryable <AdminMenu>().InSingle(request.Data.Id); if (menu == null) { return(Error("找不到该条信息")); } menu.OrderIndex = int.Parse(request.Data.OrderIndex); client.Updateable(menu).UpdateColumns(t => new { t.OrderIndex }).ExecuteCommand(); return(Ok()); } }
/// <summary> /// 删除 /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult DeleteAdPlace(ServRequest <DeleteAdPlaceDto> request) { using (var client = DbFactory.GetClient()) { var adPlace = client.Queryable <AdPlace>().InSingle(request.Data.Id); if (adPlace == null) { return(Error("找不到该条信息")); } client.Deleteable <AdPlace>(request.Data.Id).ExecuteCommand(); _eventPublisher.EntityDeleted(adPlace); return(Ok()); } }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult ConfigPermission(ServRequest <ConfigPermissionDto> request) { using (var client = DbFactory.GetClient()) { var list = client.Queryable <RolePermission, Permission>((rp, p) => new object[] { JoinType.Left, rp.PermissionId == p.Id }) .Where((rp, p) => rp.RoleId == request.Data.RoleId) .Select((rp, p) => new { PermissionId = p.Id, RolePermissonId = rp.Id }) .ToList(); client.UseTran(tran => { var willAddPermissions = request.Data.ConfigedPermissions .Where(t => list.All(x => x.PermissionId != t.Id)) .Select(t => new RolePermission() { PermissionId = t.Id, RoleId = request.Data.RoleId }) .ToList(); var willRemovePermissions = list .Where(t => request.Data.ConfigedPermissions.All(x => x.Id != t.PermissionId)) .Select(t => t.RolePermissonId) .ToList(); if (willAddPermissions.Any()) { tran.Insertable <RolePermission>(willAddPermissions).ExecuteCommand(); } if (willRemovePermissions.Any()) { tran.Deleteable <RolePermission>().In(willRemovePermissions).ExecuteCommand(); } return(0); }); _distributedCache.Remove(PermissionService.CACHE_ROLE_PERMISSION_ALL_KEY); return(Ok()); } }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ServResult ConfigMenu(ServRequest <ConfigMenuDto> request) { using (var client = DbFactory.GetClient()) { var list = client.Queryable <RoleMenu, AdminMenu>((rm, m) => new object[] { JoinType.Left, rm.MenuId == m.Id }) .Where((rm, m) => rm.RoleId == request.Data.RoleId) .Select((rm, m) => new { MenuId = m.Id, RoleMenuId = rm.Id }) .ToList(); client.UseTran(tran => { var willAddMenus = request.Data.ConfigedMenus .Where(t => list.All(x => x.MenuId != t.Id)) .Select(t => new RoleMenu() { MenuId = t.Id, RoleId = request.Data.RoleId }) .ToList(); var willRemoveMenus = list .Where(t => request.Data.ConfigedMenus.All(x => x.Id != t.MenuId)) .Select(t => t.RoleMenuId) .ToList(); if (willAddMenus.Any()) { tran.Insertable <RoleMenu>(willAddMenus).ExecuteCommand(); } if (willRemoveMenus.Any()) { tran.Deleteable <RoleMenu>().In(willRemoveMenus).ExecuteCommand(); } return(0); }); return(Ok()); } }