public JsonResult actualizarDatosUsuario(DatosUsuario du) { try { Usuario u = new Usuario { UsuarioID = du.UsuarioID, Nombre = du.Nombre, Apellido = du.Apellido, Pais = du.Pais, Ciudad = du.Ciudad, Direccion = du.Direccion, NumeroContacto = du.NumeroContacto, Email = du.Email }; uC.ActualizarUsuario(u, Session["Tienda_Nombre"].ToString()); var result = new { Success = "True", Message = "Usuario actualizado" }; return Json(result, JsonRequestBehavior.AllowGet); } catch (Exception e) { var result = new { Success = "False", Message = e.Message }; return Json(result, JsonRequestBehavior.AllowGet); } }
public void ActualizarUsuario(Usuario u, string idTienda) { try { chequearTienda(idTienda); using (var context = ChebayDBContext.CreateTenant(idTienda)) { var query = from usr in context.usuarios where usr.UsuarioID == u .UsuarioID select usr; Usuario user = query.FirstOrDefault(); user.Apellido = u.Apellido; user.Nombre = u.Nombre; user.Ciudad = u.Ciudad; user.Pais = u.Pais; user.Direccion = u.Direccion; user.NumeroContacto = u.NumeroContacto; user.CodigoPostal = u.CodigoPostal; user.Email = u.Email; context.SaveChanges(); } } catch (Exception e) { Debug.WriteLine(e.Message); throw e; } }
private List<DataProducto> getByFavoriteCategory(List<Producto> products, Usuario user) { List<DataProducto> ret = new List<DataProducto>(); var query = (from p in user.favoritos group p by p.CategoriaID into grupo select new { catid = grupo.FirstOrDefault().CategoriaID, count = grupo.Count() }) .OrderByDescending(x => x.count); foreach (var i in query) { System.Console.WriteLine(i.catid+" "+ i.count); } if (query.Count() == 0) { //si no tiene favoritos retorna primeros 3 productos categoria samsung var q = (from p in products where p.CategoriaID==2 select p).Take(3); foreach (var p in q) { ret.Add(new DataProducto(p)); } return ret; } var mostfav = (long)query.FirstOrDefault().catid; foreach (var p in products) { if (p.CategoriaID == mostfav) ret.Add(new DataProducto(p)); } return ret; }
public void custom_algorithm(Personalizacion personalizacion, List<Producto> products, Usuario user, string tiendaID) { Assembly ddl = Assembly.Load(personalizacion.algoritmo); var t = ddl.GetType("Chebay.AlgorithmDLL.ChebayAlgorithm"); dynamic c = Activator.CreateInstance(t); DataRecomendacion dr = new DataRecomendacion { UsuarioID = user.UsuarioID }; Thread timeThread = new Thread(() => { try { dr.productos = (List<DataProducto>)c.getProducts(products, user); IDALUsuario udal = new DALUsuarioEF(); udal.AgregarRecomendacionesUsuario(tiendaID, dr); } catch (Exception e) { //si falla entonces default default_recomendation_algorithm(products, user, tiendaID); } }); timeThread.Start(); bool finished = timeThread.Join(5000); if (!finished) { Debug.WriteLine("ALGORITMO PERSONALIZADO SUSPENDIDO... EXCESO TIEMPO"); timeThread.Abort(); default_recomendation_algorithm(products,user,tiendaID); } }
//only read! //toma los 5 productos mas costosos de la tienda private List<DataProducto> getByCost(List<Producto> products, Usuario user) { List<DataProducto> ret = new List<DataProducto>(); var query = (from p in products orderby p.precio_compra descending select p).Take(5); foreach (var i in query) { ret.Add(new DataProducto(i)); } return ret; }
//default algorithm return the mosts visited product public void default_recomendation_algorithm(List<Producto> products, Usuario user, String tiendaID) { IDALUsuario udal = new DALUsuarioEF(); var query = from p in products orderby (p.visitas.Count) descending select p; DataRecomendacion dr = new DataRecomendacion { UsuarioID = user.UsuarioID, productos = new List<DataProducto>() }; foreach (var p in query.ToList()) { dr.productos.Add(new DataProducto(p)); } udal.AgregarRecomendacionesUsuario(tiendaID, dr); }
//--USUARIOS-- public void AgregarUsuario(Usuario u, string idTienda) { try { chequearTienda(idTienda); using (var context = ChebayDBContext.CreateTenant(idTienda)) { u.fecha_ingreso = DateTime.Today; u.promedio_calificacion = 0; context.usuarios.Add(u); context.SaveChanges(); } } catch (Exception e) { Debug.WriteLine(e.Message); throw e; } }
private void CrearUsuarioML(string TiendaID) { string usermail = "*****@*****.**"; Usuario u = new Usuario { Nombre="MercadoLibreWebscraping", Pais="Uruguay", Email=usermail, UsuarioID=usermail, fecha_ingreso= DateTime.UtcNow }; using (var db = ChebayDBContext.CreateTenant(TiendaID)) { db.usuarios.Add(u); db.SaveChanges(); } }
public List<DataProducto> getProducts(List<Producto> products, Usuario user) { return getByCost(products, user); //getByFavoriteCategory(products, user); }
/** * 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; }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return RedirectToAction("Index", "Manage"); } if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return View("ExternalLoginFailure"); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { IDALUsuario dalU = new DALUsuarioEF(); Usuario userNuevo = new Usuario {UsuarioID = model.Email, Email = model.EmailNotification }; dalU.AgregarUsuario(userNuevo, Session["Tienda_Nombre"].ToString()); await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); return RedirectToLocal(returnUrl); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return View(model); }
public async Task<ActionResult> ExternalLoginCallback(string returnUrl) { var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); if (loginInfo == null) { return RedirectToAction("Login"); } // Sign in the user with this external login provider if the user already has a login var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false); switch (result) { case SignInStatus.Success: IDALUsuario dalU = new DALUsuarioEF(); Usuario userChebay; try { userChebay = dalU.ObtenerUsuario(loginInfo.Email, Session["Tienda_Nombre"].ToString()); Session["Usuario"] = userChebay; } catch (Exception e) { userChebay = new Usuario { UsuarioID = loginInfo.Email, Email = loginInfo.Email }; try { Debug.WriteLine(e.Message); dalU.AgregarUsuario(userChebay, Session["Tienda_Nombre"].ToString()); Session["Usuario"] = userChebay; } catch (Exception e2) { Debug.WriteLine(e2.Message); ViewBag.ErrorMessage = e2.Message; return View("Error"); } } if (userChebay != null) { } return RedirectToLocal(returnUrl); case SignInStatus.LockedOut: return View("Lockout"); case SignInStatus.RequiresVerification: return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false }); case SignInStatus.Failure: default: // If the user does not have an account, then prompt the user to create an account ViewBag.ReturnUrl = returnUrl; ViewBag.LoginProvider = loginInfo.Login.LoginProvider; return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email }); } }