public DataRecomendacion GetRecomendacionesUsuario(string TiendaID, DataRecomendacion dataRecomendacion) { var db = _client.GetDatabase(_database); var collection = db.GetCollection<BsonDocument>(TiendaID); var query = collection.Find(new BsonDocument("UsuarioID", dataRecomendacion.UsuarioID)); var count = query.CountAsync(); count.Wait(); if(count.Result == 0) return null; var prod= query.FirstAsync(); List<DataProducto> listDP = new List<DataProducto>(); string UsuarioID = prod.Result["UsuarioID"].AsString; BsonArray ar = prod.Result["productos"].AsBsonArray; string nombre = ""; long productoid = 0; string descripcion = ""; int precio_base_subasta = 0; int precio_compra = 0; DateTime fecha_cierre = DateTime.UtcNow; string idOfertante = ""; foreach (var a in ar) { if(!a["nombre"].IsBsonNull) nombre = a["nombre"].AsString; if(!a["ProductoID"].IsBsonNull) productoid = a["ProductoID"].AsInt64; if(!a["descripcion"].IsBsonNull) descripcion = a["descripcion"].AsString; if (!a["precio_base_subasta"].IsBsonNull) precio_base_subasta = a["precio_base_subasta"].AsInt32; if (!a["precio_compra"].IsBsonNull) precio_compra = a["precio_compra"].AsInt32; if (!a["fecha_cierre"].IsBsonNull) fecha_cierre = a["fecha_cierre"].ToUniversalTime(); if (!a["idOfertante"].IsBsonNull) idOfertante = a["idOfertante"].AsString; DataProducto dp = new DataProducto {descripcion=descripcion, fecha_cierre=fecha_cierre, idOfertante=idOfertante, nombre=nombre, precio_compra=precio_compra, precio_base_subasta=precio_base_subasta, ProductoID=productoid }; listDP.Add(dp); } return new DataRecomendacion { UsuarioID=UsuarioID, productos=listDP }; }
public List<DataProducto> ObtenerProductosVisitados(string idUsuario, string idTienda) { try { if (idUsuario == null) throw new Exception("Debe pasar el identificador de un usuario."); chequearTienda(idTienda); using (var context = ChebayDBContext.CreateTenant(idTienda)) { var query = from usr in context.usuarios.Include("visitas") where usr.UsuarioID == idUsuario select usr; if (query.Count() == 0) throw new Exception("No existe el usuario " + idUsuario); Usuario u = query.FirstOrDefault(); List<Producto> prods = u.visitas.ToList(); List<DataProducto> ret = new List<DataProducto>(); foreach (Producto p in prods) { //Para agregar solo los productos que no vencieron. if (p.fecha_cierre > DateTime.UtcNow) { DataProducto dp = new DataProducto { nombre = p.nombre, descripcion = p.descripcion, precio_actual = p.precio_base_subasta, precio_base_subasta = p.precio_base_subasta, precio_compra = p.precio_compra, ProductoID = p.ProductoID, fecha_cierre = p.fecha_cierre }; //Para agregar idOfertante y mayor oferta recibida Oferta of = ObtenerMayorOferta(p.ProductoID, idTienda); if (of != null) { dp.precio_actual = of.monto; dp.idOfertante = of.UsuarioID; } ret.Add(dp); } } return ret; } } catch (Exception e) { Debug.WriteLine(e.Message); throw e; } }
public List<DataProducto> ObtenerProductosPorTerminar(int cantProductos, string idTienda) { try { chequearTienda(idTienda); using (var context = ChebayDBContext.CreateTenant(idTienda)) { var qProd = from p in context.productos orderby p.fecha_cierre where p.fecha_cierre > DateTime.UtcNow select p; List<DataProducto> ret = new List<DataProducto>(); List<Producto> aux = qProd.ToList(); int cantActual = 0; foreach (Producto p in aux) { cantActual++; DataProducto dp = new DataProducto { nombre = p.nombre, descripcion = p.descripcion, precio_actual = p.precio_base_subasta, precio_base_subasta = p.precio_base_subasta, precio_compra = p.precio_compra, ProductoID = p.ProductoID, fecha_cierre = p.fecha_cierre }; Oferta of = ObtenerMayorOferta(p.ProductoID, idTienda); if (of != null) { dp.precio_actual = of.monto; dp.idOfertante = of.UsuarioID; } ret.Add(dp); if (cantActual == cantProductos) break; } return ret; } } catch (Exception e) { Debug.WriteLine(e.Message); throw e; } }
public List<DataProducto> ObtenerProductosPersonalizados(string idTienda) { try { chequearTienda(idTienda); using (var context = ChebayDBContext.CreateTenant(idTienda)) { var qProductos = from p in context.productos orderby p.fecha_cierre ascending select p; List<DataProducto> ret = new List<DataProducto>(); if (qProductos.Count() > 0) { foreach (Producto p in qProductos) { DataProducto dp = new DataProducto { descripcion = p.descripcion, fecha_cierre = p.fecha_cierre, nombre = p.nombre, precio_base_subasta = p.precio_base_subasta, precio_actual = p.precio_base_subasta, precio_compra = p.precio_compra, ProductoID = p.ProductoID, idOfertante = null }; Oferta of = ObtenerMayorOferta(p.ProductoID,idTienda); if (of != null) { dp.precio_actual = of.monto; dp.idOfertante = of.UsuarioID; } ret.Add(dp); } } return ret; } } catch (Exception e) { Debug.WriteLine(e.Message); throw e; } }
public List<DataProducto> ObtenerProductosCategoria(long idCategoria, string idTienda) { IDALTienda idalt = new DALTiendaEF(); List<DataProducto> listadp = new List<DataProducto>(); //obtengo todas las categorias simples de idCategoria using(var db = ChebayDBContext.CreateTenant(idTienda)) { //valido var query = from cat in db.categorias where cat.CategoriaID == idCategoria select cat; if(query.Count()==0){ throw new Exception("DALSubastaEF::ObtenerProductosCategoria: No existe categoria"); } //backtracking List<Categoria> stack = new List<Categoria>(); stack.Add(query.First()); while (stack.Count() != 0) { var first = stack.First(); System.Console.WriteLine(first.CategoriaID); if (first is CategoriaSimple) { CategoriaSimple cs = (CategoriaSimple)first; db.Entry(cs).Collection(c => c.productos).Load(); foreach (var p in cs.productos) { //Para agregar solo los productos que no vencieron. if (p.fecha_cierre > DateTime.UtcNow) { DataProducto dp = new DataProducto { nombre = p.nombre, descripcion = p.descripcion, precio_actual = p.precio_base_subasta, precio_base_subasta = p.precio_base_subasta, precio_compra = p.precio_compra, ProductoID = p.ProductoID, fecha_cierre = p.fecha_cierre }; //Para agregar idOfertante y mayor oferta recibida Oferta of = ObtenerMayorOferta(p.ProductoID, idTienda); if (of != null) { dp.precio_actual = of.monto; dp.idOfertante = of.UsuarioID; } listadp.Add(dp); } } } else { CategoriaCompuesta cc = (CategoriaCompuesta)first; db.Entry(cc).Collection(p => p.hijas).Load(); foreach (var c in cc.hijas) { stack.Add(c); } } //quito el primero stack.RemoveAt(0); } }//using return listadp; }
public List<DataProducto> ObtenerProductosBuscados(string searchTerm, string idTienda) { try { if (searchTerm == null) throw new Exception("Debe pasar el algo para buscar."); chequearTienda(idTienda); using (var context = ChebayDBContext.CreateTenant(idTienda)) { var qProductos = from prd in context.productos select prd; List<Producto> lp = qProductos.ToList(); List<DataProducto> ret = new List<DataProducto>(); foreach (Producto p in lp) { if (p.nombre.ToLower().Contains(searchTerm.ToLower()) || ( p.descripcion != null && p.descripcion.ToLower().Contains(searchTerm.ToLower()) ) || p.UsuarioID.ToLower().Contains(searchTerm.ToLower())) { DataProducto dp = new DataProducto { descripcion = p.descripcion, fecha_cierre = p.fecha_cierre, nombre = p.nombre, precio_base_subasta = p.precio_base_subasta, precio_actual = p.precio_base_subasta, precio_compra = p.precio_compra, ProductoID = p.ProductoID, idOfertante = null }; Oferta of = ObtenerMayorOferta(p.ProductoID, idTienda); if (of != null) { dp.precio_actual = of.monto; dp.idOfertante = of.UsuarioID; } ret.Add(dp); } } return ret; } } catch (Exception e) { Debug.WriteLine(e.Message); throw e; } }