// GET /TB_UNIVERSIDADE_VIDEOS/token/colecao/campo/orderBy/pageSize/pageNumber?CAMPO1=VALOR&CAMPO2=VALOR public Retorno Get(string token, int colecao = 0, int campo = 0, int orderBy = 0, int pageSize = 0, int pageNumber = 0) { // Abre nova conexão using (ServeLojaContext _db = new ServeLojaContext()) { try { Dictionary <string, string> queryString = Request.GetQueryNameValuePairs().ToDictionary(x => x.Key, x => x.Value); if (Permissoes.Autenticado(token, _db)) { return(GatewayTbUniversidadeVideos.Get(token, colecao, campo, orderBy, pageSize, pageNumber, queryString)); } else { return new Retorno() { Token = false } }; //return new Retorno() { Token = false }; //throw new Exception("Unauthorized"); } catch (Exception e) { throw new Exception(e.Message); } } }
/// <summary> /// Retorna true se o token informado é válido /// </summary> /// <param name="token"></param> /// <returns></returns> public static bool Autenticado(string token, ServeLojaContext _dbContext = null) { ServeLojaContext _db; if (_dbContext == null) { _db = new ServeLojaContext(); } else { _db = _dbContext; } //using (var transaction = _db.Database.BeginTransaction()) //{ try { //Boolean result = Permissoes.GetAdminPermissionFromToken(token); //if (!result) // return result; DateTime dt = DateTime.Now; var verify = _db.TB_UNIVERSIDADE_TOKEN_API .Where(v => v.UTA_TX_TOKEN.Equals(token) && v.UTA_DT_VALIDADE > dt ) .Select(v => v).ToList(); if (verify.Count != 0) { return(true); } return(false); } catch (Exception e) { if (e is DbEntityValidationException) { string erro = MensagemErro.getMensagemErro((DbEntityValidationException)e); throw new Exception(erro.Equals("") ? "Falha ao consultar pdvs" : erro); } throw new Exception(e.InnerException == null ? e.Message : e.InnerException.InnerException == null ? e.InnerException.Message : e.InnerException.InnerException.Message); //return false; } finally { if (_dbContext == null) { //transaction.Dispose(); _db.Database.Connection.Close(); _db.Dispose(); } } //} }