예제 #1
0
        public Product GetProduct(int id)
        {
            ProductBDO productBDO = null;

            try
            {
                productBDO = productLogic.GetProduct(id);
            }
            catch (Exception e)
            {
                string msg    = e.Message;
                string reason = "GetProduct Exception";
                throw new FaultException <ProductFault>
                          (new ProductFault(msg), reason);
            }

            if (productBDO == null)
            {
                string msg =
                    string.Format("No product found for id {0}",
                                  id);
                string reason = "GetProduct Empty Product";
                throw new FaultException <ProductFault>
                          (new ProductFault(msg), reason);
            }

            Product product = new Product();

            TranslateProductBDOToProductDTO(productBDO, product);
            return(product);
        }
예제 #2
0
        public Product GetProduct(int id)
        {
            ProductEntity productEntity = productLogic.GetProduct(id);

            if (productEntity == null)
            {
                throw new Exception("No product found with id " + id);

                /*
                 * if (id != 999)
                 * {
                 * }
                 */
            }

            Product product = new Product();

            TranslateProductEntityToProductContractData(productEntity, product);

            return(product);

            /*
             * Product product = new Product();
             * product.ProductID = id;
             * product.Color = "fake color from service layer";
             * product.ListPrice = (decimal)10.0;
             * return product;
             */
        }
예제 #3
0
        public ActionResult GetProduct(int id)
        {
            ProductLogic proLogic = new ProductLogic();
            Product      pro      = proLogic.GetProduct(id);

            return(View(pro));
        }
예제 #4
0
        public Object GetProduct()
        {
            List <Product> list = _productLogic.GetProduct();

            return(new
            {
                success = true,
                Product = new { Record = list, TotalRecords = list.Count }
            });
        }
예제 #5
0
 // Deletes order from database
 public Order DeleteOrder(Order o)
 {
     foreach (OrderLine ol in o.Orderlines)
     {
         Product p = productLogic.GetProduct("productID", ol.Product.ID.ToString());
         ol.Product = p;
         orderLineDB.DeleteInDesktop(ol);
     }
     return(orderDB.Delete(o));
 }
예제 #6
0
        // Get an user with orders and orderlines, builds products on orderlines
        public User GetUserWithOrdersAndOrderlines(string email)
        {
            User user = GetUserWithOrders(email);

            foreach (Order o in user.Orders)
            {
                o.Orderlines = orderLineDB.GetOrderlinesByOrderID(o.ID);
                foreach (OrderLine ol in o.Orderlines)
                {
                    ol.Product = productLogic.GetProduct("productID", ol.Product.ID.ToString());
                }
            }
            return(user);
        }
예제 #7
0
        public Product GetProduct(int id)
        {
            var productEntity = _productLogic.GetProduct(id);

            if (productEntity == null)
            {
                if (id != 999)
                {
                    throw new FaultException <ProductFault>(new ProductFault("No product found with id " + id), "Product Fault");
                }
                throw new Exception("Test Exception");
            }

            return(TranslateProductEntityToProductContractData(productEntity));
        }
예제 #8
0
        public Product GetProduct(int id)
        {
            /*
             * // TODO: call business logic layer to retrieve product
             * Product product = new Product();
             * product.ProductID = id;
             * product.ProductName =
             *  "fake product name from service layer";
             * product.UnitPrice = 10.0m;
             * product.QuantityPerUnit = "fake QPU";
             * return product;
             */

            ProductBDO productBDO = null;

            try
            {
                productBDO = productLogic.GetProduct(id);
            }
            catch (Exception e)
            {
                string msg    = e.Message;
                string reason = "GetProduct Exception";
                throw new FaultException <ProductFault>
                          (new ProductFault(msg), reason);
            }

            if (productBDO == null)
            {
                string msg =
                    string.Format("No product found for id {0}",
                                  id);
                string reason = "GetProduct Empty Product";
                if (id == 999)
                {
                    throw new Exception(msg);
                }
                else
                {
                    throw new FaultException <ProductFault>
                              (new ProductFault(msg), reason);
                }
            }
            Product product = new Product();

            TranslateProductBDOToProductDTO(productBDO, product);
            return(product);
        }
예제 #9
0
 public void LoadDataGrid()
 {
     productGridView.DataSource = _productLogic.GetProduct();
     if (productGridView.Columns.Count > 0)
     {
         productGridView.Columns[0].IsVisible  = false;
         productGridView.Columns[6].IsVisible  = false;
         productGridView.Columns[7].IsVisible  = false;
         productGridView.Columns[8].IsVisible  = false;
         productGridView.Columns[9].IsVisible  = false;
         productGridView.Columns[1].HeaderText = "Part Number";
         productGridView.Columns[2].HeaderText = "Name";
         productGridView.Columns[3].HeaderText = "Description";
         productGridView.Columns[4].HeaderText = "Price";
         productGridView.Columns[5].HeaderText = "Class";
         productGridView.Refresh();
     }
 }
예제 #10
0
        public Product DeleteProduct(int id)
        {
            Product p = productLogic.GetProduct("productID", id.ToString());

            return(productDb.Delete(p));
        }
예제 #11
0
        // GET: api/Product/5
        public ProductJson Get(int id)
        {
            var product = productLogic.GetProduct(id);

            return(product);
        }
예제 #12
0
        public void FindProductTest()
        {
            Product p = productLogic.GetProduct("productID", 1.ToString());

            Assert.IsNotNull(p);
        }
예제 #13
0
        static void Main(string[] args)
        {
            var           finalizar        = false;
            var           connectionString = "Server=DESKTOP-RCIFPVC\\SQLEXPRESS; Database=Tienda; User Id=labUser; Password=Password01.;";
            IProductLogic logic            = new ProductLogic(new ProductDataAccessDatabase(connectionString));

            while (!finalizar)
            {
                Console.WriteLine(@"Las opciones disponibles son
                    1 listado de productos
                    2 alta de producto
                    3 eliminar producto
                    4 modificar producto
                    5 Obtener productos filtrados
                    6 salir
                ");
                var entrada = Console.ReadLine();

                switch (entrada)
                {
                case "1":
                {
                    Console.WriteLine("listado");
                    var productos = logic.ListProducts();
                    if (!productos.Any())
                    {
                        Console.WriteLine("No hay productos");
                    }

                    foreach (var producto in productos)
                    {
                        Console.WriteLine($" id {producto.Id}, Nombre {producto.Name}, Descripcion {producto.Description}, Precio {producto.Price}");
                    }


                    break;
                };

                case "2":
                {
                    Console.WriteLine("alta");

                    Console.WriteLine("Ingrese id");
                    if (!int.TryParse(Console.ReadLine(), out int id))
                    {
                        Console.WriteLine("Id incorrecto");
                        break;
                    }

                    var newProduct = RequestProductData(id);

                    if (newProduct != null)
                    {
                        try
                        {
                            logic.CreateProduct(newProduct);
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("hubo un error al ingresar el producto");
                        }
                    }

                    break;
                };

                case "3":
                {
                    Console.WriteLine("eliminar");

                    Console.WriteLine("Ingrese id");
                    if (!int.TryParse(Console.ReadLine(), out int id))
                    {
                        Console.WriteLine("Id incorrecto");
                        break;
                    }
                    try
                    {
                        var success = logic.DeleteProduct(id);
                        if (success)
                        {
                            Console.WriteLine("Producto eliminado");
                        }
                        else
                        {
                            Console.WriteLine("No se encontró el producto");
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("hubo un error al eliminar el producto");
                    }
                    break;
                };

                case "4":
                {
                    Console.WriteLine("modificar");

                    Console.WriteLine("Ingrese id a modificar");
                    if (!int.TryParse(Console.ReadLine(), out int id))
                    {
                        Console.WriteLine("Id incorrecto");
                        break;
                    }
                    try
                    {
                        var product = logic.GetProduct(id);
                        if (product == null)
                        {
                            Console.WriteLine("El producto no existe");
                            break;
                        }
                        else
                        {
                            var newProductData = RequestProductData(id);
                            if (newProductData != null)
                            {
                                newProductData.Id = id;
                                logic.UpdateProduct(newProductData);
                                Console.WriteLine("Producto actualizado");
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("hubo un error al modificar el producto");
                    }
                    break;
                };

                case "5":
                {
                    Console.WriteLine("Obtener producto filtrado");

                    Console.Write("PageIndex: ");
                    int pageIndex = int.Parse(Console.ReadLine());
                    Console.Write("PageSize: ");
                    int pageSize = int.Parse(Console.ReadLine());
                    Console.Write("Name: ");
                    string name = Console.ReadLine();
                    Console.Write("CategoryId: ");
                    int categoryId;
                    int.TryParse(Console.ReadLine(), out categoryId);
                    Console.Write("OrderByNameOrPrice: ");
                    string orderby = Console.ReadLine();
                    Console.Write("AscOrDesc: ");
                    string asc = Console.ReadLine();

                    var products = logic.GetProductsPaginated(pageIndex, pageSize, name, categoryId, orderby, asc);
                    foreach (var producto in products)
                    {
                        Console.WriteLine($" id {producto.Id}, Nombre {producto.Name}, Descripcion {producto.Description}, Precio {producto.Price}");
                    }
                    break;
                };

                case "6":
                {
                    Console.WriteLine("salir");
                    finalizar = true;
                    break;
                };

                default:
                {
                    Console.WriteLine("Opcion incorrecta");
                    break;
                };
                }
            }
        }