public async Task <HttpResponseMessage> Authenticate(HttpRequestMessage request)
        {
            return(await CreateHttpResponseAsync(request, async() =>
            {
                HttpResponseMessage response = null;
                string message = String.Empty;
                try
                {
                    if (UserLogged != null)
                    {
                        var op = _usuarioservice.GetUsuario(UserLogged.UserName, UserLogged.Password);
                        var accesos = _tipoUsuarioService.GetTipoUsuarioAccesos(op.ID_TipoUsuario);
                        User = Thread.CurrentPrincipal;
                        response = request.CreateResponse(HttpStatusCode.OK, new { usuario = op, accesos = accesos });
                    }
                    else
                    {
                        message = "Usuario o contraseña invalidas, Intente de nuevo.";
                        response = request.CreateResponse(HttpStatusCode.NotFound, new { Status = "ERROR", message = message, Sucess = false });
                    }
                }
                catch (Exception ex)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                      new
                    {
                        Status = "ERROR",
                        Message = ex.Message
                    });
                }

                return await Task.FromResult(response);
            }));
        }
Exemplo n.º 2
0
        public async Task <HttpResponseMessage> getTipoUsuario(HttpRequestMessage request, int id)
        {
            return(await CreateHttpResponseAsync(request, async() =>
            {
                HttpResponseMessage response = null;
                string message = String.Empty;
                try
                {
                    var usuario = _tipoUsuarioService.GetTipoUsuario(id);
                    var accesos = _tipoUsuarioService.GetTipoUsuarioAccesos(id);

                    response = request.CreateResponse(HttpStatusCode.OK, new { usuario, accesos });
                }
                catch (Exception ex)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                      new
                    {
                        error = "ERROR",
                        message = ex.Message
                    });
                }

                return await Task.FromResult(response);
            }));
        }