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, IUserRole { public UserRoleModel GetModelById(int id) { var res = (from ur in GetQueryable() join role in DbContext.Set() on ur.RoleId equals role.Id join user in DbContext.Set() 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 GetRolesForUser(int userId) { var roles = (from ru in DbContext.Set() join role in DbContext.Set() 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 GetUsersInRole(int roleId) { var users = (from ru in GetQueryable() join user in DbContext.Set() 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; } } }