public DataResult <UsuarioDTO> Login([FromBody] UsuarioDTO request)
        {
            DataResult <UsuarioDTO> response = null;
            UsuarioDTO usuario;

            try
            {
                usuario = repository.Login(request);

                ClaimsIdentity identity = new ClaimsIdentity(
                    authenticationType: DefaultAuthenticationTypes.ApplicationCookie,
                    nameType: ClaimsIdentity.DefaultNameClaimType,
                    roleType: ClaimsIdentity.DefaultRoleClaimType);

                identity.AddClaim(new Claim(ClaimTypes.Email, request.Email, ClaimValueTypes.Email));

                Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                Authentication.SignIn(identity);

                response = DataResultHelper.Done(usuario);
            }
            catch (Exception exception)
            {
                return(DataResultHelper.Fail <UsuarioDTO>(exception));
            }

            return(response);
        }
Esempio n. 2
0
        public IHttpActionResult ConsultarHistorico()
        {
            List <HistoricoKilometrajeDTO> listaHistoricos = null;

            DataResult <List <HistoricoKilometrajeDTO> > result = null;

            try
            {
                repository      = new HistoricoKilometrajeRepository();
                listaHistoricos = repository.GetAll();
                result          = DataResultHelper.Done(listaHistoricos);
            }
            catch (Exception ex)
            {
                result = DataResultHelper.Fail <List <HistoricoKilometrajeDTO> >(ex);
            }

            return(Ok(result));
        }
Esempio n. 3
0
        public IHttpActionResult SubirArchivoInterface([FromBody] UploadedFileDTO file)
        {
            List <HistoricoKilometrajeDTO> listaResultado         = new List <HistoricoKilometrajeDTO>();
            DataResult <List <HistoricoKilometrajeDTO> > response = null;

            ClaimsIdentity claimsIdentity = User.Identity as ClaimsIdentity;
            Claim          claim          = claimsIdentity.FindFirst(ClaimTypes.Email);

            string emailUsuario = claim == null ? "" : claim.Value;

            try
            {
                listaResultado = repository.ImportarDatosInterface(file, emailUsuario);
                response       = DataResultHelper.Done(listaResultado);
            }
            catch (Exception exception)
            {
                response = DataResultHelper.Fail <List <HistoricoKilometrajeDTO> >(exception);
            }

            return(Ok(response));
        }