You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CaiQie/DB/Service/UserService.cs

162 lines
4.7 KiB
C#

1 month ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
1 month ago
using System.Web.Security;
using System.Windows.Forms.VisualStyles;
1 month ago
using Chloe;
1 month ago
using DB.Dto;
1 month ago
using DB.Entity;
1 month ago
using Tool;
1 month ago
namespace DB.Service
{
public class UserService
{
1 month ago
RoleService roleService=new RoleService();
1 month ago
public UserService()
{
}
1 month ago
public PagedList<UserDto> GetPagedList(int pageIndex, int pageSize, string key)
{
var roleList = roleService.GetList();
List<UserDto> ls = new List<UserDto>();
PagingResult<UserInfo> userInfoPage;
using (var dbContext = DbFactory.GetContext)
{
userInfoPage = dbContext.Query<UserInfo>()
.WhereIfNotNull(key, x => x.UserName.Contains(key))
.OrderBy(x=>x.RoleId)
.Paging(pageIndex, pageSize);
foreach (var userInfo in userInfoPage.DataList)
{
var first = roleList.First(x => x.ID == userInfo.RoleId);
UserDto user = new UserDto
{
Id = userInfo.ID,
UserName = userInfo.UserName,
RoleId = first.ID,
RoleName = first.RoleName,
RoleLevel = first.RoleLevel
};
ls.Add(user);
}
}
PagedList<UserDto> paged = new PagedList<UserDto>(ls, userInfoPage.Totals.ToInt(),pageIndex,pageSize);
return paged;
}
public PagedList<UserDto> GetPagedList(int pageIndex, int pageSize, string key, List<int> lsLevel)
{
var roleList = roleService.GetList();
List<UserDto> ls = new List<UserDto>();
PagingResult<UserInfo> userInfoPage;
using (var dbContext = DbFactory.GetContext)
{
userInfoPage = dbContext.Query<UserInfo>()
.LeftJoin<Role>(((userinfo, role) => userinfo.RoleId == role.ID))
.Select((userinfo, role) => new
{
UserInfo = userinfo,
Role = role
}).WhereIf(!string.IsNullOrEmpty(key), x => x.UserInfo.UserName.Contains(key))
.Where(x=>lsLevel.Contains(x.Role.RoleLevel))
.OrderBy(x => x.Role.RoleLevel)
.Select(x => x.UserInfo)
.Paging(pageIndex, pageSize);
foreach (var userInfo in userInfoPage.DataList)
{
var first = roleList.First(x => x.ID == userInfo.RoleId);
UserDto user = new UserDto
{
Id = userInfo.ID,
UserName = userInfo.UserName,
RoleId = first.ID,
RoleName = first.RoleName,
RoleLevel = first.RoleLevel
};
ls.Add(user);
}
}
PagedList<UserDto> paged = new PagedList<UserDto>(ls, userInfoPage.Totals.ToInt(), pageIndex, pageSize);
return paged;
}
public UserDto GetOne(string name, string pwd)
1 month ago
{
using (var dbContext = DbFactory.GetContext)
{
1 month ago
var userInfo= dbContext.Query<UserInfo>()
1 month ago
.Where(x => x.UserName == name)
.Where(x => x.Pwd == pwd)
.FirstOrDefault();
1 month ago
if (userInfo != null)
{
var first = roleService.GetList().First(x => x.ID == userInfo.RoleId);
UserDto user = new UserDto
{
Id = userInfo.ID,
UserName = userInfo.UserName,
RoleId = first.ID,
RoleName = first.RoleName,
RoleLevel = first.RoleLevel
};
return user;
}
1 month ago
}
1 month ago
return null;
1 month ago
}
public List<string> GetAllName()
{
using (var dbContext = DbFactory.GetContext)
{
return dbContext.Query<UserInfo>()
.Select(x => x.UserName).ToList();
}
}
1 month ago
}
public class RoleService
{
public RoleService()
{
}
public IReadOnlyCollection<Role> GetList()
{
using (var dbContext = DbFactory.GetContext)
{
return dbContext.Query<Role>().ToList();
}
}
1 month ago
}
1 month ago
1 month ago
}