예제 #1
0
        public UsuarioVM Detail(string id)
        {
            var usuario = UsuarioAdapter.ToViewModel(this._usuarioRepository.Get(id), true);

            usuario.UsuarioInfo = this.DetailUsuarioInfo(id);
            return(usuario);
        }
예제 #2
0
        public void Update(UsuarioVM viewModel)
        {
            var model = UsuarioAdapter.ToModel(viewModel, true);

            this._usuarioRepository.Update(model);

            this._usuarioRepository.SaveChanges();
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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));
        }
예제 #6
0
 public List <UsuarioInfoVM> GetAllByTermo(string perfil, string termo)
 {
     return(this._usuarioRepository.GetAllByTermo(perfil, termo).Select(x => UsuarioAdapter.ToViewModel(x, true)).ToList());
 }
예제 #7
0
 public List <UsuarioVM> All()
 {
     return(this._usuarioRepository.GetAll(true).Select(x => UsuarioAdapter.ToViewModel(x, true)).ToList());
 }
예제 #8
0
        public UsuarioInfoVM DetailUsuarioInfo(string id)
        {
            var usuarioInfo = this._usuarioRepository.GetUsuarioInfo(id);

            return(UsuarioAdapter.ToViewModel(usuarioInfo, true));
        }