Пример #1
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            Detalle_Ventas detalle_Ventas = await db.Detalle_Ventas.FindAsync(id);

            detalle_Ventas.suspencion       = true;
            detalle_Ventas.fecha_suspencion = DateTime.Now;
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Пример #2
0
        public void RegistraVenta()
        {
            List <CarritoModel> carrito = (List <CarritoModel>)Session["carrito"];
            Ventas venta = new Ventas();
            //List< Detalle_Ventas> detalles = new List<Detalle_Ventas>();
            Detalle_Ventas detalle = new Detalle_Ventas();
            //List<Ventas> u = _unitOfWork.GetRepositoryInstance<Ventas>().GetAllRecords().ToList();
            Ventas lastVenta = _unitOfWork.GetRepositoryInstance <Ventas>().GetLastRecord();

            if (lastVenta != null)
            {
                venta.id = lastVenta.id + 1;
            }

            venta.fecha      = DateTime.Today;
            venta.id_usuario = ((Usuarios)Session["usr"]).id;
            venta.iva        = 0;
            venta.sub_total  = carrito.Sum(i => i.Cantidad * i.Precio_venta);
            venta.total      = venta.sub_total;

            _unitOfWork.GetRepositoryInstance <Ventas>().Add(venta);

            foreach (CarritoModel item in carrito)
            {
                Detalle_Ventas d = _unitOfWork.GetRepositoryInstance <Detalle_Ventas>().GetLastRecord();

                if (d != null)
                {
                    detalle.id = d.id + 1;
                }

                detalle.id_producto   = item.Id_producto;
                detalle.precio_venta  = item.Precio_venta;
                detalle.precio_compra = _unitOfWork.GetRepositoryInstance <Productos>().GetFirstOrDefaultByParameter(i => i.id == item.Id_producto).precio_compra;
                detalle.stat          = 1;
                detalle.id_venta      = venta.id;
                detalle.cantidad      = item.Cantidad;

                _unitOfWork.GetRepositoryInstance <Detalle_Ventas>().Add(detalle);

                Productos p        = _unitOfWork.GetRepositoryInstance <Productos>().GetFirstOrDefaultByParameter(i => i.id == item.Id_producto);
                int       cantidad = p.cantidad - item.Cantidad;

                p.cantidad = cantidad;

                _unitOfWork.GetRepositoryInstance <Productos>().Update(p);

                detalle = new Detalle_Ventas();
            }

            Session["carrito"] = null;
        }
Пример #3
0
        public async Task <ActionResult> Edit(Detalle_Ventas detalle_Ventas)
        {
            //Al ser tabla intermediaria entre dos (para evitar relación M-M... no se modifica código al no tener datos propios más que eliminación lógica)
            if (ModelState.IsValid)
            {
                db.Entry(detalle_Ventas).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.id_producto = new SelectList(db.Productos, "id_producto", "nombre_producto", detalle_Ventas.id_producto);
            ViewBag.id_venta    = new SelectList(db.Ventas, "id_venta", "id_venta", detalle_Ventas.id_venta);
            return(View(detalle_Ventas));
        }
Пример #4
0
        // GET: Detalle_Ventas/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Detalle_Ventas detalle_Ventas = await db.Detalle_Ventas.FindAsync(id);

            if (detalle_Ventas == null)
            {
                return(HttpNotFound());
            }
            return(View(detalle_Ventas));
        }
Пример #5
0
        // GET: Detalle_Ventas/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Detalle_Ventas detalle_Ventas = await db.Detalle_Ventas.FindAsync(id);

            if (detalle_Ventas == null)
            {
                return(HttpNotFound());
            }
            ViewBag.id_producto = new SelectList(db.Productos, "id_producto", "nombre_producto", detalle_Ventas.id_producto);
            ViewBag.id_venta    = new SelectList(db.Ventas, "id_venta", "id_venta", detalle_Ventas.id_venta);
            return(View(detalle_Ventas));
        }
Пример #6
0
        public async Task <ActionResult> Create(Detalle_Ventas detalle_Ventas)
        {
            if (ModelState.IsValid)
            {
                Detalle_Ventas det = await db.Detalle_Ventas.Where(x => x.id_detalle_venta == detalle_Ventas.id_detalle_venta).FirstOrDefaultAsync();

                if (det == null)
                {
                    db.Detalle_Ventas.Add(detalle_Ventas);
                    await db.SaveChangesAsync();
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.id_producto = new SelectList(db.Productos, "id_producto", "nombre_producto", detalle_Ventas.id_producto);
            ViewBag.id_venta    = new SelectList(db.Ventas, "id_venta", "id_venta", detalle_Ventas.id_venta);
            return(View(detalle_Ventas));
        }