//TODO: modificar nombre "index" por punto de venta
        public IActionResult PuntoVenta()
        {
            CarroCompras cart        = SessionHelper.GetObjectFromJson <CarroCompras>(HttpContext.Session, "cart");
            var          clienteInfo = SessionHelper.GetObjectFromJson <ClienteDTO>(HttpContext.Session, "clienteInformacion");
            int          ventaId     = (int)SessionHelper.GetObjectFromJson <int>(HttpContext.Session, "ventaId");

            PuntoVentaViewModel puntoVentaViewModel = new PuntoVentaViewModel();

            puntoVentaViewModel.CarroArticulos     = cart;
            puntoVentaViewModel.VentaId            = ventaId;
            puntoVentaViewModel.InformacionCliente = clienteInfo;

            /*
             * si hubo una venta "reinicia" ventaId a "0", el cual indica que habra una nueva venta y no
             * imprimira un comprobante de venta
             * */
            if (ventaId != 0)
            {
                SessionHelper.SetObjectAsJson(HttpContext.Session, "ventaId", 0);
                SessionHelper.SetObjectAsJson(HttpContext.Session, "clienteInformacion", null);
            }


            return(View(puntoVentaViewModel));
        }
Exemplo n.º 2
0
        }//fin del constructor

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            //registrar el AppDBContext para interctuar con la conexion al DBMS
            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(_configurationRoot.GetConnectionString("DefaultConnection")));
            //registrar mis clases repositorios y mock ya que todo es un servicio
            //actualizado por implementacion EFCore
            //services.AddTransient<ICatProductosRepositorio, MockCatProductosRepositorio>();
            //services.AddTransient<IProductosRepositorio, MockProductosRepositorio>();
            services.AddTransient <ICatProductosRepositorio, CatProductosRepositorio>();
            services.AddTransient <IProductosRepositorio, ProductosRepositorio>();

            services.AddTransient <ICatUsuariosRepositorio, CatUsuariosRepositorio>();
            services.AddTransient <IUsuariosRepositorio, UsuariosRepositorio>();

            services.AddTransient <IUsuariosRepositorio, UsuariosRepositorio>();


            //registros para que la clase CarroCompras pueda trabajar con el DBContext
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();


            //clase que permite crear un objeto que se asociara con cada usuario que haga
            //uso de la clase CarroCompras. Es como una instancia
            services.AddScoped <CarroCompras>(sp => CarroCompras.GetCarroCompras(sp));

            //agrega soporte MVC a mi proyecto
            services.AddMvc();

            //habilitacion de trabajar con sesiones
            services.AddMemoryCache();
            services.AddSession();
        }
Exemplo n.º 3
0
        public ActionResult Agregar(CarroCompras carroCompras, int id, string regresarUrl)
        {
            Producto producto = context.Productos.FirstOrDefault(p => p.Id == id);

            carroCompras.AgregarLinea(producto);

            return(RedirectToAction("Mostrar", new { regresarUrl }));
        }
Exemplo n.º 4
0
        public void AgregaUnaNuevaLineaCuandoElProductoNoExiste()
        {
            var carroCompras = new CarroCompras();

            carroCompras.AgregarLinea(new Producto());

            Assert.AreEqual(1, carroCompras.CantidadProductos);
        }
Exemplo n.º 5
0
 public ActionResult Comprar(CarroCompras carroCompras)
 {
     //DatabaseContext context = new DatabaseContext();
     //var orden = new Orden(carroCompras);
     //context.Ordenes.Add(orden);
     //context.SaveChanges();
     return(View());
 }
        public IActionResult EliminarArticulo([FromQuery] int IdArticulo)
        {
            CarroCompras cart  = SessionHelper.GetObjectFromJson <CarroCompras>(HttpContext.Session, "cart");
            int          index = isExist(IdArticulo);

            cart.Articulos.RemoveAt(index);
            SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
            return(RedirectToAction("PuntoVenta"));
        }
Exemplo n.º 7
0
 public ActionResult Confirmacion(CarroCompras carroCompras)
 {
     //var confirmacion = new Confirmacion
     //    {
     //        Productos = carroCompras.TotalProductos(),
     //        Envio = carroCompras.TotalEnvio(),
     //        Total = carroCompras.Total()
     //    };
     return(View(carroCompras));
 }
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            CarroCompras carroCompras = (CarroCompras)controllerContext.HttpContext.Session[sessionKey];

            if (carroCompras == null)
            {
                carroCompras = new CarroCompras();
                controllerContext.HttpContext.Session[sessionKey] = carroCompras;
            }
            return(carroCompras);
        }
        public void AgregarLinea_ProductoNoExiste_LineaAgregada()
        {
            //Arrange
            var carroCompras = new CarroCompras();

            //Act
            carroCompras.AgregarLinea(new Producto());

            //Assert
            Assert.AreEqual(1, carroCompras.CantidadProductos);
        }
        public ActionResult Agregar(CarroCompras carroCompras, int id, [DefaultValue(1)] int cantidad, string regresarUrl)
        {
            using (var session = NHibernateConfigurator.GetSession())
                using (var transaction = session.BeginTransaction())
                {
                    var producto = session.Get <Producto>(id);
                    carroCompras.AgregarLinea(producto, cantidad);
                    transaction.Commit();
                }

            return(RedirectToAction("Mostrar", new { regresarUrl }));
        }
Exemplo n.º 11
0
        public void ActualizaLaCantidadCuandoElProductoExiste()
        {
            var carroCompras = new CarroCompras();

            carroCompras.AgregarLinea(new Producto {
                Id = 1
            });

            carroCompras.ActualizarLinea(1, 3);

            Assert.AreEqual(3, carroCompras.CantidadProductos);
        }
Exemplo n.º 12
0
        public void RemueveLaLineaAlActualizarCuandoLaCantidadEsCero()
        {
            var carroCompras = new CarroCompras();

            carroCompras.AgregarLinea(new Producto {
                Id = 1
            });

            carroCompras.ActualizarLinea(1, 0);

            Assert.AreEqual(0, carroCompras.CantidadProductos);
        }
Exemplo n.º 13
0
        public void ActualizarLinea_ProductoExiste_CantidadIncrementada()
        {
            var carroCompras = new CarroCompras();

            carroCompras.AgregarLinea(new Producto {
                Id = 1
            });

            carroCompras.ActualizarLinea(1, 3);

            Assert.AreEqual(3, carroCompras.CantidadProductos);
        }
Exemplo n.º 14
0
        public void ActualizarLinea_CantidadCero_RemueveLaLinea()
        {
            var carroCompras = new CarroCompras();

            carroCompras.AgregarLinea(new Producto {
                Id = 1
            });

            carroCompras.ActualizarLinea(1, 0);

            Assert.AreEqual(0, carroCompras.CantidadProductos);
        }
        private int isExist(int IdArticulo)
        {
            CarroCompras cart = SessionHelper.GetObjectFromJson <CarroCompras>(HttpContext.Session, "cart");

            for (int i = 0; i < cart.Articulos.Count; i++)
            {
                if (cart.Articulos[i].Id.Equals(IdArticulo))
                {
                    return(i);
                }
            }
            return(-1);
        }
Exemplo n.º 16
0
        public void IncrementaLaCantidadAlAgregarUnaLineaCuandoElProductoExiste()
        {
            var carroCompras = new CarroCompras();

            carroCompras.AgregarLinea(new Producto {
                Id = 1
            });

            carroCompras.AgregarLinea(new Producto {
                Id = 1
            });

            Assert.AreEqual(2, carroCompras.CantidadProductos);
        }
Exemplo n.º 17
0
        public void AgregarLinea_ProductoYaExiste_IncrementaLaCantidadDeLaLinea()
        {
            var carroCompras = new CarroCompras();

            carroCompras.AgregarLinea(new Producto {
                Id = 1
            });

            carroCompras.AgregarLinea(new Producto {
                Id = 1
            });

            Assert.AreEqual(2, carroCompras.CantidadProductos);
        }
Exemplo n.º 18
0
        public void RemoverLinea_ProductoExiste_RemueveLaLinea()
        {
            //Arrange
            var carroCompras = new CarroCompras();

            carroCompras.AgregarLinea(new Producto {
                Id = 1
            });

            //Act
            carroCompras.RemoverLinea(1);

            //Assert
            Assert.AreEqual(0, carroCompras.CantidadProductos);
        }
Exemplo n.º 19
0
        public void DataDrivenTesting()
        {
            var carroCompras = new CarroCompras();
            int cantidad     = int.Parse(this.TestContext.DataRow["Cantidad"].ToString());
            int precio       = int.Parse(this.TestContext.DataRow["Precio"].ToString());;
            int costoenvio   = int.Parse(this.TestContext.DataRow["CostoEnvio"].ToString());

            for (int i = 0; i < cantidad; i++)
            {
                carroCompras.AgregarLinea(new Producto
                {
                    Id     = 1,
                    Precio = precio
                });
            }
            carroCompras.CostoEnvio = costoenvio;

            var total = carroCompras.Total;

            Assert.AreEqual(int.Parse(this.TestContext.DataRow["Total"].ToString()), total);
        }
        public IActionResult VenderArticulos(PuntoVentaViewModel p_puntoVentaViewModel)
        {
            try
            {
                CarroCompras cart = SessionHelper.GetObjectFromJson <CarroCompras>(HttpContext.Session, "cart");
                if (cart == null)
                {
                    throw new Exception("Debe agregar articulos al carro de compras para generar una venta");
                }
                if (cart.Articulos?.Count != 0)
                {
                    int ventaId = this._ventaService.GenerarVenta(cart.Articulos, p_puntoVentaViewModel.InformacionCliente);
                    if (ventaId != 0)
                    {
                        cart = null;
                        SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", null);               //TODO: verificar si esto esta de mas
                        SessionHelper.SetObjectAsJson(HttpContext.Session, "clienteInformacion", null); //TODO: verificar si esto esta de mas
                        SessionHelper.SetObjectAsJson(HttpContext.Session, "ventaId", ventaId.ToString());
                        ViewBag.result = "Se realizo la venta con exito.";
                    }
                    return(RedirectToAction("PuntoVenta"));
                }
                else
                {
                    ViewBag.info = "Debe agregar articulos al carro de compras.";
                    return(RedirectToAction("PuntoVenta"));
                }
            }
            catch (Exception e)
            {
                ViewBag.error = e.Message;

                AlmacenarInformacionClienteSession(p_puntoVentaViewModel);

                return(View("PuntoVenta", p_puntoVentaViewModel));
            }
        }
Exemplo n.º 21
0
 public CarroComprasContenido(CarroCompras carroCompras)
 {
     _carroCompras = carroCompras;
 }//fin del constructor
Exemplo n.º 22
0
        public void SeProduceUnErrorAlActualizarCuandoElProductoNoExiste()
        {
            var carroCompras = new CarroCompras();

            carroCompras.ActualizarLinea(1, 1);
        }
        public IActionResult AgregarArticulo([FromQuery] string p_codigoBarras, [FromQuery] int cantidadUnideades, PuntoVentaViewModel puntoVentaViewModel)
        {
            try
            {
                bool hayStoy = false;
                //debe traer el registro de un articulo el cual tiene asignado stock, sino retorna null
                ArticuloDTO articuloDTO = this._articuloService.ObtenerArticuloPorCodigoBarras(p_codigoBarras);
                if (articuloDTO != null)
                {
                    hayStoy = (articuloDTO.CantidadStock - cantidadUnideades) >= 0;
                }

                if (articuloDTO != null && hayStoy)
                {
                    if (SessionHelper.GetObjectFromJson <CarroCompras>(HttpContext.Session, "cart") == null)
                    {
                        CarroCompras cart = new CarroCompras();
                        cart.Articulos.Add(new CarroItemDTO
                        {
                            Id                   = articuloDTO.Id,
                            Descripcion          = articuloDTO.Descripcion,
                            CategoriaDescripcion = articuloDTO.CategoriaDescripcion,
                            ModeloDescripcion    = articuloDTO.ModeloDescripcion,
                            ColorDescripcion     = articuloDTO.ColorDescripcion,
                            Precio               = articuloDTO.Precio,
                            CantidadUnidades     = cantidadUnideades,
                            Total                = cantidadUnideades * articuloDTO.Precio,
                        });
                        SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
                        AlmacenarInformacionClienteSession(puntoVentaViewModel);
                    }
                    else
                    {
                        CarroCompras cart  = SessionHelper.GetObjectFromJson <CarroCompras>(HttpContext.Session, "cart");
                        int          index = isExist(articuloDTO.Id);
                        if (index != -1)
                        {
                            //cart.CarroArticulos[index].ca++;
                        }
                        else
                        {
                            cart.Articulos.Add(new CarroItemDTO
                            {
                                Id                = articuloDTO.Id,
                                Descripcion       = articuloDTO.Descripcion,
                                ModeloDescripcion = articuloDTO.ModeloDescripcion,
                                ColorDescripcion  = articuloDTO.ColorDescripcion,
                                Precio            = articuloDTO.Precio,
                                CantidadUnidades  = cantidadUnideades,
                                Total             = cantidadUnideades * articuloDTO.Precio,
                            });
                        }
                        SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
                        AlmacenarInformacionClienteSession(puntoVentaViewModel);
                    }
                    var puntoDeVentaVM = ConstruirPuntoVentaViewModel();
                    return(View("PuntoVenta", puntoDeVentaVM));
                }
                else
                {
                    if (!hayStoy)
                    {
                        ViewBag.info = $"El articulo ingresado no tiene stock disponible para la cantidad ingresada. su stock disponible es de: {articuloDTO?.CantidadStock}.";
                    }
                    if (articuloDTO == null)
                    {
                        ViewBag.info = "El articulo no tiene stock asignado o no existe, solo se puede agregar articulos con stock asignado.";
                    }

                    var cart        = SessionHelper.GetObjectFromJson <CarroCompras>(HttpContext.Session, "cart");
                    var clienteInfo = SessionHelper.GetObjectFromJson <ClienteDTO>(HttpContext.Session, "clienteInformacion");


                    var puntoDeVentaVM = ConstruirPuntoVentaViewModel();
                    puntoDeVentaVM.InformacionCliente = clienteInfo;
                    return(View("PuntoVenta", puntoDeVentaVM));
                }
            }
            catch (Exception ex)
            {
                ViewBag.error = ex.Message;
                var puntoDeVentaVM = ConstruirPuntoVentaViewModel();
                return(View("PuntoVenta", puntoDeVentaVM));
            }
        }
Exemplo n.º 24
0
 public CarroComprasController(IProductosRepositorio productosRepositorio, CarroCompras carroCompras)
 {
     _productosRepositorio = productosRepositorio;
     _carroCompras         = carroCompras;
 }//fin del constructor
Exemplo n.º 25
0
 public ActionResult Eliminar(CarroCompras carroCompras, int id, string regresarUrl)
 {
     carroCompras.RemoverLinea(id);
     return(RedirectToAction("Mostrar", new { regresarUrl }));
 }
Exemplo n.º 26
0
 public ActionResult Actualizar(CarroCompras carroCompras, int id, int cantidad, string regresarUrl)
 {
     carroCompras.ActualizarLinea(id, cantidad);
     return(RedirectToAction("Mostrar", new { regresarUrl }));
 }
Exemplo n.º 27
0
 public ActionResult Envio(CarroCompras carroCompras, DireccionEnvio envio)
 {
     carroCompras.Envio = envio;
     return(RedirectToAction("Confirmacion"));
 }
Exemplo n.º 28
0
 public ActionResult Mostrar(CarroCompras carroCompras, string regresarUrl)
 {
     ViewBag.RegresarUrl = regresarUrl;
     return(View(carroCompras));
 }