public UsuarioVM Detail(string id) { var usuario = UsuarioAdapter.ToViewModel(this._usuarioRepository.Get(id), true); usuario.UsuarioInfo = this.DetailUsuarioInfo(id); return(usuario); }
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 List <UsuarioInfoVM> GetAllByTermo(string perfil, string termo) { return(this._usuarioRepository.GetAllByTermo(perfil, termo).Select(x => UsuarioAdapter.ToViewModel(x, true)).ToList()); }
public List <UsuarioVM> All() { return(this._usuarioRepository.GetAll(true).Select(x => UsuarioAdapter.ToViewModel(x, true)).ToList()); }
public UsuarioInfoVM DetailUsuarioInfo(string id) { var usuarioInfo = this._usuarioRepository.GetUsuarioInfo(id); return(UsuarioAdapter.ToViewModel(usuarioInfo, true)); }