コード例 #1
0
        public void Add(string productCode)
        {
            if (string.IsNullOrWhiteSpace(productCode))
            {
                throw new ArgumentNullException(nameof(productCode));
            }

            var product = _productRepository.Find(productCode);

            if (product == null)
            {
                throw new Exception($"{productCode} does not exist.");
            }

            var existingItem = this[product];

            if (existingItem == null)
            {
                this[product] = new ProductOrderDetails {
                    Quantity = 1
                };
            }
            else
            {
                existingItem.Quantity++;
            }
        }
コード例 #2
0
        public bool DeleteProductOrderDetailsDAL(string productOrderID)
        {
            bool ProductOrderDeleted = false;

            try
            {
                ProductOrderDetails deleteProductOrder = null;
                foreach (ProductOrderDetails item in productorderList)
                {
                    if (item.ProductOrderID == productOrderID)
                    {
                        deleteProductOrder = item;
                    }
                }

                if (deleteProductOrder != null)
                {
                    productorderList.Remove(deleteProductOrder);
                    ProductOrderDeleted = true;
                }
            }
            catch (Exception ex)
            {
                throw new  InventoryException(ex.Message);
            }
            return(ProductOrderDeleted);
        }
コード例 #3
0
        public bool AddProductOrderDetailsDAL(ProductOrderDetails orderdetail, List <ProductOrderDetails> orderDetails)
        {
            bool ProductorderDetailAdded = false;

            try
            {
                orderDetails.Add(orderdetail);
                ProductorderDetailAdded = true;
            }
            catch (Exception ex)
            {
                throw new InventoryException(ex.Message);
            }
            return(ProductorderDetailAdded);
        }
コード例 #4
0
        public InvoiceDetails Invoice(FinalOrder finalOrder)
        {
            int    sum    = 0;
            Orders orders = new Orders();

            orders.CustomerId   = finalOrder.CustomerId;
            orders.OrderDate    = DateTime.Now;
            orders.DeliveryDate = DateTime.Now.AddDays(7);


            for (int i = 0; i < finalOrder.products.Count; i++)
            {
                sum += finalOrder.products[i].Quantity * finalOrder.products[i].Price;
            }
            orders.TotalAmount = sum;
            context.Orders.Add(orders);
            context.SaveChanges();
            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            ProductOrderDetails[] products = new ProductOrderDetails[finalOrder.products.Count];
            for (int i = 0; i < finalOrder.products.Count; i++)
            {
                products[i] = new ProductOrderDetails()
                {
                    OrderId   = orders.OrderId,
                    ProductId = finalOrder.products[i].ProductId,
                    Price     = finalOrder.products[i].Price,
                    Quantity  = finalOrder.products[i].Quantity
                };
            }
            context.ProductOrderDetails.AddRange(products);

            Payment payment = new Payment();

            payment.Method      = finalOrder.PaymentMode;
            payment.OrderId     = orders.OrderId;
            payment.PaymentDate = DateTime.Now;

            context.Payment.Add(payment);
            context.SaveChanges();
            Customer customer = context.Customer.SingleOrDefault(c => c.CustomerId == finalOrder.CustomerId);

            customer.Orders = null;
            InvoiceDetails details = new InvoiceDetails();

            details.customer  = customer;
            details.InvoiceNo = payment.InvoiceNo;
            return(details);
        }
コード例 #5
0
        public bool UpdateProductOrderDetailsDAL(ProductOrderDetails updateorder)
        {
            bool orderUpdated = false;

            try
            {
                for (int i = 0; i < productorderList.Count; i++)
                {
                    if (productorderList[i].ProductOrderID == updateorder.ProductOrderID)
                    {
                        productorderList[i] = updateorder;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new InventoryException(ex.Message);
            }
            return(orderUpdated);
        }
コード例 #6
0
        public int UpdateQuantity(ReorderLevelDetails[] r)
        {
            int Quantity = 0;

            ProductOrderDetails[] ary = new ProductOrderDetails[r.Length];

            foreach (var i in r)
            {
                Quantity += i.Quantity;
            }
            ProductOrder o = new ProductOrder()
            {
                ProductOrderDate     = DateTime.Now,
                ProductOrderQuantity = Quantity,
            };

            if (o.ProductOrderQuantity != 0)
            {
                context.ProductOrder.Add(o);
                context.SaveChanges();
            }
            for (int j = 0; j < r.Length; j++)
            {
                ary[j] = new ProductOrderDetails()
                {
                    ProductOrderQuantity = r[j].Quantity,
                    BookId    = r[j].BookId,
                    RequestId = o.RequestId
                };
                if (ary[j].ProductOrderQuantity != 0)
                {
                    context.ProductOrderDetails.AddRange(ary[j]);
                    context.SaveChanges();
                }
            }
            return(o.RequestId);
        }