public void CierreSubastaNoCompras() { Console.WriteLine("Cierre subasta sin compradores"); IDALSubasta sdal = new DALSubastaEF(); Producto p = new Producto { nombre = "test", UsuarioID = "*****@*****.**", fecha_cierre = DateTime.UtcNow.AddMinutes(1), CategoriaID = 5 }; sdal.AgregarProducto(p, "MobileCenter"); Console.WriteLine("Se espera que se le notifique al vendedor que no fue exitosa la venta."); }
public DataProducto(Producto p) { ProductoID = p.ProductoID; nombre = p.nombre; descripcion = p.descripcion; precio_base_subasta = p.precio_base_subasta; precio_compra = p.precio_compra; fecha_cierre = p.fecha_cierre.ToUniversalTime(); idOfertante = p.UsuarioID; }
public void CierreSubastaCompraDirecta() { Console.WriteLine("Cierre subasta con compra directa"); string tienda = "MobileCenter"; IDALSubasta sdal = new DALSubastaEF(); Producto p = new Producto { nombre = "test2", UsuarioID = "*****@*****.**", fecha_cierre = DateTime.UtcNow.AddMinutes(1), CategoriaID = 5 }; long prod = sdal.AgregarProducto(p, tienda); Compra compra = new Compra { monto = 200, ProductoID = prod, UsuarioID = "*****@*****.**", fecha_compra = DateTime.UtcNow }; sdal.AgregarCompra(compra, tienda); Console.WriteLine("Se espera el envio de un mail al vendedor como comprador."); }
public void CierreSubastaConOferta() { Console.WriteLine("Cierre subasta con una oferta"); string tienda = "MobileCenter"; IDALSubasta sdal = new DALSubastaEF(); Producto p = new Producto { nombre = "test1", UsuarioID = "*****@*****.**", fecha_cierre = DateTime.UtcNow.AddMinutes(1), CategoriaID = 5 }; long prod = sdal.AgregarProducto(p, tienda); Oferta o = new Oferta { monto = 500, ProductoID = prod, UsuarioID = "*****@*****.**" }; sdal.OfertarProducto(o, tienda); Console.WriteLine("Se ha creado un producto y ofertado::" + prod); Console.WriteLine("Se espera el envio de un mail al vendedor como comprador."); }
public JsonResult Create(DatosCrearProducto producto, List<Atributo> atributos) { try { String idTienda = Session["Tienda_Nombre"].ToString(); Debug.WriteLine("Lat, Long : " + producto.latitud + ", " + producto.longitud); Producto p = new Producto { nombre = producto.Titulo, UsuarioID = User.Identity.GetUserName(), descripcion = producto.Descripcion, precio_base_subasta = producto.PrecioBase, precio_compra = producto.PrecioComprarYa, fecha_cierre = producto.FechaCierre, CategoriaID = producto.CatID, longitud = producto.longitud, latitud = producto.latitud }; Debug.WriteLine("Lat, Long : " + p.latitud + ", " + p.longitud); long idProd = cS.AgregarProducto(p, idTienda); cS.AgregarAtributo(atributos, idProd, idTienda); var result = new { Success = "True", Message = idProd }; return Json(result, JsonRequestBehavior.AllowGet); } catch (Exception e) { var result = new { Success = "False", Message = "No se pudo crear el producto" }; return Json(result, JsonRequestBehavior.AllowGet); } }
public void ObtenerProductosMLporCategoria(string TiendaID, string limit, string categoryML, long categoryLocal) { Debug.Write("DALMERCADOLIBRE::OBTENERPRODUCTOSMLPORCATEGORIA"); IDALSubasta sdal = new DALSubastaEF(); string user_ml = "*****@*****.**"; //verifico si usuario existe using (var db = ChebayDBContext.CreateTenant(TiendaID)) { var query = from u in db.usuarios where u.UsuarioID == user_ml select u; if (query.Count() == 0) { CrearUsuarioML(TiendaID); } List<Producto> productos = new List<Producto>(); dynamic json = ripJson("/sites/MLU/search?limit=" + limit + "&category=" + categoryML); int total = 0; foreach (var p in json.results) { string nombre = (string)p.title; int price = (int)double.Parse((string)p.price); int subasta = price / 2; string latitud = (string)p.seller_address.latitude; string longitud = (string)p.seller_address.longitude; DateTime fecha_cierre = Convert.ToDateTime((string)p.stop_time); Producto producto = new Producto { fecha_cierre = fecha_cierre, latitud = latitud, longitud = longitud, nombre = nombre, precio_compra = price, precio_base_subasta =subasta, UsuarioID = user_ml, CategoriaID = categoryLocal, imagenes = new List<ImagenProducto>() }; long idprod = sdal.AgregarProducto(producto, TiendaID); //agrego producto Debug.WriteLine("Se agrego producto "+ nombre); var imagenes = ObtenerImagenesProducto(idprod, (string)p.id); foreach (var im in imagenes) { sdal.AgregarImagenProducto(im, TiendaID); } total++; Debug.WriteLine(producto.nombre+" " +producto.UsuarioID+" " +producto.latitud + " " +producto.longitud + " " +producto.precio_compra + " " +producto.CategoriaID ); } Debug.WriteLine("Total: " + total); } Debug.WriteLine("DALMERCADOLIBRE::TERMINO WEBSCRAPPING"); }
/** * Función para mandar un mail formato HTML al cliente o al vendedor de producto * * {titulo} Subasta ganada! ó Producto vendido! * {motivo} Has ganado una nueva subasta ó Has vendido un nuevo producto * {u} Usuario vendedor o comprador * {p} Producto vendido o comprado * {monto} Monto de la compra / venta * {calificacion} true si es para el usuario que compró el producto * {linkCalif} Si calificacion = true http://chebuynow.azurewebsites.net/{tiendaId}/Usuario/CalificarUsuario?prodId={prodId} * Si calificacion = false "" * {linkWeb} http://chebuynow.azurewebsites.net/tiendaId */ public string getBodyMailHTML(String titulo, String motivo, Usuario u, Producto p, int monto, bool calificacion, String linkCalif, String linkWeb) { String dest = ""; String fecha = DateTime.UtcNow.ToString(); if (u.Nombre != "" || u.Apellido != "") { dest = u.Nombre + " " + u.Apellido; } else { dest = u.UsuarioID; } String cuerpo = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + "<head>\n" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" + "<title>" + titulo +"</title>\n" + "</head>\n" + "\n" + "<body>\n" + "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n" + " <tr>\n" + " <td align=\"center\" valign=\"top\" bgcolor=\"#ffe77b\" style=\"background-color:#ffe77b;\"><br>\n" + " <br>\n" + " <table width=\"600\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n" + " <tr>\n" + " </tr>\n" + " <tr>\n" + " <td align=\"left\" valign=\"top\" bgcolor=\"#f89406\" style=\"background-color:#f89406; font-family:Arial, Helvetica, sans-serif; padding:10px;\"><div style=\"font-size:46px; color:#ff5500;\"><b>" + titulo + "</b></div>\n" + " <div style=\"font-size:13px; color:#000;\"><b>Estimado cliente " + dest + ", "+ motivo +"</b></div>\n" + " </td>\n" + " </tr>\n" + " <tr>\n" + " <td align=\"left\" valign=\"top\" bgcolor=\"#ffffff\" style=\"background-color:#ffffff;\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n" + " <tr>\n" + " <td align=\"center\" valign=\"middle\" style=\"padding:10px; color:#ff5500; font-size:42px; font-family:Georgia, 'Times New Roman', Times, serif;\">" + p.nombre + "</td>\n" + " </tr>\n" + " </table>\n" + " <table width=\"95%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\n" + " <tr>\n" + " <td align=\"left\" valign=\"middle\" style=\"color:#525252; font-family:Arial, Helvetica, sans-serif; padding:10px;\">\n" + " <div style=\"font-size:12px;\">" + p.descripcion + "</div>\n" + " </td>\n" + " </tr>\n" + " </table>\n" + " <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n" + " </table>\n" + " <table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" style=\"margin-bottom:15px;\">\n" + " <tr>\n" + " <td align=\"left\" valign=\"middle\" style=\"padding:15px; font-family:Arial, Helvetica, sans-serif;\">\n" + " <div align=\"right\" style=\"font-size:25px; color:#468847;\"> Comprado por </div> <div align=\"right\" style=\"font-size:36px; color:#468847;\">" + monto + " U$S! </div>\n" + " </td>\n" + " </tr>\n" + " </table>\n"; if (calificacion) { cuerpo += " <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin-bottom:10px;\">\n" + " <tr>\n" + " <td align=\"left\" valign=\"middle\" style=\"padding:15px; background-color:#f89406 ; font-family:Arial, Helvetica, sans-serif;\"><div style=\"font-size:20px; color:#ffe77b;\">Calificaciones</div>\n" + " <div style=\"font-size:13px; color:#000;\">Te invitamos a calificar la compra en nuestra página web. <br>\n" + " <br>\n" + " <a href=\"" + linkCalif + "\" style=\"color:#000; text-decoration:underline;\">CLICK AQUI</a> PARA CALIFICAR LA COMPRA </div></td>\n" + " </tr>\n" + " </table>\n"; }; cuerpo += " <table width=\"100%\" border=\"0\" style=\"background-color: burlywood;\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\n" + " <tr>\n" + " <td width=\"50%\" align=\"left\" valign=\"middle\" style=\"padding:10px;\"><table width=\"75%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n" + " <tr>\n" + " <td align=\"left\" valign=\"top\" style=\"font-family:Verdana, Geneva, sans-serif; font-size:14px; color:#000000;\"><b>Seguinos en</b></td>\n" + " </tr>\n" + " <tr>\n" + " <td align=\"left\" valign=\"top\" style=\"font-family:Verdana, Geneva, sans-serif; font-size:12px; color:#000000;\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n" + " <tr>\n" + " <td width=\"50%\" align=\"left\" valign=\"middle\" style=\"color:#564319; font-size:11px; font-family:Arial, Helvetica, sans-serif; padding:10px;\"><b>Facebook: </b> <a href=\"https://www.facebook.com\" style=\"color:#564319; text-decoration:none;\">Chebay FB</a><br>\n" + " <br>\n" + " </tr>\n" + " </table></td>\n" + " </tr>\n" + " </table></td>\n" + " <td width=\"50%\" align=\"left\" valign=\"middle\" style=\"color:#564319; font-size:11px; font-family:Arial, Helvetica, sans-serif; padding:10px;\"><b>Fecha:</b> " + fecha + "<br>\n" + " <b>Atencion al cliente: </b> <a href=\"mailto:[email protected]\" style=\"color:#564319; text-decoration:none;\">[email protected]</a><br>\n" + " <br>\n" + " <b>Pagina web: </b><br>\n" + "Chebay: <a href=\"" + linkWeb + "\" target=\"_blank\" style=\"color:#564319; text-decoration:none;\"> " + linkWeb + "</a></td>\n" + " </tr>\n" + " </table></td>\n" + " </tr>\n" + " </table>\n" + " <br>\n" + " <br></td>\n" + " </tr>\n" + "</table>\n" + "</body>\n" + "</html>"; return cuerpo; }
//--PRODUCTOS-- public long AgregarProducto(Producto p, string idTienda) { try { if (p == null) throw new Exception("Debe pasar un producto."); chequearTienda(idTienda); using (var context = ChebayDBContext.CreateTenant(idTienda)) { //Agrega el producto a la lista de publicados del usuario. var qUser = from usr in context.usuarios where usr.UsuarioID == p.UsuarioID select usr; if (qUser.Count() == 0) throw new Exception("No existe el usuario " + p.UsuarioID); Usuario u = qUser.FirstOrDefault(); if (u.publicados == null) u.publicados = new HashSet<Producto>(); u.publicados.Add(p); //Agregar el producto a la lista de productos de la Categoria. var qCat = from cat in context.categorias where cat.CategoriaID == p.CategoriaID select cat; if (qCat.Count() == 0) throw new Exception("No existe la categoria " + p.CategoriaID); CategoriaSimple cs = (CategoriaSimple)qCat.FirstOrDefault(); if (cs.productos == null) cs.productos = new HashSet<Producto>(); cs.productos.Add(p); context.productos.Add(p); context.SaveChanges(); //app.config... string QueueName = "subasta"; string connectionString = "Endpoint=sb://chebay.servicebus.windows.net/;SharedAccessKeyName=auth;SharedAccessKey=Jd/ztAsr+7snQ02QpUfn9bIvb9QvTjup+nox7GDw1dM="; //CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); //mandar a la queue fecha de cierre QueueClient Client = QueueClient.CreateFromConnectionString(connectionString, QueueName); //creo dataproductoqueue DataProductoQueue dpq = new DataProductoQueue { OwnerProducto=u.UsuarioID, nombre = p.nombre, fecha_cierre= p.fecha_cierre, ProductoID=p.ProductoID, TiendaID=idTienda }; var message = new BrokeredMessage(dpq) { ScheduledEnqueueTimeUtc = p.fecha_cierre }; Client.Send(message); System.Console.WriteLine(p.fecha_cierre.ToString()); return p.ProductoID; } } catch (Exception e) { Debug.WriteLine(e.Message); throw e; } }