Exemple #1
0
        internal void Crear(GenVenta infoVenta)
        {
            var venta = new Venta();

            venta.Asesor   = db.Asesor.Where(x => x.Correo.Equals(infoVenta.EmailAsesor)).Single();
            venta.Producto = db.Producto.Where(x => x.Id.Equals(infoVenta.IdProducto)).Single();
            venta.Cantidad = infoVenta.Cantidad;
            venta.Fecha    = DateTime.Now;
            venta.Valor    = infoVenta.Valor;

            var cliente = db.Cliente.Where(x => x.Documento.Equals(infoVenta.NoDocumento)).SingleOrDefault();

            if (cliente == null)
            {
                cliente = new Cliente
                {
                    Correo          = string.Empty,
                    Documento       = infoVenta.NoDocumento,
                    PrimerApelldo   = infoVenta.PrimerApellido,
                    PrimerNombre    = infoVenta.PrimerNombre,
                    SegundoApellido = infoVenta.SegundoApellido,
                    SegundoNombre   = infoVenta.SegundoNombre
                };

                db.Cliente.Add(cliente);
            }

            venta.Cliente = cliente;
            db.Venta.Add(venta);
            db.SaveChanges();
        }
Exemple #2
0
 public ActionResult Edit([Bind(Include = "Id,EmailAsesor,IdProducto,NoDocumento,PrimerNombre,SegundoNombre,PrimerApellido,SegundoApellido,Cantidad,Valor")] GenVenta genVenta)
 {
     if (ModelState.IsValid)
     {
         return(RedirectToAction("Index"));
     }
     return(View(genVenta));
 }
Exemple #3
0
        public ActionResult Create([Bind(Include = "Id,EmailAsesor,IdProducto,NoDocumento,PrimerNombre,SegundoNombre,PrimerApellido,SegundoApellido,Cantidad,Valor")] GenVenta genVenta)
        {
            if (ModelState.IsValid)
            {
                genVenta.EmailAsesor = HttpContext.User.Identity.Name;
                ventas.Crear(genVenta);
                return(RedirectToAction("Index"));
            }

            return(View(genVenta));
        }
Exemple #4
0
        // GET: GenVentas/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id.HasValue)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            GenVenta genVenta = ventas.ObtenerPorId(id.Value);

            if (genVenta == null)
            {
                return(HttpNotFound());
            }

            return(View(genVenta));
        }