コード例 #1
0
        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)));
        }
コード例 #2
0
        public async Task <ActionResult> Puja(int?subastaId, [Bind(Include = "puja")] int puja, [Bind(Include = "TarjetaDeCreditoId")] double TarjetaDeCreditoId)
        {
            if (subastaId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Subasta subasta = await db.Subastas.FindAsync(subastaId);

            TarjetaDeCredito tarjetaDeCredito = db.Tarjetas.Find(TarjetaDeCreditoId);

            if (subasta.PujaActual < puja && tarjetaDeCredito.CreditoDisponible >= puja)
            {
                Comprador         comprador         = QuerysGeneric.GetComprador(User.Identity.Name, db.Compradores);
                UsuarioConTarjeta usuarioconTarjeta = subasta.UsuarioConTarjeta;
                if (usuarioconTarjeta != null)
                {
                    usuarioconTarjeta.TarjetadeCredito.CreditoDisponible += subasta.PujaActual;
                }
                usuarioconTarjeta                  = db.UsuarioConTarjetas.Where(m => (m.CompradorId == comprador.Id && m.TarjetadeCredito.NumDeTarjeta == TarjetaDeCreditoId)).ToList()[0];
                subasta.PujaActual                 = puja;
                subasta.UsuarioConTarjeta          = usuarioconTarjeta;
                tarjetaDeCredito.CreditoDisponible = tarjetaDeCredito.CreditoDisponible - puja;
                subasta.Comprador                  = comprador;
                db.Entry(subasta).State            = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", "Home", new { nameAnuncio = "AcceptSubasta" }));
            }

            ViewBag.AnuncioId   = new SelectList(db.Anuncios, "AnuncioId", "Etiqueta", subasta.AnuncioId);
            ViewBag.CompradorId = new SelectList(db.Compradores, "CompradorId", "Nombre", subasta.Comprador);
            return(RedirectToAction("Index", "Home", new { nameAnuncio = "ErrorSubasta" }));
        }
コード例 #3
0
        // GET: Carritos
        public ActionResult Index()
        {
            var comprador = QuerysGeneric.GetComprador(User.Identity.Name, db.Compradores);
            var carritoes = Articulos(comprador.Id);

            return(View(carritoes));
        }
コード例 #4
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)));
        }
コード例 #5
0
        public ActionResult IndexAccept(string nameAnuncio)
        {
            var Anuncios = QuerysGeneric.Get_N_Obj_Mientras <Anuncio>(db.Anuncios, 10, m => m.Cantidad > 0).OrderBy(m => m.Calificacion);
            var Subastas = QuerysGeneric.Get_N_Obj_Ordenado_Por <Subasta, int>(db.Subastas, 3, m => m.PujaActual, true);
            var Rebajas  = QuerysGeneric.Get_N_Obj_Mientras <Anuncio>(db.Anuncios, 2, m => m.Precio > m.NuevoPrecio);

            return(View(new Tuple <IEnumerable <Anuncio>, IEnumerable <Subasta>, IEnumerable <Anuncio>, string>(Anuncios, Subastas, Rebajas, nameAnuncio)));
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="compro"></param>
        /// <returns></returns>
        public ActionResult VaciarCarrito(bool compro, double numedeTarjeta = 0)
        {
            Comprador comprador = QuerysGeneric.GetComprador(User.Identity.Name, db.Compradores);

            foreach (var item in Articulos(comprador.Id))
            {
                db.Carritos.Remove(item);
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
コード例 #7
0
        // GET: Producto_Vendido/Create
        public ActionResult Create(int carritoId = -1, int Total = 0)
        {
            Comprador comprador = QuerysGeneric.GetComprador(User.Identity.Name, db.Compradores);
            IEnumerable <TarjetaDeCredito> tarjetas = QuerysGeneric.GetTarjetas(comprador.Tarjetas);
            Carrito carrito;

            if (carritoId != -1)
            {
                carrito = db.Carritos.Find(carritoId);
            }
            ViewBag.TarjetaDeCreditoId = new SelectList(tarjetas, "NumDeTarjeta", "NumDeTarjeta", new Producto_Vendido());
            ViewBag.Total     = Total;
            ViewBag.carritoId = carritoId;
            return(View(new Producto_Vendido()));
        }
コード例 #8
0
        // GET: Subastas/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            Comprador comprador = QuerysGeneric.GetComprador(User.Identity.Name, db.Compradores);
            IEnumerable <TarjetaDeCredito> tarjetas = QuerysGeneric.GetTarjetas(comprador.Tarjetas);

            ViewBag.TarjetaDeCreditoId = new SelectList(tarjetas, "NumDeTarjeta", "NumDeTarjeta", new Producto_Vendido());
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Subasta subasta = await db.Subastas.FindAsync(id);

            if (subasta == null)
            {
                return(HttpNotFound());
            }
            return(View(subasta));
        }
コード例 #9
0
        // GET: Subastas
        public async Task <ActionResult> Index(int vista = 0, int filtros1 = -1, int filtros2 = -1)
        {
            IEnumerable <Subasta> subastas;

            if (filtros1 == -1)
            {
                subastas = await db.Subastas.Include(a => a.Anuncio).Include(a => a.Comprador).Include(a => a.Anuncio.Producto).ToListAsync();
            }
            else if (filtros2 == -1)
            {
                subastas = QuerysGeneric.Get_N_Obj_Mientras(db.Subastas.Include(a => a.Anuncio).Include(a => a.Comprador).Include(a => a.Anuncio.Producto), null, m => ((int)m.Anuncio.Producto.Tipo == filtros1));
            }
            else
            {
                subastas = QuerysGeneric.Get_N_Obj_Mientras(db.Subastas.Include(a => a.Anuncio).Include(a => a.Comprador).Include(a => a.Anuncio.Producto), null, m => ((int)m.Anuncio.Producto.Tipo == filtros1 && m.Anuncio.Producto.Especificacion == filtros2));
            }
            return(View(new Tuple <IEnumerable <Subasta>, int, int, int>(subastas, vista, filtros1, filtros2)));
        }
コード例 #10
0
        public ActionResult Details([Bind(Include = "Nombre,Tipo,Especificacion,Precio,Fecha,Cantidad,Calificacion,Etiqueta,Descripcion")] ProductoAnuncio productoanuncio, int cantidad)
        {
            Anuncio   anuncio   = db.Anuncios.Find(productoanuncio.AnuncioId);
            Comprador comprador = QuerysGeneric.GetComprador(User.Identity.Name, db.Compradores);

            if (anuncio.Cantidad < cantidad)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                anuncio.Cantidad = anuncio.Cantidad - cantidad;
                db.Carritos.Add(new Carrito {
                    Comprador = comprador, CompradorId = comprador.Id, Anuncio = anuncio, AnuncioId = anuncio.AnuncioId, Cantidad = cantidad
                });
                db.SaveChanges();
            }
            return(RedirectToAction("Index", "Carritos"));
        }
コード例 #11
0
        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));
        }
コード例 #12
0
        public void RevisarSubastas()
        {
            var subastas = QuerysGeneric.Get_N_Obj_Mientras(Subastas.Include(m => m.Comprador).Include(m => m.Anuncio.Vendedor).Include(m => m.Anuncio.Vendedor.TarjetaDeCredito).Include(m => m.UsuarioConTarjeta.TarjetadeCredito).Include(m => m.Anuncio).Include(m => m.Anuncio.Producto), null, m => m.FechadeCulminacion <= DateTime.Now);

            foreach (var sub in subastas)
            {
                if (sub.Comprador != null)
                {
                    sub.Comprador.Mensaje = sub.Comprador.Mensaje + "@Ha Ganado La Subasta del Producto: " + sub.Anuncio.Producto.Nombre;
                    sub.UsuarioConTarjeta.TarjetadeCredito.CreditoContable = sub.UsuarioConTarjeta.TarjetadeCredito.CreditoContable - sub.PujaActual;
                    TarjetaDeCredito tar = sub.Anuncio.Vendedor.TarjetaDeCredito;
                    tar.CreditoContable         += sub.PujaActual;
                    tar.CreditoDisponible       += sub.PujaActual;
                    sub.Anuncio.Vendedor.Mensaje = sub.Anuncio.Vendedor.Mensaje + "@Se ha vendido su subasta del Producto: " + sub.Anuncio.Producto.Nombre + " en " + sub.PujaActual;
                    Entry(sub).State             = EntityState.Modified;
                }
            }
            Subastas.RemoveRange(subastas);
            SaveChanges();
        }
コード例 #13
0
        public async Task <ActionResult> AñadirAlCarrito([Bind(Include = "Cantidad")] int?cantidad, int idAnuncio, string controlador = "Anuncios")
        {
            Anuncio   anuncio   = db.Anuncios.Find(idAnuncio);
            Comprador comprador = QuerysGeneric.GetComprador(User.Identity.Name, db.Compradores);

            if (anuncio.Cantidad < cantidad)
            {
                return(RedirectToAction("Index", new { nameAnuncio = "ErrorCantidad" }));
            }
            else
            {
                var pedidos = QuerysGeneric.Get_N_Obj_Mientras(db.Carritos, 1, m => (m.CompradorId == comprador.Id && m.AnuncioId == idAnuncio && !(m is Producto_Vendido)));
                if (pedidos.Count() == 0)
                {
                    anuncio.Cantidad = anuncio.Cantidad - (cantidad == null?1:(int)cantidad);
                    db.Carritos.Add(new Carrito {
                        Comprador = comprador, CompradorId = comprador.Id, Anuncio = anuncio, AnuncioId = anuncio.AnuncioId, Cantidad = (cantidad == null ? 1 : (int)cantidad), FechaSeparado = DateTime.Now
                    });
                }
                else
                {
                    int Cantidad = (cantidad == null ? 1 : (int)cantidad);
                    var carrito  = pedidos.ToList()[0];
                    if (Cantidad > 0 && Cantidad <= carrito.Anuncio.Cantidad)
                    {
                        anuncio.Cantidad     += carrito.Cantidad;
                        carrito.Cantidad     += Cantidad;
                        anuncio.Cantidad     -= carrito.Cantidad;
                        carrito.FechaSeparado = DateTime.Today;
                    }
                    else
                    {
                        return(RedirectToAction("Index", controlador, new { nameAnuncio = anuncio.Producto.Nombre }));
                    }
                    db.Entry(carrito).State = EntityState.Modified;
                }

                await db.SaveChangesAsync();
            }
            return(RedirectToAction("Index", controlador, new { nameAnuncio = anuncio.Producto.Nombre }));
        }
コード例 #14
0
        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)));
        }
コード例 #15
0
        public async Task <ActionResult> CrearTarjeta([Bind(Include = "tarjeta")] double tarjeta)
        {
            if (tarjeta > 0)
            {
                Comprador user;
                if (User.IsInRole(RoleName.Comprador))
                {
                    int credito = QuerysGeneric.random.Next(100, 1000);
                    TarjetaDeCredito tarjetaDeCredito = await db.Tarjetas.FindAsync(tarjeta);

                    if (tarjetaDeCredito == null)
                    {
                        tarjetaDeCredito = new TarjetaDeCredito()
                        {
                            NumDeTarjeta      = tarjeta,
                            CreditoDisponible = credito,
                            CreditoContable   = credito
                        };
                        db.Tarjetas.Add(tarjetaDeCredito);
                        await db.SaveChangesAsync();
                    }

                    user = QuerysGeneric.GetComprador(User.Identity.Name, db.Compradores);
                    UsuarioConTarjeta usuario = new UsuarioConTarjeta()
                    {
                        Comprador        = user,
                        CompradorId      = user.Id,
                        TarjetadeCredito = tarjetaDeCredito
                    };
                    db.UsuarioConTarjetas.Add(usuario);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index", "Home", new { nameAnuncio = "AcceptTarjeta" }));
                }
            }
            return(View());
        }
コード例 #16
0
        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));
        }
コード例 #17
0
        public IEnumerable <Carrito> Articulos(int id)
        {
            var carros = QuerysGeneric.Get_N_Obj_Mientras(db.Carritos, null, m => (m.CompradorId == id && !(m is Producto_Vendido))).ToList();

            return(carros);
        }
コード例 #18
0
        public async Task <ActionResult> Create(Producto_Vendido producto_Vendido, int carritoId, int Total)
        {
            Comprador comprador = QuerysGeneric.GetComprador(User.Identity.Name, db.Compradores);
            IEnumerable <TarjetaDeCredito> tarjetas = QuerysGeneric.GetTarjetas(comprador.Tarjetas);

            ViewBag.NumDesuTarjeta          = new SelectList(tarjetas, "NumDeTarjeta", "NumDeTarjeta", new Producto_Vendido());
            producto_Vendido.NumDesuTarjeta = db.Tarjetas.Find(producto_Vendido.TarjetaDeCreditoId);
            TarjetaDeCredito tarjeta = producto_Vendido.NumDesuTarjeta;

            if (tarjeta.CreditoDisponible < Total)
            {
                return(RedirectToAction("Index", "Anuncios", new { nameAnuncio = "ErrorCompra" }));
            }
            tarjeta.CreditoDisponible = tarjeta.CreditoDisponible - Total;
            tarjeta.CreditoContable   = tarjeta.CreditoContable - Total;
            db.Entry(tarjeta).State   = EntityState.Modified;

            if (carritoId != -1)
            {
                Carrito carrito = db.Carritos.Find(producto_Vendido.CarritoId);
                producto_Vendido.CarritoId     = carritoId;
                producto_Vendido.Cantidad      = carrito.Cantidad;
                producto_Vendido.AnuncioId     = carrito.AnuncioId;
                producto_Vendido.CompradorId   = carrito.CompradorId;
                producto_Vendido.FechaSeparado = carrito.FechaSeparado;

                if (ModelState.IsValid)
                {
                    db.Producto_Vendido.Add(producto_Vendido as Producto_Vendido);
                    db.Carritos.Remove(carrito);

                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index", "Anuncios", new { nameAnuncio = "AcceptCompra" }));
                }
            }
            else
            {
                var carros = QuerysGeneric.Get_N_Obj_Mientras(db.Carritos, null, m => (m.CompradorId == comprador.Id && !(m is Producto_Vendido))).ToList();

                foreach (var item in carros)
                {
                    Producto_Vendido producto = new Producto_Vendido();
                    producto.CarritoId     = carritoId;
                    producto.Cantidad      = item.Cantidad;
                    producto.AnuncioId     = item.AnuncioId;
                    producto.CompradorId   = item.CompradorId;
                    producto.FechaSeparado = item.FechaSeparado;

                    if (ModelState.IsValid)
                    {
                        db.Producto_Vendido.Add(producto as Producto_Vendido);
                        db.Carritos.Remove(item);
                        await db.SaveChangesAsync();

                        return(RedirectToAction("Index", "Anuncios", new { nameAnuncio = "AcceptCompra" }));
                    }
                }
            }
            return(RedirectToAction("Index", "Anuncios", new { nameAnuncio = "ErrorCompra" }));
        }