public void Update(UsuarioVM viewModel) { var model = UsuarioAdapter.ToModel(viewModel, true); this._usuarioRepository.Update(model); this._usuarioRepository.SaveChanges(); }
public static Usuario ToModel(UsuarioVM vm, bool deep) { var model = new Usuario(); model.ID = vm.ID; model.Username = vm.Username; model.Password = vm.Password; if (vm.UsuarioInfo != null && deep) { model.UsuarioInfo = UsuarioAdapter.ToModel(vm.UsuarioInfo, false); } return(model); }
public static UsuarioVM ToViewModel(Usuario model, bool deep) { var vm = new UsuarioVM(); vm.ID = model.ID; vm.Username = model.Username; vm.Password = model.Password; if (model.UsuarioInfo != null && deep) { vm.UsuarioInfo = UsuarioAdapter.ToViewModel(model.UsuarioInfo, false); } return(vm); }
public async Task <ObjectResult> Post([FromBody] UsuarioVM vm) { var user = UsuarioAdapter.ToModel(vm, true); ClaimsIdentity identity = await GetClaimsIdentity(user); if (identity == null) { _logger.LogInformation($"Invalid email ({user.Username}) or password ({user.Password})"); return(BadRequest("Invalid credentials")); } Claim[] claims = new Claim[5] { new Claim(JwtRegisteredClaimNames.Sub, user.Username), new Claim(JwtRegisteredClaimNames.Jti, await _jwtOptions.JtiGenerator()), new Claim(JwtRegisteredClaimNames.Iat, _jwtOptions.IssuedAt.ToUnixEpochDateToString(), ClaimValueTypes.Integer64), identity.FindFirst("Auth"), identity.FindFirst("usuario-info-id") }; JwtSecurityToken jwt = new JwtSecurityToken( issuer: _jwtOptions.Issuer, audience: _jwtOptions.Audience, claims: claims, notBefore: _jwtOptions.NotBefore, expires: _jwtOptions.Expiration, signingCredentials: _jwtOptions.SigningCredentials); var encodedJwt = new JwtSecurityTokenHandler() .WriteToken(jwt); var response = new AutenticacaoVM() { access_token = encodedJwt, created = _jwtOptions.IssuedAt, expires = _jwtOptions.Expiration, time_zone = TimeZoneInfo.Local.StandardName }; return(Ok(response)); }
public void Update([FromBody] UsuarioVM viewModel) { this.usuarioService.Update(viewModel); }
public void Add([FromBody] UsuarioVM viewModel) { this.usuarioService.Add(viewModel); }