public bool AddVendorOrder(VendorOrder order)
        {
            if (order == null)
            {
                throw new ApplicationException("Order cannot be null");
            }
            if (order.DateOrdered == null)
            {
                order.DateOrdered = DateTime.Now;
            }
            var result = VendorOrderDAL.Add(order, _connection);

            if (result)
            {
                var newVendorOrder = VendorOrderDAL.GetVendorOrderByVendorAndDate(order.VendorID, _connection);
                if (order.LineItems != null)
                {
                    foreach (var item in order.LineItems)
                    {
                        item.VendorOrderId = newVendorOrder.Id;
                        if (item.Note == null || item.Note == "")
                        {
                            item.Note = "no note";
                        }
                        if (VendorOrderLineItemDAL.Add(item, _connection))
                        {
                            prodMan.AddToOnOrder(item.QtyOrdered, item.ProductID);
                        }
                    }
                }
            }
            return(result);
        }
        public Boolean FinalizeVendorOrder(VendorOrder order)
        {
            if (order == null)
            {
                throw new ApplicationException("VendorOrder cannot be null");
            }
            if (order.LineItems == null)
            {
                throw new ApplicationException("VendorOrder cannot have zero line items");
            }
            var oldOrder = new VendorOrder(order.Id, order.VendorID);

            oldOrder.Finalized         = order.Finalized;
            oldOrder.NumberOfShipments = order.NumberOfShipments;
            order.Finalized            = true;
            foreach (VendorOrderLineItem item in order.LineItems)
            {
                prodMan.AddToAvailable(item.QtyReceived, item.ProductID);
                prodMan.AddToOnHand(item.QtyDamaged + item.QtyReceived, item.ProductID);
                prodMan.RemoveFromOnOrder(item.QtyReceived + item.QtyDamaged, item.ProductID);
            }
            var result = VendorOrderDAL.Update(oldOrder, order, _connection);

            return(result);
        }
 public VendorOrder getVendorOrder(int VendorOrderID)
 {
     if (VendorOrderID < 0)
     {
         throw new ApplicationException("VendorOrderID must be positive");
     }
     return(VendorOrderDAL.GetVendorOrder(VendorOrderID, _connection));
 }
Esempio n. 4
0
        public List <VendorOrder> GetAllOpenOrdersByVendor(Vendor vendor)
        {
            if (vendor == null)
            {
                throw new ApplicationException("No such Vendor");
            }
            var vendorOrders = VendorOrderDAL.GetAllOpenOrdersByVendor(vendor.Id, _connection);

            return(vendorOrders ?? new List <VendorOrder>());
        }
        public bool UpdateShipmentsReceived(VendorOrder order, int qtyReceived)
        {
            if (order == null)
            {
                throw new ApplicationException("VendorOrder cannot be null");
            }
            if (qtyReceived + order.NumberOfShipments < 0)
            {
                throw new ApplicationException("Total quantity of shipments received cannot be negative");
            }
            var oldOrder = order;

            order.NumberOfShipments += qtyReceived;
            var result = VendorOrderDAL.Update(oldOrder, order, _connection);

            return(result);
        }
Esempio n. 6
0
        public List <VendorOrder> GetAllOpenOrders()
        {
            var vendorOrders = VendorOrderDAL.GetAll(_connection);

            return(vendorOrders ?? new List <VendorOrder>());
        }