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 bool AddLineItem(VendorOrder order, Product product, int qty)
        {
            if (order == null)
            {
                throw new ApplicationException("Vendor Order is null");
            }
            if (product == null)
            {
                throw new ApplicationException("Product cannot be null");
            }
            if (qty == null)
            {
                qty = 0;
            }
            VendorOrderLineItem lineItem = new VendorOrderLineItem(order.Id, product.Id);

            lineItem.QtyOrdered = qty;
            var result = VendorOrderLineItemDAL.Add(lineItem, _connection);

            if (result)
            {
                order.AddLineItem(lineItem);
            }
            return(result);
        }
Example #3
0
        public List <VendorOrderLineItem> GetExceptionItemsByVendorOrder(VendorOrder vendorOrder)
        {
            if (vendorOrder == null)
            {
                throw new ApplicationException("No such VendorOrder");
            }
            var exceptionLineItems = VendorOrderLineItemDAL.GetExceptionItemsByVendorOrder(vendorOrder, _connection);

            return(exceptionLineItems ?? new List <VendorOrderLineItem>());
        }
Example #4
0
        public bool UpdateQtyDamaged(VendorOrderLineItem currentLineItem, VendorOrderLineItem oldLineItem)
        {
            if (currentLineItem == null)
            {
                throw new ApplicationException("VendorOrderLineItem is null");
            }
            if (currentLineItem.QtyDamaged < 0)
            {
                Console.Write("Qty Damaged can't be negative");
                throw new ApplicationException("Quantity damaged cannot be negative.");
            }
            currentLineItem.QtyReceived = oldLineItem.QtyReceived;
            currentLineItem.QtyDamaged  = oldLineItem.QtyDamaged + currentLineItem.QtyDamaged;
            var result = VendorOrderLineItemDAL.Update(oldLineItem, currentLineItem, _connection);

            return(result);
        }
        public bool UpdateLineItem(VendorOrderLineItem item, int newQtyOrdered)
        {
            if (item == null)
            {
                throw new ApplicationException("VendorOrderLineItem cannot be null");
            }
            if (newQtyOrdered == null)
            {
                newQtyOrdered = 0;
            }
            var oldLineItem = item;

            item.QtyOrdered = newQtyOrdered;
            var result = VendorOrderLineItemDAL.Update(oldLineItem, item, _connection);

            return(result);
        }
Example #6
0
        public bool UpdateLineItemNote(VendorOrderLineItem currentLineItem, String note)
        {
            if (currentLineItem == null)
            {
                throw new ApplicationException("VendorOrderLineItem is null");
            }
            if (note == null)
            {
                note = "";
            }
            if (note.Length > 250)
            {
                throw new ApplicationException("Note can only be 250 characters long.");
            }
            var oldLineItem = currentLineItem;

            currentLineItem.Note = note;
            var result = VendorOrderLineItemDAL.UpdateNote(currentLineItem, _connection);

            return(result);
        }
Example #7
0
        public bool AddNewLineItemToVendorOrder(VendorOrder vendorOrder, Product productToAdd, int qtyReceived, string note, int qtyDamaged)
        {
            if (productToAdd == null)
            {
                throw new ApplicationException("Product can't be null");
            }
            if (vendorOrder == null)
            {
                throw new ApplicationException("VendorOrder can't be null");
            }
            if (qtyReceived <= 0)
            {
                throw new ApplicationException("Quantity recieved has to be greater than 0");
            }
            var newVendorOrderLineItem = new VendorOrderLineItem(vendorOrder.Id, productToAdd.Id)
            {
                QtyOrdered  = 0,
                QtyReceived = qtyReceived,
                QtyDamaged  = qtyDamaged,
                Note        = note
            };

            return(VendorOrderLineItemDAL.Add(newVendorOrderLineItem, _connection));
        }