/// <summary> /// Async Process /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public override System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> ExecuteAsync(System.Threading.CancellationToken cancellationToken) { using (Gale.Db.DataService svc = new Gale.Db.DataService("PA_MOT_OBT_Escritorio")) { svc.Parameters.Add("USUA_Token", _user); svc.Parameters.Add("Rango", this.Model.range); svc.Parameters.Add("Fecha_Inicio", this.Model.start); svc.Parameters.Add("Fecha_Fin", this.Model.end); Gale.Db.EntityRepository rep = this.ExecuteQuery(svc); Models.Counters counters = rep.GetModel <Models.Counters>().FirstOrDefault(); List <Models.GraphItem> items = rep.GetModel <Models.GraphItem>(1); //---------------------------------------------------------------------------------------------------- //Create Response var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new ObjectContent <Object>( new { timestamp = DateTime.Now.ToString("s"), counters = counters, graph = items }, System.Web.Http.GlobalConfiguration.Configuration.Formatters.JsonFormatter ) }; //Return Task return(Task.FromResult(response)); //---------------------------------------------------------------------------------------------------- } }
/// <summary> /// Async Process /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public override Task <HttpResponseMessage> ExecuteAsync(System.Threading.CancellationToken cancellationToken) { using (Gale.Db.DataService svc = new Gale.Db.DataService("PA_MAE_OBT_AutenticarUsuario")) { svc.Parameters.Add("USUA_NombreUsuario", Model.username); svc.Parameters.Add("USUA_Contrasena", Gale.Security.Cryptography.MD5.GenerateHash(Model.password)); Gale.Db.EntityRepository rep = this.ExecuteQuery(svc); Models.User user = rep.GetModel <Models.User>(0).FirstOrDefault(); Gale.Db.EntityTable <Models.Profile> profiles = rep.GetModel <Models.Profile>(1); //------------------------------------------------------------------------------------------------------------------------ //GUARD EXCEPTION Gale.Exception.RestException.Guard(() => user == null, "USERNAME_OR_PASSWORD_INCORRECT", Resources.Security.ResourceManager); //------------------------------------------------------------------------------------------------------------------------ List <System.Security.Claims.Claim> claims = new List <System.Security.Claims.Claim>(); claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Email, user.email)); claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.PrimarySid, user.token.ToString())); claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Name, user.fullname)); claims.Add(new System.Security.Claims.Claim("photo", user.photo.ToString())); profiles.ForEach((perfil) => { claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Role, perfil.identifier)); }); int expiration = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Gale:Security:TokenTmeout"]); //RETURN TOKEN return(Task.FromResult(_request.CreateResponse <Gale.Security.Oauth.Jwt.Wrapper>( Gale.Security.Oauth.Jwt.Manager.CreateToken(claims, DateTime.Now.AddMinutes(expiration)) ))); } }
/// <summary> /// Async Process /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public override System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> ExecuteAsync(System.Threading.CancellationToken cancellationToken) { using (Gale.Db.DataService svc = new Gale.Db.DataService("[PA_MOT_OBT_Ruta]")) { svc.Parameters.Add("USUA_Token", HttpContext.Current.User.PrimarySid()); svc.Parameters.Add("RUTA_Token", this.Model); Gale.Db.EntityRepository rep = this.ExecuteQuery(svc); Models.Route route = rep.GetModel <Models.Route>().FirstOrDefault(); Models.SocialRoute socialRoute = rep.GetModel <Models.SocialRoute>().FirstOrDefault(); List <Models.Coordinates> coords = rep.GetModel <Models.Coordinates>(1); List <Models.RoutePhoto> photos = rep.GetModel <Models.RoutePhoto>(2); //---------------------------------------------------------------------------------------------------- //Create Response var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new ObjectContent <Object>( new { details = route, coordinates = coords, social = socialRoute, photos = photos }, System.Web.Http.GlobalConfiguration.Configuration.Formatters.KqlFormatter() ) }; //Return Task return(Task.FromResult(response)); //---------------------------------------------------------------------------------------------------- } }
/// <summary> /// Async Process /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public override System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> ExecuteAsync(System.Threading.CancellationToken cancellationToken) { //Check the Debug Access Token (Future Implementation) //http://stackoverflow.com/questions/8605703/how-to-verify-facebook-access-token //--------------------------------------------- //Get Stream Image from the User byte[] imageBytes = null; if (Model.image != null) { try { //Try to download the image var webClient = new WebClient(); imageBytes = webClient.DownloadData(Model.image); } catch { } } using (Gale.Db.DataService svc = new Gale.Db.DataService("PA_MOT_OBT_AutenticarUsuarioExterno")) { svc.Parameters.Add("USUA_NombreCompleto", Model.name); svc.Parameters.Add("USUA_Email", Model.email); svc.Parameters.Add("AEXT_Identificador", Model.id); svc.Parameters.Add("ARCH_Binario", imageBytes); svc.Parameters.Add("ARCH_Tamano", imageBytes.Length); svc.Parameters.Add("TIAU_Identificador", "gmail"); //Facebook Gale.Db.EntityRepository rep = this.ExecuteQuery(svc); Models.User user = rep.GetModel <Models.User>(0).FirstOrDefault(); Gale.Db.EntityTable <Models.Profile> profiles = rep.GetModel <Models.Profile>(1); //------------------------------------------------------------------------------------------------------------------------ //GUARD EXCEPTION Gale.Exception.RestException.Guard(() => user == null, "USERNAME_OR_PASSWORD_INCORRECT", Resources.Security.ResourceManager); //------------------------------------------------------------------------------------------------------------------------ List <System.Security.Claims.Claim> claims = new List <System.Security.Claims.Claim>(); claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Email, user.email)); claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.PrimarySid, user.token.ToString())); claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Name, user.fullname)); claims.Add(new System.Security.Claims.Claim("photo", user.photo.ToString())); profiles.ForEach((perfil) => { claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Role, perfil.identifier)); }); int expiration = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Gale:Security:TokenTmeout"]); //RETURN TOKEN return(Task.FromResult(_request.CreateResponse <Gale.Security.Oauth.Jwt.Wrapper>( Gale.Security.Oauth.Jwt.Manager.CreateToken(claims, DateTime.Now.AddMinutes(expiration)) ))); } }
/// <summary> /// Async Process /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public override System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> ExecuteAsync(System.Threading.CancellationToken cancellationToken) { using (Gale.Db.DataService svc = new Gale.Db.DataService("[PA_MOT_OBT_MisRutas]")) { svc.Parameters.Add("USUA_Token", this.Model); svc.Parameters.Add("MarcaTiempo", _timestamp); Gale.Db.EntityRepository rep = this.ExecuteQuery(svc); List <Models.Route> items = rep.GetModel <Models.Route>(); DateTime stamp = items.Count > 0 ? items.Max((a) => a.createdAt) : _timestamp; //---------------------------------------------------------------------------------------------------- //Create Response var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new ObjectContent <Object>( new { timestamp = stamp, total = items.Count, items = items }, System.Web.Http.GlobalConfiguration.Configuration.Formatters.KqlFormatter() //-> CAMEL_CASING RETRIEVE DIFERENT OBJECT =) ) }; //Return Task return(Task.FromResult(response)); //---------------------------------------------------------------------------------------------------- } }
/// <summary> /// Obtiene la foto del usuario /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public override Task <HttpResponseMessage> ExecuteAsync(System.Threading.CancellationToken cancellationToken) { //------------------------------------------------------------------------------------------------------ // DB Execution using (Gale.Db.DataService svc = new Gale.Db.DataService("PA_MAE_OBT_ArchivoBinario")) { svc.Parameters.Add("ARCH_Token", _token); Gale.Db.EntityRepository rep = this.ExecuteQuery(svc); Models.FileData file = rep.GetModel <Models.FileData>().FirstOrDefault(); if (file == null) { return(Task.FromResult(new HttpResponseMessage(System.Net.HttpStatusCode.NotFound))); } //Create Response var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new StreamContent(new System.IO.MemoryStream(file.binary.ToArray())), }; response.Headers.CacheControl = new System.Net.Http.Headers.CacheControlHeaderValue() { MaxAge = TimeSpan.FromMinutes(30) }; //Add Content-Type Header response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(file.contentType); return(Task.FromResult(response)); } //------------------------------------------------------------------------------------------------------ }
/// <summary> /// Async Process /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public override System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> ExecuteAsync(System.Threading.CancellationToken cancellationToken) { //------------------------------------------------------------------------------------------------------ // GUARD EXCEPTIONS Gale.Exception.RestException.Guard(() => _latitude == null, "LATITUDE_EMPTY", API.Errors.ResourceManager); Gale.Exception.RestException.Guard(() => _longitude == null, "LONGITUDE_EMPTY", API.Errors.ResourceManager); Gale.Exception.RestException.Guard(() => _distance == null, "DISTANCE_EMPTY", API.Errors.ResourceManager); //------------------------------------------------------------------------------------------------------ using (Gale.Db.DataService svc = new Gale.Db.DataService("[PA_MOT_OBT_DescubrirRutas]")) { svc.Parameters.Add("USUA_Token", HttpContext.Current.User.PrimarySid()); svc.Parameters.Add("Nombre", _route); svc.Parameters.Add("Distancia", _distance); svc.Parameters.Add("Latitud", _latitude); svc.Parameters.Add("Longitud", _longitude); svc.Parameters.Add("RegistrosPorPagina", _limit); svc.Parameters.Add("RegistrosSaltados", _offset); Gale.Db.EntityRepository rep = this.ExecuteQuery(svc); Models.Pagination pagination = rep.GetModel <Models.Pagination>(0).FirstOrDefault(); List <Models.DiscoveredRoute> routes = rep.GetModel <Models.DiscoveredRoute>(1); //---------------------------------------------------------------------------------------------------- //Create Response var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new ObjectContent <Object>( new { offset = _offset, limit = _limit, total = pagination.total, items = routes }, System.Web.Http.GlobalConfiguration.Configuration.Formatters.KqlFormatter() ) }; //Return Task return(Task.FromResult(response)); //---------------------------------------------------------------------------------------------------- } }
/// text public static Models.Config GetConfiguration(String NameConfiguration, Gale.Db.IDataActions dataActions) { using (Gale.Db.DataService svc = new Gale.Db.DataService("PA_MAE_SEL_Configuracion")) { svc.Parameters.Add("@CONF_Nombre", NameConfiguration); Gale.Db.EntityRepository rep = dataActions.ExecuteQuery(svc); Models.Config result = rep.GetModel <Models.Config>().FirstOrDefault(); return(result); } }
/// <summary> /// Async Process /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public override System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> ExecuteAsync(System.Threading.CancellationToken cancellationToken) { using (Gale.Db.DataService svc = new Gale.Db.DataService("PA_MOT_OBT_Perfl")) { svc.Parameters.Add("USUA_Token", this.Model); Gale.Db.EntityRepository rep = this.ExecuteQuery(svc); Models.Account account = rep.GetModel <Models.Account>().FirstOrDefault(); List <Models.Role> roles = rep.GetModel <Models.Role>(1); Models.SocialProfile counter = rep.GetModel <Models.SocialProfile>(2).FirstOrDefault(); Models.PersonalData personal = rep.GetModel <Models.PersonalData>(3).FirstOrDefault(); Models.Sport sport = rep.GetModel <Models.Sport>(3).FirstOrDefault(); List <Models.EmergencyPhones> phones = rep.GetModel <Models.EmergencyPhones>(4); List <Models.Medal> medals = rep.GetModel <Models.Medal>(5); //---------------------------------------------------------------------------------------------------- //Guard Exception's Gale.Exception.RestException.Guard(() => account == null, "ACCOUNT_DONT_EXISTS", API.Errors.ResourceManager); //---------------------------------------------------------------------------------------------------- account.photo = (account.photo == System.Guid.Empty ? null : account.photo); if (personal != null) { personal.emergencyPhones = (from t in phones select t.phone).ToList(); } //---------------------------------------------------------------------------------------------------- //Create Response var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new ObjectContent <Object>( new { account = account, roles = roles, sport = sport, personal = personal, social = counter, medals = medals }, System.Web.Http.GlobalConfiguration.Configuration.Formatters.KqlFormatter() ) }; //Return Task return(Task.FromResult(response)); //---------------------------------------------------------------------------------------------------- } }
/// text public static Models.Config GetConfiguration(Nullable <Guid> token, Gale.Db.IDataActions dataActions) { using (Gale.Db.DataService svc = new Gale.Db.DataService("PA_MAE_SEL_Configuracion")) { if (token != null) { svc.Parameters.Add("@DOCU_Token", token); } svc.Parameters.Add("@CONF_Nombre", DBNull.Value); Gale.Db.EntityRepository rep = dataActions.ExecuteQuery(svc); Models.Config result = rep.GetModel <Models.Config>().FirstOrDefault(); return(result); } }