/// <summary> /// /// </summary> /// <param name="Mercante"></param> /// <param name="Cliente"></param> /// <returns></returns> public static int UnFollowMercante(int Mercante, int Cliente) { try { using (MsSqlFacade<ClientesMercantes, ClientesMercantesMapper> facade = new MsSqlFacade<ClientesMercantes, ClientesMercantesMapper>()) { /// client facade read from the list ClientesMercantes entity = facade.Read().Single(p => p.Cliente == Cliente && p.Mercante == Mercante); /// we now check if the entity is null if (entity != null) { /// if is null we deleted form the merchant list of followers return facade.Delete(entity.ID); } else { /// we return a -1 if error return -1; } } } catch { /// in case that fails, we give an empty list return -1; } }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public static Promociones Get(int id) { using (MsSqlFacade<Promociones, PromocionesMapper> facade = new MsSqlFacade<Promociones, PromocionesMapper>()) { //// we use the Collection to build the broker entity on an abstract phase to manage it as a all return facade.Read().Single(p => p.ID == id); } }
/// <summary> /// /// </summary> /// <returns></returns> public static List<Promociones> Read() { using (MsSqlFacade<Promociones, PromocionesMapper> facade = new MsSqlFacade<Promociones, PromocionesMapper>()) { //// we use the Collection to build the broker entity on an abstract phase to manage it as a all return facade.Read(); } }
/// <summary> /// /// </summary> /// <param name="Mercante"></param> /// <returns></returns> public static List<data.entities.Categorias> ReadCategories() { try { using (MsSqlFacade<Categorias, CategoriasMapper> facade = new MsSqlFacade<Categorias, CategoriasMapper>()) { //// we use the Collection to build the broker entity on an abstract phase to manage it as a all return facade.Read(); } } catch { return null; } }
/// <summary> /// /// </summary> /// <param name="axis"></param> /// <param name="cliente"></param> public static string getCiudadPorID(int id) { try { using (MsSqlFacade<Ciudad, CiudadMapper> facade = new MsSqlFacade<Ciudad, CiudadMapper>()) { //// we use the Collection to build the broker entity on an abstract phase to manage it as a all return facade.Read().Single(p => p.ID == id).Nombre; } } catch { return null; } }
/// <summary> /// /// </summary> /// <param name="Mercante"></param> /// <param name="Cliente"></param> /// <returns></returns> public static int CheckFollower(int Mercante, int Cliente) { try { using (MsSqlFacade<ClientesMercantes, ClientesMercantesMapper> facade = new MsSqlFacade<ClientesMercantes, ClientesMercantesMapper>()) { // we now select all the promotions that are active but we make it into a linear research // thus is not woow efficient is enought for it's end. return facade.Read().Where(p=> p.Cliente == Cliente && p.Mercante == Mercante).Count(); } } catch { /// in case that fails, we give an empty list return -1; } }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <returns></returns> public static List<data.entities.CategoriasClientes> ReadClientCategories(int client) { try { using (MsSqlFacade<CategoriasClientes, CategoriasClientesMapper> facade = new MsSqlFacade<CategoriasClientes, CategoriasClientesMapper>()) { //// we use the Collection to build the broker entity on an abstract phase to manage it as a all return facade.Read().Where(p=>p.Cliente == client).ToList<CategoriasClientes>(); } } catch { return null; } }
/// <summary> /// /// </summary> /// <param name="Collection"></param> /// <returns></returns> public static string GetPositionsPorMercante(int id) { try { using (MsSqlFacade<Positions, PositionsMapper> facade = new MsSqlFacade<Positions, PositionsMapper>()) { // we now select all the promotions that are active but we make it into a linear research // thus is not woow efficient is enought for it's end. return facade.Read().Single(p => p.Mercante == id).Axis; } } catch { /// in case that fails, we give an empty list return null; } }
/// <summary> /// /// </summary> /// <returns></returns> public static List<data.entities.Membresias> ReadMembresias() { try { using (MsSqlFacade<Membresias, MembresiasMapper> facade = new MsSqlFacade<Membresias, MembresiasMapper>()) { // we now select all the promotions that are active but we make it into a linear research // thus is not woow efficient is enought for it's end. return facade.Read(); } } catch { /// in case that fails, we give an empty list return null; } }
/// <summary> /// /// </summary> /// <param name="Collection"></param> /// <returns></returns> public static List<data.entities.Promociones> ReadPromocionesPorCategorias(List<int> Collection, int Barrio) { try { using (MsSqlFacade<Promociones, PromocionesMapper> facade = new MsSqlFacade<Promociones, PromocionesMapper>()) { // we now select all the promotions that are active but we make it into a linear research // thus is not woow efficient is enought for it's end. return facade.Read().Where(p => Collection.Contains(p.Categoria) && p.Barrio == Barrio).ToList<Promociones>(); } } catch { /// in case that fails, we give an empty list return null; } }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public static List<Clientes> GetSeguidoresPorMercante(int id) { try { using (MsSqlFacade<ClientesMercantes, ClientesMercantesMapper> facade = new MsSqlFacade<ClientesMercantes, ClientesMercantesMapper>()) { /// client list to fill List<Clientes> clientes = new List<Clientes>(); /// first thing is to get the clients form the merchant so we lookup List<ClientesMercantes> list = facade.Read().Where(p => p.Mercante == id).ToList<ClientesMercantes>(); /// we now iterate to get the clients foreach (ClientesMercantes parent in list) { /// we release and use disposable using (MsSqlFacade<Clientes, ClientesMapper> facade1 = new MsSqlFacade<Clientes, ClientesMapper>()) { /// we now get the client form db Clientes cliente = facade1.Get(parent.Cliente); /// we now check for null if (cliente != null) { /// add to client clientes.Add(cliente); } } } /// we return the clients return clientes; } } catch { /// in case that fails, we give an empty list return null; } }
/// <summary> /// /// </summary> /// <param name="Mercante"></param> /// <returns></returns> public static List<data.entities.ClientesMercantes> ReadClientesMercantes(int Mercante) { try { using (MsSqlFacade<ClientesMercantes, ClientesMercantesMapper> facade = new MsSqlFacade<ClientesMercantes, ClientesMercantesMapper>()) { //// we select all the promotion that are active first return facade.Read().Where(p=>p.Mercante == Mercante).ToList<ClientesMercantes>(); } } catch { /// in case that fails, we give an empty list return null; } }
/// <summary> /// /// </summary> /// <param name="Mercante"></param> /// <returns></returns> public static List<data.entities.ItemProductos> ReadItemProductos(int Venta) { try { using (MsSqlFacade<ItemProductos, ItemProductosMapper> facade = new MsSqlFacade<ItemProductos, ItemProductosMapper>()) { //// we select all the promotion that are active first return facade.Read().Where(p=>p.Venta == Venta).ToList<ItemProductos>(); } } catch { /// in case that fails, we give an empty list return null; } }
/// <summary> /// /// </summary> /// <param name="Collection"></param> /// <returns></returns> public static List<data.entities.Promociones> ReadPromocionesPorCategorias(List<int> Collection) { try { using (MsSqlFacade<Promociones, PromocionesMapper> facade = new MsSqlFacade<Promociones, PromocionesMapper>()) { //// we select all the promotion that are active first return facade.Read().Where(p=> Collection.Contains(p.Categoria)).ToList<Promociones>(); } } catch { /// in case that fails, we give an empty list return null; } }
/// <summary> /// /// </summary> /// <returns></returns> public static List<data.entities.Productos> ReadProductos() { try { using (MsSqlFacade<Productos, ProductosMapper> facade = new MsSqlFacade<Productos, ProductosMapper>()) { //// we select all the promotion that are active first return facade.Read(); } } catch { /// in case that fails, we give an empty list return null; } }
/// <summary> /// /// </summary> /// <param name="Cliente"></param> /// <returns></returns> public static List<ComprasPromociones> getComprasPorCliente(int Cliente) { try { using (MsSqlFacade<ComprasPromociones, ComprasPromocionesMapper> facade = new MsSqlFacade<ComprasPromociones, ComprasPromocionesMapper>()) { return facade.Read().Where(p => p.Cliente == Cliente).ToList<ComprasPromociones>(); } } catch { /// in case that fails, we give an empty list return null; } }
/// <summary> /// /// </summary> /// <returns></returns> public static List<data.entities.Promociones> ReadPromociones(int estado) { try { using (MsSqlFacade<Promociones, PromocionesMapper> facade = new MsSqlFacade<Promociones, PromocionesMapper>()) { //// we select all the promotion that are active first return facade.Read().Where(p=>p.Estado == estado).ToList<Promociones>(); } } catch { /// in case that fails, we give an empty list return null; } }
/// <summary> /// /// </summary> /// <param name="Mercante"></param> /// <returns></returns> public static List<data.entities.Barrios> ReadBarriosPorCiudad(int Ciudad) { try { using (MsSqlFacade<Barrios, BarriosMapper> facade = new MsSqlFacade<Barrios, BarriosMapper>()) { //// we use the Collection to build the broker entity on an abstract phase to manage it as a all return facade.Read().Where(p => p.Ciudad == Ciudad).ToList<Barrios>(); } } catch { return null; } }
/// <summary> /// /// </summary> /// <param name="axis"></param> /// <returns></returns> public static List<data.entities.Promociones> ReadPromocionesPorGeolocation(string axis, double tolerance, int Barrio) { try { /// this is the list of merchants near my location List<int> MerchantCandidatesNear = new List<int>(); /// this is the full collection for the merchants positions List<Positions> PositionsCollection = new List<Positions>(); /// first we get the lat and lon in terms of (x,y) -> (lat, lon) string[] geo = axis.Split(','); /// latitude double lat1 = double.Parse(geo[0]); /// longitude double lon1 = double.Parse(geo[1]); /// Geo Location for the one we are looking for GeoCoordinate coord1 = new GeoCoordinate(lat1, lon1); /// we now prepare the object to be used GeoCoordinate coord2; /// facade call so it's O(n) = n^2 using (MsSqlFacade<Positions, PositionsMapper> facade = new MsSqlFacade<Positions, PositionsMapper>()) { /// this is the full collection for the merchants positions PositionsCollection = facade.Read(); } /// this is only valid if the number of monkey is higher than zero if (PositionsCollection.Count > 0) { /// now we iterate to search the candidates foreach (Positions parent in PositionsCollection) { /// we now get the axis comma separated string[] g = parent.Axis.Split(','); /// latitude double lat2 = double.Parse(g[0]); /// longitude double lon2 = double.Parse(g[1]); /// we now set the object coord2 = new GeoCoordinate(lat2, lon2); /// this gives me the distance of /// how long is the current actor's position to it destination /// this distance is measured in meters !! double distance = coord1.GetDistanceTo(coord2); /// if my candidate is near my location if (distance <= tolerance) { MerchantCandidatesNear.Add(parent.Mercante); } else { /// DO NOTHING :: } } if (MerchantCandidatesNear.Count >= 0) { /// another facade call O(n) = n^2 + 1 using (MsSqlFacade<Promociones, PromocionesMapper> facade = new MsSqlFacade<Promociones, PromocionesMapper>()) { /// this returns the promotions whre the merchant are near the tolerance given by the user return facade.Read().Where(p => MerchantCandidatesNear.Contains(p.Mercante) && p.Barrio == Barrio).ToList<Promociones>(); } } else { /// we only open the facade if the candidates are higher than zero, else /// we get out return null; } } else { /// no candidates near so you are so f****d !! /// Maybe should reduce tolerance return null; } } catch(Exception ex) { /// in case that fails, we give an empty list return new List<Promociones>() { new Promociones(){ Mercante = -1, Cuerpo = ex.ToString() }}; } }
/// <summary> /// /// </summary> /// <param name="axis"></param> /// <param name="cliente"></param> public static double getDistanceToPromociones(int mercante, string axis) { try { /// this is the full collection for the merchants positions List<Positions> PositionsCollection = new List<Positions>(); /// first we get the lat and lon in terms of (x,y) -> (lat, lon) string[] geo = axis.Split(','); string[] geo1 = null; /// latitude double lat1 = double.Parse(geo[0]); /// longitude double lon1 = double.Parse(geo[1]); /// Geo Location for the one we are looking for GeoCoordinate coord1 = new GeoCoordinate(lat1, lon1); /// facade call so it's O(n) = n^2 using (MsSqlFacade<Positions, PositionsMapper> facade = new MsSqlFacade<Positions, PositionsMapper>()) { /// this is the full collection for the merchants positions geo1 = facade.Read().Single(p=>p.Mercante == mercante).Axis.Split(','); } /// latitude double lat2 = double.Parse(geo1[0]); /// longitude double lon2 = double.Parse(geo1[1]); /// Geo Location for the one we are looking for GeoCoordinate coord2 = new GeoCoordinate(lat2, lon2); return coord1.GetDistanceTo(coord2);; } catch (Exception ex) { return -1; } }
/// <summary> /// /// </summary> /// <param name="Cliente"></param> /// <returns></returns> public static List<data.entities.CategoriasClientes> ReadCategoriasClientes(int Cliente) { try { using (MsSqlFacade<CategoriasClientes, CategoriasClientesMapper> facade = new MsSqlFacade<CategoriasClientes, CategoriasClientesMapper>()) { // we now select all the promotions that are active but we make it into a linear research // thus is not woow efficient is enought for it's end. return facade.Read().Where(p => p.Cliente == Cliente).ToList<CategoriasClientes>(); } } catch { /// in case that fails, we give an empty list return null; } }
/// <summary> /// /// </summary> /// <param name="Mercante"></param> /// <returns></returns> public static List<data.entities.Rutas> ReadRutas(int Cliente) { try { using (MsSqlFacade<Rutas, RutasMapper> facade = new MsSqlFacade<Rutas, RutasMapper>()) { //// we use the Collection to build the broker entity on an abstract phase to manage it as a all return facade.Read().Where(p=>p.Cliente == Cliente).ToList<Rutas>(); } } catch { return null; } }
/// <summary> /// /// </summary> /// <param name="Mercante"></param> /// <returns></returns> public static List<data.entities.Positions> ReadPositionsPorMercante(int Mercante) { try { using (MsSqlFacade<Positions, PositionsMapper> facade = new MsSqlFacade<Positions, PositionsMapper>()) { //// we use the Collection to build the broker entity on an abstract phase to manage it as a all return facade.Read().Where(p => p.Mercante == Mercante).ToList<Positions>(); } } catch { return null; } }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public static int GetNumeroSeguidoresPorMercante(int id) { try { using (MsSqlFacade<ClientesMercantes, ClientesMercantesMapper> facade = new MsSqlFacade<ClientesMercantes, ClientesMercantesMapper>()) { // we now select all the promotions that are active but we make it into a linear research // thus is not woow efficient is enought for it's end. return facade.Read().Where(p=>p.Mercante == id).Count(); } } catch { /// in case that fails, we give an empty list return 0; } }