public async Task <ActionResult> pvwAddUserClaim([FromBody] UserClaimDTO _sarpara) { UserClaimDTO _UserClaim = new UserClaimDTO(); try { string baseadress = config.Value.urlbase; HttpClient _client = new HttpClient(); _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token")); var result = await _client.GetAsync(baseadress + "api/UserClaims/GetAspNetUserClaimsById/" + _sarpara.Id); string valorrespuesta = ""; if (result.IsSuccessStatusCode) { valorrespuesta = await(result.Content.ReadAsStringAsync()); _UserClaim = JsonConvert.DeserializeObject <UserClaimDTO>(valorrespuesta); } if (_UserClaim == null) { _UserClaim = new UserClaimDTO(); } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; } return(PartialView(_UserClaim)); }
public IActionResult Create(UserClaimDTO model) { var result = apiRequestService.RequestPost <string>("api/v1/UserClaims/CreateUserClaim", model).Result; if (result is not null && result.IsSuccess) { return(RedirectToAction("Index", new { userName = model.UserName })); } return(View(model)); }
public async Task <ActionResult <ApplicationUserClaim> > SaveUserClaim([FromBody] UserClaimDTO _UserClaimS) { ApplicationUserClaim _UserClaim = _UserClaimS; try { // UserClaimDTO _li_UserClaim = new UserClaimDTO(); string baseadress = config.Value.urlbase; HttpClient _client = new HttpClient(); _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token")); var result = await _client.GetAsync(baseadress + "api/UserClaims/GetAspNetUserClaimsById/" + _UserClaim.Id); string valorrespuesta = ""; if (result.IsSuccessStatusCode) { valorrespuesta = await(result.Content.ReadAsStringAsync()); _UserClaim = JsonConvert.DeserializeObject <UserClaimDTO>(valorrespuesta); } if (_UserClaim == null) { _UserClaim = new Models.ApplicationUserClaim(); } if (_UserClaim.Id == 0) { var insertresult = await Insert(_UserClaimS); } else { var updateresult = await Update(_UserClaim.Id, _UserClaimS); } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; } return(Json(_UserClaim)); }
private static void AutoMapperIdentity123() { Console.WriteLine("\nApplication Identity DTO -> Data -> DTO\n"); { Console.WriteLine("Role"); Role data = new Role(); RoleDTO dto = DIHelper.Mapper.Map <RoleDTO>(data); data = DIHelper.Mapper.Map <Role>(dto); } { Console.WriteLine("UserClaim"); UserClaim data = new UserClaim(); UserClaimDTO dto = DIHelper.Mapper.Map <UserClaimDTO>(data); data = DIHelper.Mapper.Map <UserClaim>(dto); } { Console.WriteLine("UserLogim"); UserLogin data = new UserLogin(); UserLoginDTO dto = DIHelper.Mapper.Map <UserLoginDTO>(data); data = DIHelper.Mapper.Map <UserLogin>(dto); } { Console.WriteLine("UserRole"); UserRole data = new UserRole(); UserRoleDTO dto = DIHelper.Mapper.Map <UserRoleDTO>(data); data = DIHelper.Mapper.Map <UserRole>(dto); } { Console.WriteLine("User"); User data = new User(); UserDTO dto = DIHelper.Mapper.Map <UserDTO>(data); data = DIHelper.Mapper.Map <User>(dto); } }
public async Task <IActionResult> Login(UserSignDTO userSignDTO) { if (ModelState.IsValid) { JObject datasJson = await _userServices.Login(userSignDTO); if (datasJson["error"] is null) { AuthorizationDTO authorization = JsonHelper.Deserialize <AuthorizationDTO>(datasJson.ToString()); UserClaimDTO userClaim = await _authenticationService.AcquireUserClaim(_serverAddresses.Addresses.FirstOrDefault(), authorization.access_token); if (authorization is null || userClaim is null) { return(StatusCode(500)); } var loginStatus = _mapper.Map <LoginStatusDTO>(userSignDTO); _mapper.Map(userClaim, loginStatus); _mapper.Map <AuthorizationDTO, LoginStatusDTO>(authorization, loginStatus); return(Ok(new ResponseCtrMsg <LoginStatusDTO>(CtrResult.Success) { ResultObj = loginStatus })); } else { this._logger.LogInformation("User:"******",Login Control failed"); return(BadRequest("账号密码错误")); } } else { this._logger.LogInformation("The passed in model is empty"); return(BadRequest(new ResponseCtrMsg <object>(CtrResult.Failure) { message = "传入的模型为空" })); } }