Exemplo n.º 1
0
Arquivo: Store.cs Projeto: fswong/WDT1
        /// <summary>
        /// if there is sufficient quantity in the store, reduce the store quantity
        /// </summary>
        /// <param name="store"></param>
        /// <param name="ProductID"></param>
        /// <param name="Quantity"></param>
        /// <returns></returns>
        public BusinessObject.Store PurchaseItem(BusinessObject.Store store, int ProductID, int Quantity)
        {
            try
            {
                // TODO pass this to the BO
                //get the item from the store
                var siRepo = new StoreInventoryRepository();
                var item   = siRepo.GetStoreInventoryByStoreIdAndProductId(StoreID: store._poco.StoreID, ProductID: ProductID);

                // validate that there is enough stock
                if (item.StockLevel >= Quantity)
                {
                    int newStock = item.StockLevel - Quantity;
                    siRepo.UpdateStoreInventory(StoreID: store._poco.StoreID, ProductID: ProductID, Quantity: newStock);

                    // refresh the store's inventory
                    // this is the stores internal private method, so this logic has to move into the store
                }
                else
                {
                    throw new Exception("Insufficient stock to process this request");
                }
                return(store);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// displays list of stock below threshold
 /// </summary>
 /// <param name="Threshold"></param>
 /// <returns></returns>
 public List <DataObject.StoreInventory> DisplayStockThreshold(int Threshold)
 {
     try {
         var stock = new StoreInventoryRepository().GetStoreRequestByStoreIdAndThreshold(StoreID: _poco.StoreID, Threshold: Threshold);
         return(stock);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// list store products
        /// </summary>
        public int?DisplayProducts()
        {
            var headers   = new List <string>();
            var content   = new List <string>();
            var responses = new List <int>();
            var footer    = "Enter product ID to purchase or function: ";

            //generate header
            string[] header = { "ID", "Product", "Current Stock" };
            header[0] = header[0].PadRight((int)Padding.id, ' ');
            header[1] = header[1].PadRight((int)Padding.name, ' ');
            header[2] = header[2].PadRight((int)Padding.quantity, ' ');

            string headerString = "";

            foreach (string str in header)
            {
                headerString += str;
            }

            headers.Add(headerString);

            var products = new StoreInventoryRepository().GetStoreInventoryByStoreId(_store._poco.StoreID, true);

            //generate details
            foreach (var item in products)
            {
                string outputRow =
                    item.ProductID.ToString().PadRight((int)Padding.id, ' ') +
                    item.ProductName.PadRight((int)Padding.name, ' ') +
                    item.StockLevel.ToString().PadRight((int)Padding.quantity, ' ');
                content.Add(outputRow);
                responses.Add(item.ProductID);
            }

            var obj = new WidgetPaging(headers, content, footer, responses);

            return(obj.ReturnSelection());
        }
Exemplo n.º 4
0
        /// <summary>
        /// if valid, transfers from the owners stock to the relavant store
        /// </summary>
        /// <param name="stockRequestID"></param>
        public void ProcessStockRequest(int stockRequestID)
        {
            try
            {
                var StockRequest = new StockRequestRepository().GetStockRequestById(stockRequestID);
                var product      = _ownerInventory.Find(item => item.ProductID == StockRequest.ProductID);

                if (product != null)
                {
                    // validate
                    if (product.StockLevel > StockRequest.Quantity && StockRequest.StockAvailability)
                    {
                        product.StockLevel = product.StockLevel - StockRequest.Quantity;
                        product            = new OwnerInventoryRepository().UpdateOwnerInventory(product.ProductID, product.StockLevel);

                        //add store stock
                        var siRepo         = new StoreInventoryRepository();
                        var storeInventory = siRepo.GetStoreInventoryByStoreIdAndProductId(StockRequest.StoreID, product.ProductID);
                        storeInventory.StockLevel = storeInventory.StockLevel + StockRequest.Quantity;
                        siRepo.UpdateStoreInventory(product.ProductID, StockRequest.StoreID, storeInventory.StockLevel);

                        //delete stock request
                        new StockRequestRepository().DeleteStockRequest(StockRequest.StockRequestID);
                    }
                    else
                    {
                        WidgetError.DisplayError("Insufficient stock to process this request");
                    }
                }
                else
                {
                    WidgetError.DisplayError("Invalid product chosen");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }