public async Task <UserDto> AddAsync(UserDto inputDto) { var query = _userRepository.GetAll().Where(r => r.UserName == inputDto.UserName || r.Email == inputDto.Email || r.PhoneNum == inputDto.PhoneNum).FirstOrDefault(); if (query != null) { throw new AggregateException("添加失败,用户名或邮箱或电话已存在!"); } var user = AutoMapperExtension.MapTo <UserDto, User>(inputDto); var roIds = inputDto.RoleIds; var result = await _userRepository.InsertAsync(user); if (result != null) { roIds.ForEach(async r => { await _userRoleRepository.InsertAsync(new UserRole() { RoleId = r, UserId = result.Id }); }); return(inputDto); } return(null); }
public static Log_SystemMonitorMQ GetLog_SystemMonitorMQModel(Log_SystemMonitorR oldModel) { if (oldModel == null) { return(null); } Log_SystemMonitorMQ newModel = new Log_SystemMonitorMQ(); try { newModel = AutoMapperExtension.MapTo <Log_SystemMonitorMQ>(oldModel); } catch { newModel = SerializerHelper.ObjectDeepCopy <Log_SystemMonitorMQ>(oldModel); } if (oldModel.DiskSpaceR != null) { newModel.DiskSpaceMQ = new SQLXMLEdm() { IsNull = oldModel.DiskSpaceR.IsNull, Value = oldModel.DiskSpaceR.Value }; } if (oldModel.PageViewNumR != null) { newModel.PageViewNumMQ = new SQLXMLEdm() { IsNull = oldModel.PageViewNumR.IsNull, Value = oldModel.PageViewNumR.Value }; } return(newModel); }
/// <summary> /// 添加角色 /// </summary> /// <param name="dto"></param> /// <returns></returns> public async Task <RoleDto> AddAsync(RoleDto inputDto) { var query = _roleRepository.GetAll().Where(r => r.RoleName.Contains(inputDto.RoleName)).FirstOrDefault(); if (query != null) { throw new AggregateException("添加失败,角色名称已存在!"); } var role = AutoMapperExtension.MapTo <RoleDto, Role>(inputDto); var result = _roleRepository.Insert(role); var permissionIds = inputDto.PermissionIds; if (result != null) { permissionIds.ForEach(r => { _rolePermissionRepository.InsertAsync(new RolePermission() { PermissionId = r, RoleId = inputDto.Id }); }); return(inputDto); } return(null); }
/// <summary> /// 获取所有权限 /// </summary> /// <param name="dto"></param> /// <returns></returns> public IQueryable <PermissionDto> GetAll(PermissionInputDto dto) { var query = _permissionRepository.GetAll(); if (string.IsNullOrEmpty(dto?.SearchPermissionName)) { query = query.Where(u => u.PermissionName.Contains(dto.SearchPermissionName)); } return(AutoMapperExtension.MapTo <Permission, PermissionDto>(query).AsQueryable()); }
/// <summary> /// 获取所有角色 /// </summary> /// <param name="dto"></param> /// <returns></returns> public IQueryable <RoleDto> GetAll(RoleInputDto dto) { var query = _roleRepository.GetAll(); if (string.IsNullOrEmpty(dto?.SearchRoleName)) { query = query.Where(u => u.RoleName.Contains(dto.SearchRoleName)); } return(AutoMapperExtension.MapTo <Role, RoleDto>(query).AsQueryable()); }
/// <summary> /// 获取所有菜单 /// </summary> /// <param name="dto"></param> /// <returns></returns> public IQueryable <MenuDto> GetAll(MenuInputDto dto) { var query = _menuRepository.GetAll(); if (string.IsNullOrEmpty(dto?.SearchMenuName)) { query = query.Where(u => u.MenuName.Contains(dto.SearchMenuName)); } return(AutoMapperExtension.MapTo <Menu, MenuDto>(query).AsQueryable()); }
/// <summary> /// 根据id获取权限 /// </summary> /// <param name="id"></param> /// <returns></returns> public PermissionDto Get(long id) { var role = _permissionRepository.Get(id); if (role != null) { return(AutoMapperExtension.MapTo <Permission, PermissionDto>(role)); } return(null); }
/// <summary> /// 根据id获取权限 /// </summary> /// <param name="id"></param> /// <returns></returns> public MenuDto Get(long id) { var role = _menuRepository.Get((int)id); if (role != null) { return(AutoMapperExtension.MapTo <Menu, MenuDto>(role)); } return(null); }
/// <summary> /// 根据id获取角色 /// </summary> /// <param name="id"></param> /// <returns></returns> public RoleDto Get(long id) { var role = _roleRepository.Get(id); if (role != null) { return(AutoMapperExtension.MapTo <Role, RoleDto>(role)); } return(null); }
/// <summary> /// 分页获取权限列表 /// </summary> /// <param name="dto"></param> /// <returns></returns> public IQueryable <MenuDto> GetPageList(MenuInputDto dto) { var query = _menuRepository.GetAll(); int count = query.Count(); if (string.IsNullOrEmpty(dto?.SearchMenuName)) { query = query.Where(u => u.MenuName.Contains(dto.SearchMenuName)); } query = query.Skip((dto.PageIndex - 1) * dto.PageSize).Take(dto.PageSize); return(AutoMapperExtension.MapTo <Menu, MenuDto>(query).AsQueryable()); }
/// <summary> /// 分页获取用户列表 /// </summary> /// <param name="dto"></param> /// <returns></returns> public IQueryable <UserDto> GetPageList(UserInputDto dto) { var query = _userRepository.GetAll(); int count = query.Count(); if (string.IsNullOrEmpty(dto.SearchInputStr)) { query = query.Where(u => u.Email == dto.SearchInputStr || u.PhoneNum == dto.SearchInputStr || u.UserName == dto.SearchInputStr); } query = query.Skip((dto.PageIndex - 1) * dto.PageSize).Take(dto.PageSize); return(AutoMapperExtension.MapTo <User, UserDto>(query).AsQueryable()); }
public static Log_OperateTrace GetLog_OperateTraceModel(Log_OperateTraceR oldModel) { if (oldModel == null) { return(null); } try { return(AutoMapperExtension.MapTo <Log_OperateTrace>(oldModel)); } catch { var newModel = SerializerHelper.ObjectDeepCopy <Log_OperateTrace>(oldModel); return(newModel); } }
/// <summary> /// 添加权限 /// </summary> /// <param name="dto"></param> /// <returns></returns> public MenuDto Add(MenuDto dto) { var query = _menuRepository.GetAll().Where(r => r.MenuName.Contains(dto.MenuName)).FirstOrDefault(); if (query != null) { throw new AggregateException("添加失败,角色名称已存在!"); } var role = AutoMapperExtension.MapTo <MenuDto, Menu>(dto); var result = _menuRepository.Insert(role); if (result != null) { return(AutoMapperExtension.MapTo <Menu, MenuDto>(result)); } return(null); }
/// <summary> /// 修改权限 /// </summary> /// <param name="user"></param> /// <returns></returns> public PermissionDto Update(PermissionDto dto) { var query = _permissionRepository.GetAll().Where(r => r.PermissionName.Contains(dto.PermissionName) && r.Id != dto.Id).FirstOrDefault(); if (query != null) { throw new AggregateException("修改失败,角色名称已存在!"); } var role = AutoMapperExtension.MapTo <PermissionDto, Permission>(dto); var result = _permissionRepository.Update(role); if (result != null) { return(AutoMapperExtension.MapTo <Permission, PermissionDto>(result)); } return(null); }
/// <summary> /// 根据id获取用户 /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <UserDto> GetAsync(long id) { var user = await _userRepository.GetAsync(id); if (user != null) { UserDto userDto = AutoMapperExtension.MapTo <User, UserDto>(user); var list = await _userRoleRepository.GetAll().Include(r => r.User).Include(r => r.Role).Where(r => r.UserId == id).ToListAsync(); //await _userRoleRepository.GetAllListAsync(r => r.UserId == id); userDto.RoleIds = new List <long>(); userDto.RoleNames = new List <string>(); list.ForEach(r => { userDto.RoleIds.Add(r.RoleId); userDto.RoleNames.Add(r.Role.RoleName); }); return(userDto); } return(null); }
public static Log_SystemMonitor GetLog_SystemMonitorModel(Log_SystemMonitorMQ oldModel) { if (oldModel == null) { return(null); } Log_SystemMonitor newModel = new Log_SystemMonitor(); try { newModel = AutoMapperExtension.MapTo <Log_SystemMonitor>(oldModel); } catch { newModel = SerializerHelper.ObjectDeepCopy <Log_SystemMonitor>(oldModel); } newModel.DiskSpace = /* GetSQLXml */ GetSQLXmlString <DiskSpaceEdm>(oldModel.DiskSpaceMQ); newModel.PageViewNum = /* GetSQLXml */ GetSQLXmlString <PageVist>(oldModel.PageViewNumMQ); return(newModel); }
/// <summary> /// 修改角色 /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <RoleDto> UpdateAsync(RoleDto inputDto) { var query = _roleRepository.GetAll().Where(r => r.RoleName.Contains(inputDto.RoleName) && r.Id != inputDto.Id).FirstOrDefault(); if (query != null) { throw new AggregateException("修改失败,角色名称已存在!"); } var role = AutoMapperExtension.MapTo <RoleDto, Role>(inputDto); var result = _roleRepository.Update(role); var permissionIds = inputDto.PermissionIds; var rolePermissions = await _rolePermissionRepository.GetAllListAsync(t => t.RoleId == inputDto.Id); rolePermissions.ForEach(async r => { if (!permissionIds.Contains(r.PermissionId)) { await _rolePermissionRepository.DeleteAsync(r); } else { permissionIds.Remove(r.PermissionId); } }); permissionIds.ForEach(r => { _rolePermissionRepository.InsertAsync(new RolePermission() { PermissionId = r, RoleId = inputDto.Id }); }); if (result != null) { return(inputDto); } return(null); }
/// <summary> /// 修改用户 /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <UserDto> UpdateAsync(UserDto inputDto) { var query = _userRepository.GetAll().Where(r => r.UserName == inputDto.UserName || r.Email == inputDto.Email || r.PhoneNum == inputDto.PhoneNum).FirstOrDefault(); if (query != null) { throw new AggregateException("修改失败,用户名或邮箱或电话已存在!"); } var user = AutoMapperExtension.MapTo <UserDto, User>(inputDto); var roIds = inputDto.RoleIds; var userRoles = await _userRoleRepository.GetAllListAsync(t => t.UserId == inputDto.Id); userRoles.ForEach(async t => { if (!inputDto.RoleIds.Contains(t.RoleId)) { await _userRoleRepository.DeleteAsync(t); } else { roIds.Remove(t.RoleId); } }); roIds.ForEach(async r => { await _userRoleRepository.InsertAsync(new UserRole() { RoleId = r, UserId = inputDto.Id }); }); var result = await _userRepository.UpdateAsync(user); if (result != null) { return(inputDto); } return(null); }
/// <summary> /// 获取所有权限 /// </summary> /// <returns></returns> public IQueryable <PermissionDto> GetAll() { var query = _permissionRepository.GetAll(); return(AutoMapperExtension.MapTo <Permission, PermissionDto>(query).AsQueryable()); }