public async Task <ActionResult <IEnumerable <AcUserInfoDto> > > GetUserInfoById(int id) { MessageModel <AcUserInfoDto> res = new MessageModel <AcUserInfoDto>(); if (!await _acUserInfoServices.ExistEntityAsync(a => a.Id == id)) { return(NotFound(StyleCode.NotFound(res))); } AcUserInfo entity = await _acUserInfoServices.GetEntityByIdAsync(id); res.Data = _mapper.Map <AcUserInfoDto>(entity); return(Ok(res)); }
public async Task <ActionResult <MessageModel <AcUserInfoDto> > > EditUserInfo(AcUserInfoEditDto userInfoEditDto) { MessageModel <AcUserInfoDto> res = new MessageModel <AcUserInfoDto>(); if (!await _acUserInfoServices.ExistEntityAsync(a => a.Id == userInfoEditDto.Id)) { return(NotFound(StyleCode.NotFound(res))); } AcUserInfo entity = _mapper.Map <AcUserInfo>(userInfoEditDto); await _acUserInfoServices.EditEntityAsync(entity); res.Data = _mapper.Map <AcUserInfoDto>(entity); return(Ok(res)); }
public async Task <ActionResult <ActionResult <MessageModel <string> > > > Login(LoginDto loginDto) { MessageModel <string> res = new MessageModel <string>(); JwtSecurityTokenHandler jwtHandler = new JwtSecurityTokenHandler(); AcUserInfo user = await _acUserInfoServices.GetEntitys(a => a.Pwd == loginDto.Pwd && a.Account == loginDto.Account).FirstOrDefaultAsync(); if (user == null) { return(NotFound(StyleCode.NotFound(res))); } string token = jwtHandler.WriteToken(new JwtSecurityToken (issuer: _configuration["Authentication:Issuer"], audience: _configuration["Authentication:Audience"], claims: new Claim[] { new Claim("id", user.Id.ToString()), }, expires: DateTime.Now.AddDays(7), signingCredentials: new SigningCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_configuration["Authentication:SigningKey"])), SecurityAlgorithms.HmacSha256) )); res.Data = "Bearer " + token; return(Ok(res)); }