コード例 #1
0
ファイル: ProductsView.cs プロジェクト: oznama/csharp
        public void Consult()
        {
            int op = -1;

            productsController = new ProductsController();

            Console.WriteLine("\t...CONSULT PRODUCT...\n");
            do
            {
                Console.WriteLine("\t1. CONSULTAR TODOS");
                Console.WriteLine("\t2. CONSULTAR POR ID");
                Console.WriteLine("\t3. REGRESAR");
                Console.Write("\t\nOPCION: ");
                op = Int32.Parse(Console.ReadLine());

                switch (op)
                {
                case 1:
                    ArrayList result = (ArrayList)productsController.Consult(0);
                    Console.WriteLine("\nPRODUCTOS ENCONTRADOS {0}", result.Count);
                    foreach (Products r in result)
                    {
                        Console.WriteLine(r);
                    }
                    break;

                case 2:
                    Console.Write("\t\n ID: ");
                    int id = Int32.Parse(Console.ReadLine());
                    Console.WriteLine(productsController.Consult(id));
                    break;

                case 3:
                    Console.Clear();
                    break;

                default:
                    Console.Write("\t\n...OPCION INVALIDA...");
                    break;
                }
            } while (op != 3);
        }
コード例 #2
0
        public void Sale()
        {
            SaleCreateDto sale = new SaleCreateDto();

            saleController    = new SalesController();
            productController = new ProductsController();

            Console.Write("\nUsuario id: ");
            sale.UserId = int.Parse(Console.ReadLine());
            Console.Write("\nCliente id: ");
            sale.ClientId = int.Parse(Console.ReadLine());
            Console.Write("\nEs Venta Fiada ?? S | N ");
            sale.Trusted = Console.ReadLine() == "S" ? true : false;

            SaleItemCreateDto item;
            bool @continue = true;

            while (@continue)
            {
                item = new SaleItemCreateDto();
                Console.Write("\n\nProduct Id: ");
                item.ProductId = int.Parse(Console.ReadLine());
                Products product = (Products)productController.Consult(item.ProductId);
                if (product != null)
                {
                    Console.Write("\nCantidad: ");
                    item.Quantity = int.Parse(Console.ReadLine());
                    sale.ProductList.Add(item);
                    sale.Total += product.Price;
                }
                else
                {
                    Console.Write("\n\n\tProducto no encontrado");
                }
                Console.Write("\n\nAgregar otro producto ?? S | N ");
                @continue = Console.ReadLine() == "S" ? true : false;
            }


            if (saleController.DoSale(sale))
            {
                Console.WriteLine("\nVenta registrada satisfactoriamente");
            }
        }