public async Task <ActionResult <dynamic> > Post([FromServices] DataContext context, [FromBody] UserLoginDTO model) { if (ModelState.IsValid) { var user = await context.Users .AsNoTracking() .Where(x => x.Email == model.Email && x.Password == model.Password) .FirstOrDefaultAsync(); if (user == null) { return(NotFound(new { message = "Usuário ou senha inválidos" })); } var token = TokenService.GenerateToken(user); UserResultDTO dto = new UserResultDTO { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Role = user.Role }; return(new { user = dto, token = token }); } else { return(BadRequest(ModelState)); } }
public async Task <ActionResult <dynamic> > RefreshToken([FromServices] DataContext context) { var email = User.Claims .Where(c => c.Type == ClaimTypes.Email) .Select(v => v.Value).FirstOrDefault(); var user = await context.Users .AsNoTracking() .Where(x => x.Email == email) .FirstOrDefaultAsync(); if (user == null) { return(NotFound(new { message = "Usuário não encontrado" })); } var token = TokenService.GenerateToken(user); UserResultDTO dto = new UserResultDTO { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Role = user.Role }; return(new { user = dto, token = token }); }
/// <summary> /// 得到一条用户信息 /// </summary> /// <returns></returns> public UserResultDTO GetOneUser(int id) { UserResultDTO result = null; var tcdmse = SingleQueryObject.GetObj(); var pp = tcdmse.master_UserInfo.AsNoTracking().Where(p => p.UserID == id).FirstOrDefault(); if (pp == null) { throw new Exception("此条信息不存在!"); } result = Mapper.Map <master_UserInfo, UserResultDTO>(pp); return(result); }
/// <summary> /// 得到所有用户信息(含模糊查询) /// </summary> /// <returns></returns> public List <UserResultDTO> GetUser(UserSearchDTO dto) { List <UserResultDTO> result = null; var tcdmse = SingleQueryObject.GetObj(); var pp = tcdmse.master_UserInfo.AsNoTracking().Where(p => p.UserID > 0); if (dto != null) { #region 主数据 if (dto.QueryType == 1) // 取得模块部门所对应区域下的模块管理员 { var gg = tcdmse.master_AreaInfo.AsNoTracking().Where(g => g.DepartID == dto.DepartID && g.AreaPID == null).ToList(); List <UserResultDTO> arrlst = new List <UserResultDTO>(); foreach (var m in gg) { var person = m.master_UserInfo.ToList(); if (person.Count == 0) { continue; } foreach (var ps in person) { UserResultDTO urd = new UserResultDTO(); urd.CusAdminAreaNames = m.master_DepartmentInfo.DepartName + @"/" + m.AreaName; urd.AreaID = m.AreaID; urd.Email = ps.Email; urd.UserID = ps.UserID; arrlst.Add(urd); } } ; dto.Count = arrlst.Count(); return(arrlst);//Mapper.Map<List<master_UserInfo>, List<UserResultDTO>>(gg.ToList()); } #endregion #region 主数据 if (!string.IsNullOrEmpty(dto.DepartPath)) { var depid = tcdmse.master_DepartmentInfo.Where(p => p.DepartPath.Contains(dto.DepartPath)).Select(s => s.DepartID); pp = pp.Where(p => depid.Contains(p.DepartID.Value)); } //过滤条件,用户类型过滤 if (dto.UserTypeID != null) { pp = pp.Where(p => p.UserType == dto.UserTypeID); } if (!string.IsNullOrEmpty(dto.PhoneNumber)) { pp = pp.Where(p => p.PhoneNumber == dto.PhoneNumber); } if (dto.RoleIDlist != null && dto.RoleIDlist.Count() > 0) { pp = pp.Where(p => p.master_RoleInfo.Any(g => dto.RoleIDlist.Contains(g.RoleID))); } #endregion if (dto.EffectiveTtime != null) { pp = pp.Where(p => DbFunctions.TruncateTime(p.EffectiveTtime) == dto.EffectiveTtime); } //模糊查询,按用户编号、手机号、姓名、邮箱、经销商名称模糊搜索 #region 用户申请系统 if (dto.QueryType == 2) //已有用户 { pp = pp.Where(p => p.IsActive == true && (p.StopTime >= DateTime.Now || p.StopTime == null)); } if (dto.QueryType == 3)//停用用户 { pp = pp.Where(p => p.IsActive == false || (p.IsActive == true && p.StopTime < DateTime.Now)); } if (dto.UserType != null) { pp = pp.Where(p => p.UserType == dto.UserType); } if (dto.DistributorIDList != null && dto.DistributorIDList.Count > 0) { pp = pp.Where(p => p.master_DistributorInfo.Where(w => dto.DistributorIDList.Contains(w.DistributorID)).Count() > 0); } if (dto.UserID != null) { pp = pp.Where(p => p.UserID == dto.UserID); } #endregion if (!string.IsNullOrEmpty(dto.SearchText)) { pp = pp.Where(p => p.FullName.Contains(dto.SearchText) || p.Email.Contains(dto.SearchText) || p.PhoneNumber.Contains(dto.SearchText) || p.UserCode.Contains(dto.SearchText) || p.master_DistributorInfo.Where(w => w.DistributorName.Contains(dto.SearchText)).Count() > 0 ); } } dto.Count = pp.Count(); pp = pp.OrderByDescending(m => m.CreateTime).Skip((dto.page - 1) * dto.rows).Take(dto.rows); result = Mapper.Map <List <master_UserInfo>, List <UserResultDTO> >(pp.ToList()); return(result); }