Example #1
0
 public ResultadoOperacion AgregarProducto(ElementoCarrito item)
 {
     if (ExisteElemento(item))
     {
         AumentarCantidad(item, 1);
     }
     else
     {
         AgregarProductoEnCarrito(item);
     }
     return new ResultadoOperacion()
     {
         Mensaje = "Agregado Satisfactoriamente",
         Resultado = Resultado.ok
     };
 }
Example #2
0
        public ResultadoOperacion AumentarCantidad(ElementoCarrito item, int cantidad)
        {
            ResultadoOperacion mensaje = new ResultadoOperacion();

            var prod = Productos.SingleOrDefault(p => p.ProductoId == item.ProductoId);
            if (prod != null)
            {
                prod.Cantidad += cantidad;
                if (prod.Cantidad <= 0)
                {
                    mensaje = EliminarProducto(item);
                }
            }
            else
            {
                mensaje.Mensaje = "No existe el producto en el carrito de compra";
                mensaje.Resultado = Resultado.Error;
            }
            return mensaje;
        }
Example #3
0
 private void AgregarProductoEnCarrito(ElementoCarrito item)
 {
     this.Productos.Add(item);
 }
Example #4
0
 /*        private void AumentarCantidad(ElementoCarrito item)
         {
             foreach (ElementoCarrito producto in this.Productos)
             {
                 if (producto.CompareTo(item) > 0)
                     producto.Cantidad++;
             }
         }
         */
 private bool ExisteElemento(ElementoCarrito item)
 {
     return Productos.Any(p => p.ProductoId == item.ProductoId);
 }
Example #5
0
 public ResultadoOperacion EliminarProducto(ElementoCarrito item)
 {
     Productos.Remove(item);
     return new ResultadoOperacion() { };
 }