public async Task <bool> IsLockAsync(long id) { using (AdminUserContext ctx = new AdminUserContext()) { BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx); List <ListAdminUserDTO> list = new List <ListAdminUserDTO>(); var entity = await bs.GetAll().AsNoTracking().SingleAsync(e => e.Id == id); if (entity.LoginErrorCount <= 5) { return(false); } double min = (DateTime.Now - entity.LoginErrorTime).TotalMinutes; if (min >= 30) { return(false); } return(true); } }
public async Task <List <ListRolePermissionDTO> > GetByRoleIdAsync(long roleId) { using (AdminUserContext ctx = new AdminUserContext()) { BaseService <RolePermissionEntity> rolePermissionBs = new BaseService <RolePermissionEntity>(ctx); List <ListRolePermissionDTO> list = new List <ListRolePermissionDTO>(); await rolePermissionBs.GetAll() .Include(e => e.Permission) .AsNoTracking() .ForEachAsync(e => { if (e.RoleId == roleId) { list.Add(TODTO(e.Permission)); } }); return(list); } }
public async Task UpdateAsync(UpdateRolePermissionDTO dto) { using (AdminUserContext ctx = new AdminUserContext()) { BaseService <RoleEntity> roleBs = new BaseService <RoleEntity>(ctx); var namePer = await roleBs.GetAll().SingleOrDefaultAsync(e => e.Name == dto.Name); if (namePer != null) { if (dto.Id != namePer.Id) { throw new Exception("权限名已存在"); } } var entity = await roleBs.GetAll().SingleAsync(e => e.Id == dto.Id); entity.Description = dto.Description; entity.Name = dto.Name; await ctx.SaveChangesAsync(); } }
public async Task <long> AddNewAsync(AddRolePermissionDTO dto) { RoleEntity entity = new RoleEntity(); entity.Description = dto.Description; entity.Name = dto.Name; using (AdminUserContext ctx = new AdminUserContext()) { BaseService <RoleEntity> bs = new BaseService <RoleEntity>(ctx); var per = await bs.GetAll().SingleOrDefaultAsync(e => e.Name == dto.Name); if (per != null) { throw new Exception("角色名已存在"); } await ctx.Roles.AddAsync(entity); await ctx.SaveChangesAsync(); return(entity.Id); } }