public UserMobileModel GetUserByIdVersionMobile(int userId) { var userModelVersionMobile = new UserMobileModel(_userUseCase.GetUserById(userId, true)); //GetUserById var userModelVersionMobile = new UserMobileModel(_userUseCase.GetUsersById(userId)); return(userModelVersionMobile); }
public HttpResponseMessage UserMobile(UserMobileModel value) { var RegionId = userSvc.CreateMobile(value); JavaScriptSerializer js = new JavaScriptSerializer(); return(Request.CreateResponse(HttpStatusCode.OK, js.Serialize(RegionId))); }
/// <summary> /// Agrega el usuario mobile a una región, y retorna la región a la que pertenece. /// </summary> /// <param name="value">Objeto que contiene PlayerId de OneSignal y dirección del usuario</param> /// <returns>Id de la region a la que pertenece el usuario</returns> public List <int> CreateMobile(UserMobileModel value) { double latitude = 0, longitude = 0; List <int> listRegionsId = GetRegionId(value, ref latitude, ref longitude); if (listRegionsId.Count > 0) { var user = LoadByPlayerId(value.PlayerID); if (user == null) { user = Save(new User() { Address = value.Address, Lat = latitude, Lon = longitude, RoleId = (int)UserRoleEnum.UserMobile, MobileID = value.PlayerID, Active = true }); } else { user.Address = value.Address; user.MobileID = value.PlayerID; user.LastUpdate = DateTime.UtcNow; UpdateEntity(user); } IoC.Resolve <UserByUserGroupSvc>().DeleteByUser(user.ID); foreach (var regionId in listRegionsId) { IoC.Resolve <UserByUserGroupSvc>().Save(new UsersByUserGroup() { UserID = user.ID, UserGroupID = regionId, LastUpdate = DateTime.UtcNow, CreatedDate = DateTime.UtcNow, Deleted = false, Active = true }); } } return(listRegionsId); }
private static List <int> GetRegionId(UserMobileModel value, ref double latitude, ref double longitude) { List <int> listRegiones = new List <int>(); try { string URL = Settings.GoogleMapsAPIURL; string urlParameters = $"?address={value.Address}, Suncheles, Santa Fe, Argentina&sensor=false&key={Settings.GoogleMapsAPIKey}"; HttpClient client = new HttpClient { BaseAddress = new Uri(URL) }; // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); // List data response. HttpResponseMessage response = client.GetAsync(urlParameters).Result; // Blocking call! Program will wait here until a response is received or a timeout occurs. if (response.IsSuccessStatusCode) { XmlSerializer serializer = new XmlSerializer(typeof(GeocodeResponse)); GeocodeResponse resultingMessage = (GeocodeResponse)serializer.Deserialize(new XmlTextReader(response.Content.ReadAsStreamAsync().Result)); if (Settings.IsDev) { latitude = double.Parse(resultingMessage.Result.Geometry.Location.Lat.Replace('.', ',')); longitude = double.Parse(resultingMessage.Result.Geometry.Location.Lng.Replace('.', ',')); } else { latitude = double.Parse(resultingMessage.Result.Geometry.Location.Lat); longitude = double.Parse(resultingMessage.Result.Geometry.Location.Lng); } if (latitude == Settings.ExcludeLatitude && longitude == Settings.ExcludeLongitude) { listRegiones.Clear(); listRegiones.Add(0); return(listRegiones); } //Consulta a la API de AVL la región a la que pertenecen las coordenadas AvlSoapClient avlClient = new AvlSoapClient(); var avlResponse = avlClient.ObtenerRegionesActualesPorCoordenada(6, latitude, longitude); if (avlResponse.Rows.Count > 0) { foreach (DataRow item in avlResponse.Rows) { if (int.TryParse(item.ItemArray[0].ToString(), out int regionId)) { if (item.ItemArray[1].ToString().ToUpper().Contains("RECOLECCI")) { regionId = regionId * 10000; } } listRegiones.Add(regionId); } } } else { listRegiones.Clear(); listRegiones.Add(0); return(listRegiones); } client.Dispose(); } catch (Exception ex) { listRegiones.Clear(); listRegiones.Add(0); return(listRegiones); } return(listRegiones); }