public async Task <ActionResult> ElegirAnuncio() { var vendedor = QuerysGeneric.GetVendedor(User.Identity.Name, db.Vendedores); var anuncios = db.Anuncios.Where(m => m.VendedorId == vendedor.Id).Include(a => a.Producto).Include(a => a.Vendedor); return(View(new Tuple <IEnumerable <LA_VENDUTA.Models.Anuncio>, int>(await anuncios.ToListAsync(), 0))); }
public ActionResult Index(string nameAnuncio = "") { if (nameAnuncio == "") { db.RevisarSubastas(); Comprador comprador = QuerysGeneric.GetComprador(User.Identity.Name, db.Compradores); Vendedor vendedor = QuerysGeneric.GetVendedor(User.Identity.Name, db.Vendedores); if (comprador != null) { nameAnuncio = comprador.Mensaje; comprador.Mensaje = ""; db.Entry(comprador).State = EntityState.Modified; } if (vendedor != null) { nameAnuncio = vendedor.Mensaje; vendedor.Mensaje = ""; db.Entry(vendedor).State = EntityState.Modified; } db.SaveChanges(); } var Anuncios = QuerysGeneric.Get_N_Obj_Mientras <Anuncio>(db.Anuncios, 10, m => m.Cantidad > 0 && m.SoloParaSubasta == false).OrderBy(m => m.Calificacion); var Subastas = QuerysGeneric.Get_N_Obj_Ordenado_Por <Subasta, int>(db.Subastas.Include(a => a.Anuncio).Include(a => a.Comprador).Include(a => a.Anuncio.Producto).Include(a => a.Anuncio.Files), 3, m => m.PujaActual, true); var Rebajas = QuerysGeneric.Get_N_Obj_Mientras <Anuncio>(db.Anuncios, 2, m => m.Precio > m.NuevoPrecio && m.Cantidad > 0 && m.SoloParaSubasta == false); return(View(new Tuple <IEnumerable <Anuncio>, IEnumerable <Subasta>, IEnumerable <Anuncio>, string>(Anuncios, Subastas, Rebajas, nameAnuncio))); }
public async Task <ActionResult> Edit([Bind(Include = "ProductoId,AnuncioId,Nombre,Tipo,Especificacion,Precio,Fecha,Cantidad,Calificacion,Etiqueta,Descripcion")] ProductoAnuncio productoanuncio) { Anuncio anuncio = await db.Anuncios.FindAsync(productoanuncio.AnuncioId); anuncio.Cantidad = productoanuncio.Cantidad; anuncio.Descripcion = productoanuncio.Descripcion; anuncio.Etiqueta = productoanuncio.Etiqueta; anuncio.NuevoPrecio = productoanuncio.Precio; anuncio.Fecha = DateTime.Now; anuncio.Vendedor = QuerysGeneric.GetVendedor(User.Identity.Name, db.Vendedores); anuncio.VendedorId = anuncio.Vendedor.Id; Producto producto = new Producto(); producto.Nombre = productoanuncio.Nombre; producto.Tipo = productoanuncio.Tipo; HttpPostedFileBase file = Request.Files["ImageData"]; //anuncio.Image = ConvertToBytes(file); if (ModelState.IsValid) { List <Producto> productos = db.Productos.Where(m => (m.Nombre == producto.Nombre && m.Tipo == producto.Tipo)).ToList(); if (productos.Count != 0) { anuncio.Producto = productos[0]; anuncio.ProductoId = anuncio.Producto.ProductoId; } else { db.Productos.Add(producto); anuncio.Producto = producto; anuncio.ProductoId = producto.ProductoId; } db.Entry(anuncio).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } // ViewBag.ProductoId = new SelectList(db.Productos, "ProductoId", "Nombre", anuncio.ProductoId); // ViewBag.VendedorId = new SelectList(db.Vendedores, "VendedorId", "Nombre", anuncio.VendedorId); return(View(anuncio)); }
public async Task <ActionResult> Index(int vista = 0, int filtros1 = -1, int filtros2 = -1, int filtros3 = 0, string nombre = "", int precioMin = 0, int PrecioMax = 10000, string nameAnuncio = "") { Vendedor vendedor = QuerysGeneric.GetVendedor(User.Identity.Name, db.Vendedores); IEnumerable <Anuncio> anuncios; if (filtros1 == -1) { anuncios = QuerysGeneric.Get_N_Obj_Mientras(db.Anuncios.Include(a => a.Producto).Include(a => a.Vendedor), null, m => ((User.IsInRole(RoleName.Vendedor) && m.VendedorId == vendedor.Id) || m.Cantidad > 0) && m.SoloParaSubasta == false); } else { if (filtros2 == -1) { anuncios = QuerysGeneric.Get_N_Obj_Mientras(db.Anuncios.Include(a => a.Producto).Include(a => a.Vendedor), null, m => ((int)m.Producto.Tipo == filtros1 && ((User.IsInRole(RoleName.Vendedor) && m.VendedorId == vendedor.Id) || m.Cantidad > 0) && m.SoloParaSubasta == false)); } else { anuncios = QuerysGeneric.Get_N_Obj_Mientras(db.Anuncios.Include(a => a.Producto).Include(a => a.Vendedor), null, m => ((int)m.Producto.Tipo == filtros1 && m.Producto.Especificacion == filtros2 && ((User.IsInRole(RoleName.Vendedor) && m.VendedorId == vendedor.Id) || m.Cantidad > 0) && m.SoloParaSubasta == false)); } } if (filtros3 != 0) { anuncios = anuncios.Where(m => m.Precio > m.NuevoPrecio); } if (nombre != "") { anuncios = anuncios.Where(m => m.Etiqueta.Contains(nombre) || m.Producto.Nombre.Contains(nombre) || m.Descripcion.Contains(nombre)); vista = -1; } if (precioMin != 0 || PrecioMax != 10000) { vista = -1; anuncios = anuncios.Where(m => m.NuevoPrecio > precioMin && m.NuevoPrecio < PrecioMax); } return(View(new Tuple <IEnumerable <Anuncio>, int, Filtros, string>(anuncios, vista, new Filtros(filtros1, filtros2, filtros3), nameAnuncio))); }
public async Task <ActionResult> Create([Bind(Include = "Nombre,Tipo,Especificacion,Precio,Fecha,Cantidad,Calificacion,Etiqueta,Descripcion")] ProductoAnuncio productoanuncio, HttpPostedFileBase upload) { Anuncio anuncio = new Anuncio(); anuncio.Cantidad = productoanuncio.Cantidad; anuncio.Descripcion = productoanuncio.Descripcion; anuncio.Etiqueta = productoanuncio.Etiqueta; anuncio.Precio = productoanuncio.Precio; anuncio.NuevoPrecio = anuncio.Precio; anuncio.Fecha = DateTime.Now; anuncio.Vendedor = QuerysGeneric.GetVendedor(User.Identity.Name, db.Vendedores); anuncio.VendedorId = anuncio.Vendedor.Id; Producto producto = new Producto(); producto.Nombre = productoanuncio.Nombre; producto.Tipo = productoanuncio.Tipo; string fileContent = string.Empty; string fileContentType = string.Empty; try { if (ModelState.IsValid) { if (upload != null && upload.ContentLength > 0) { var avatar = new File { FileName = System.IO.Path.GetFileName(upload.FileName), FileType = FileType.Avatar, ContentType = upload.ContentType }; using (var reader = new System.IO.BinaryReader(upload.InputStream)) { avatar.Content = reader.ReadBytes(upload.ContentLength); } anuncio.Files = new List <File> { avatar }; } List <Producto> productos = db.Productos.Where(m => (m.Nombre == producto.Nombre && m.Tipo == producto.Tipo)).ToList(); if (productos.Count != 0) { anuncio.Producto = productos[0]; anuncio.ProductoId = anuncio.Producto.ProductoId; } else { db.Productos.Add(producto); anuncio.Producto = producto; anuncio.ProductoId = producto.ProductoId; } db.Anuncios.Add(anuncio); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(anuncio)); }