public DetalleVentaModel AgregaDetalle(DetalleVentaModel detvent)
        {
            try
            {
                using (var contexto = new LocalDB_ProyectoMVCEntities())
                {
                    var iExiste = contexto.DetalleVenta.Where(dv => dv.idDetalleVenta == detvent.iCveDetVenta).FirstOrDefault();

                    if (iExiste != null)
                    {
                        return(null);
                    }

                    var NuevoDetVenta = new DetalleVenta
                    {
                        idDetalleVenta = detvent.iCveDetVenta,
                        producto       = detvent.iProducto,
                        cantidad       = detvent.iCantidad,
                        venta          = detvent.iRVenta
                    };
                    contexto.DetalleVenta.Add(NuevoDetVenta);
                    contexto.SaveChanges();
                    return(detvent);
                }
            }catch (Exception e)
            {
                throw e;
            }
        }
        private void AddSalesDetails()
        {
            foreach (var item in lstArticles.Items)
            {
                detalleVenta.state   = Domain.ValueObjects.EntityState.Added;
                detalleVenta         = (DetalleVentaModel)item;
                detalleVenta.IdVenta = Convert.ToInt32(venta.IdVenta);

                bool valid = new Helps.DataValidation(detalleVenta).Validate();
                if (valid == true)
                {
                    string result = detalleVenta.SaveChanges();
                }
            }
            System.Windows.MessageBox.Show("Venta Facturada con Exito");
        }
Beispiel #3
0
        public ActionResult DetalleVenta(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (((ProyectoFinal_Ecommerce.Models.Usuarios)Session["mom"]).role_id == 2 || ((ProyectoFinal_Ecommerce.Models.Usuarios)Session["mom"]).role_id == 3)
            {
                DetalleVentaModel model = new DetalleVentaModel();
                model.venta = _unitToWork.GetRepositoryInstance <Ventas>().GetFirstorDefaultByParameter(i => i.id == id);

                Usuarios usuario = _unitToWork.GetRepositoryInstance <Usuarios>().GetFirstorDefaultByParameter(i => i.id == model.venta.id_usuario);
                usuario.pass             = "";
                usuario.fecha_nacimiento = null;
                usuario.telefono         = "";

                model.usuario = usuario;

                List <Detalle_Ventas>     lista = _unitToWork.GetRepositoryInstance <Detalle_Ventas>().GetListParameter(i => i.id_venta == id).ToList();
                List <ProductoVentaModel> pro   = new List <ProductoVentaModel>();

                foreach (Detalle_Ventas dv in lista)
                {
                    ProductoVentaModel n = new ProductoVentaModel();
                    n.cantidad     = dv.cantidad;
                    n.id           = dv.id_producto;
                    n.precio_venta = dv.precio_venta;
                    n.nombre       = _unitToWork.GetRepositoryInstance <Productos>().GetFirstorDefaultByParameter(i => i.id == dv.id_producto).nombre;
                    pro.Add(n);
                }

                model.products = pro;

                return(View(model));
            }
            return(RedirectToAction("Index", "Home"));
        }
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var itemRow   = datagridProductos.SelectedItem;
                var Container = datagridProductos.ItemContainerGenerator.ContainerFromItem(itemRow);
                var son       = AllChildren(Container);
                var name      = "txtcant";
                var control   = (TextBox)son.First(c => c.Name == name);



                double subTotal;

                if (datagridProductos.SelectedCells.Count > 0 && control.Text != "")
                {
                    DetalleVentaModel detail = new DetalleVentaModel();
                    producto           = (ProductoModel)datagridProductos.SelectedItem;
                    detalleVenta.state = Domain.ValueObjects.EntityState.Added;
                    //aqui logica de detalle venta
                    detail.CodigoProducto = producto.Codigo_producto;
                    detail.Cantidad       = Convert.ToInt32(control.Text);
                    subTotal        = detail.Cantidad * producto.Precio;
                    detail.Subtotal = subTotal;

                    lstArticles.Items.Add(detail);
                    control.Text = "";
                }
                else
                {
                    System.Windows.MessageBox.Show("Debes seleccionar una fila que contenga una cantidad para poder hacer una venta");
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Error:" + ex.Message);
            }
        }