1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using CZFW.Framework.Interface;
- using CZFW.Framework.Model.Entity;
- using CZFW.Framework.Model.ViewModel;
- using System.Collections.Generic;
- using System.Linq;
- using CZFW.Framework.Model;
- namespace CZFW.Framework.Logic
- {
- public class UserRoleLogic : LogicBase<UserRoleEntity>, IUserRole
- {
- public UserRoleModel GetModelById(int id)
- {
- var res = (from ur in GetQueryable()
- join role in DbContext.Set<RoleEntity>() on ur.RoleId equals role.Id
- join user in DbContext.Set<UserInfoEntity>() on ur.UserId equals user.Id
- where ur.Id == ur.Id
- select new UserRoleModel()
- {
- Id = ur.Id,
- UserId = ur.UserId,
- RoleId = ur.RoleId,
- RoleName = role.Name,
- UserDisplayName = user.Name,
- SortOrder = ur.SortOrder ?? 0
- }).FirstOrDefault();
- return res;
- }
- public IList<RoleModel> GetRolesForUser(int userId)
- {
- var roles = (from ru in DbContext.Set<UserRoleEntity>()
- join role in DbContext.Set<RoleEntity>()
- on ru.RoleId equals role.Id
- where ru.UserId == userId
- select new RoleModel()
- {
- Id = ru.RoleId,
- Name = role.Name,
- Description = role.Description
- }).ToList();
- return roles;
- }
- public IList<SimpleUserInfoModel> GetUsersInRole(int roleId)
- {
- var users = (from ru in GetQueryable()
- join user in DbContext.Set<UserInfoEntity>()
- on ru.UserId equals user.Id
- where ru.RoleId == roleId
- select new SimpleUserInfoModel()
- {
- Id = ru.UserId,
- Name = user.Name,
- UserName = user.UserName,
- State = user.State
- }).ToList();
- return users;
- }
- public ResultModel Revoke(int userId, int roleId)
- {
- var res = RemoveEntities(x => x.UserId == userId && x.RoleId == roleId);
- return res;
- }
- }
- }
|