Exemple #1
0
        /// <summary>
        /// Find method.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Product Find(int id)
        {
            var productDac = new ProductDAC();
            var result     = productDac.SelectById(id);

            return(result);
        }
        public Product GetProduct(int id)
        {
            var productDAC = new ProductDAC();
            var result     = productDAC.SelectById(id);

            return(result);
        }
        /// <summary>
        /// Add method.
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public Order Add(Order order)
        {
            double totalprice = 0;

            foreach (OrderDetail detail in order.Details)
            {
                Product p = pdac.SelectById(detail.ProductId);
                if (p == null)
                {
                    throw new Exception("Product not found");
                }
                detail.Price = p.Price;
                totalprice  += detail.Quantity * detail.Price;
            }
            order.TotalPrice = totalprice;
            order.CreatedOn  = DateTime.Now;
            order.ChangedOn  = DateTime.Now;
            var orderDac        = new OrderDac();
            var orderDetailsDac = new OrderDetailDac();

            order = orderDac.Create(order);

            foreach (OrderDetail detail in order.Details)
            {
                detail.OrderId   = order.Id;
                detail.CreatedOn = DateTime.Now;
                detail.ChangedOn = DateTime.Now;
                orderDetailsDac.Create(detail);
            }


            return(order);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Product Find(int id)
 {
     return(productDAC.SelectById(id));
 }