/// <summary> /// updates the stock of a product to 20 if the stock is less than 20 /// </summary> /// <param name="productID"></param> public void ProcessOwnerInventory(int productID) { //get the product var product = _ownerInventory.Find(item => item.ProductID == productID); //validate that the product is valid if (product != null) { //check that the stock level is below max if (product.StockLevel < Constants.OWNERMAXSTOCK) { var oiRepo = new OwnerInventoryRepository(); try { //update the product product = oiRepo.UpdateOwnerInventory(product.ProductID, Constants.OWNERMAXSTOCK); } catch (Exception) { throw; } Console.WriteLine(product.ProductID + " stocklevel has been reset to " + product.StockLevel); } else { WidgetError.DisplayError(product.Name + " already has enough stock"); } } else { WidgetError.DisplayError("No such product found"); } }
/// <summary> /// 1. returns a list of all stock requests /// </summary> /// <returns></returns> private void DisplayAllStockRequests() { try { var transaction = new Warehouse(); var requests = transaction.ListAllStockRequests(); DisplayAllStockRequestsView(requests); var input = Console.ReadLine(); int inputParsed; // validate that the input was integer if (CommonFunctions.TryParseInt(input, out inputParsed)) { transaction.ProcessStockRequest(inputParsed); } else { WidgetError.DisplayError("Invalid Input"); } } catch (Exception e) { WidgetError.DisplayError(e.Message); } }
/// <summary> /// Reduces the product stock if sufficient /// </summary> /// <param name="ProductID"></param> /// <param name="Quantity"></param> private void PurchaseProduct(int ProductID, int Quantity) { try { //reset the business object _store = new Transaction.Store().PurchaseItem(_store, ProductID, Quantity); } catch (Exception e) { WidgetError.DisplayError(e.Message); } }
/// <summary> /// display stock requests for the current store /// </summary> public void StockRequestHandler() { try { // set a threshold Console.WriteLine(" "); Console.Write("Enter a threshold for restocking: "); var input = Console.ReadLine(); int inputParsed; if (CommonFunctions.TryParseInt(input, out inputParsed)) { // get items with quantity less thanthreshold var items = _store.DisplayStockThreshold(inputParsed); DisplayStoreInvontory(items); if (items.Count() > 0) { var input2 = Console.ReadLine(); int inputParsed2; if (CommonFunctions.TryParseInt(input2, out inputParsed2)) { var product = items.Find(item => item.ProductID == inputParsed2); // if valid request the stock if (product != null) { _store.RequestStock(Threshold: inputParsed, ProductID: inputParsed2); } else { WidgetError.DisplayError("Not a valid product"); } } else { WidgetError.DisplayError("Invalid input"); } } else { //do nothing } } else { WidgetError.DisplayError("Invalid input"); } } catch (Exception) { throw; } }
/// <summary> /// lists the available stores /// </summary> public void DisplayStoreList() { try { //get the business object that is being interacted with _store = Transaction.Store.DisplayStoreList(); } catch (Exception e) { WidgetError.DisplayError(e.Message); } }
/// <summary> /// owners's main view /// </summary> public override void DisplayUserMenu() { Console.WriteLine("Welcome to Marvelous Magic (Owner)"); Console.WriteLine("=========================="); Console.WriteLine("1. Display All Stock Requests"); Console.WriteLine("2. Display Owner Inventory"); Console.WriteLine("3. Reset Inventory Item Stock"); Console.WriteLine("4. Return to Main Menu"); Console.WriteLine(" "); Console.Write("Enter an option:"); try { var response = Console.ReadLine(); int responseParsed; if (CommonFunctions.TryParseInt(response, out responseParsed)) { switch ((OwnerMenu)responseParsed) { case OwnerMenu.displaystockrequest: DisplayAllStockRequests(); break; case OwnerMenu.displayownerinventory: DisplayOwnerInventory(); break; case OwnerMenu.resetitemstock: ResetInventoryItemStock(); break; case OwnerMenu.back: _state = State.closed; break; default: WidgetError.DisplayError("Invalid Input"); break; } } else { WidgetError.DisplayError("Invalid Input"); } } catch (Exception) { WidgetError.DisplayError("Invalid Input"); } }
/// <summary> /// list the items in store /// </summary> /// <param name="items"></param> public void DisplayStoreInvontory(List <DataObject.StoreInventory> items) { try { var headers = new List <string>(); var content = new List <string>(); var footer = " "; //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); if (items.Count() > 0) { //generate details foreach (var item in items) { 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); } } else { content.Add("No items to display"); } WidgetTable.DisplayTable(headers, content, footer); } catch (Exception e) { WidgetError.DisplayError(e.Message); } }
/// <summary> /// lists the items that are not in store /// </summary> /// <param name="items"></param> public void DisplayNotInInventory(List <DataObject.Product> items) { try { if (items.Count() > 0) { var headers = new List <string>(); var content = new List <string>(); var footer = " "; //generate header string[] header = { "ID", "Product" }; header[0] = header[0].PadRight((int)Padding.id, ' '); header[1] = header[1].PadRight((int)Padding.name, ' '); string headerString = ""; foreach (string str in header) { headerString += str; } headers.Add(headerString); //generate details foreach (var item in items) { string outputRow = item.ProductID.ToString().PadRight((int)Padding.id, ' ') + item.Name.PadRight((int)Padding.name, ' '); content.Add(outputRow); } WidgetTable.DisplayTable(headers, content, footer); } else { WidgetError.DisplayError("No new products available"); } } catch (Exception e) { WidgetError.DisplayError(e.Message); } }
/// <summary> /// 2. lists owner inventory /// </summary> private void DisplayOwnerInventory() { try { var items = new Warehouse().ListAllOwnerInventory(); //generate header Console.WriteLine("Owner Inventory"); Console.WriteLine(" "); DisplayOwnerInventoryView(items); Console.WriteLine(" "); } catch (Exception e) { WidgetError.DisplayError(e.Message); } }
/// <summary> /// customer generic menu /// </summary> public override void DisplayUserMenu() { Console.WriteLine("Welcome to Marvelous Magic (Customer)"); Console.WriteLine("=========================="); Console.WriteLine("1. Display Products"); Console.WriteLine("2. Return to Main Menu"); Console.WriteLine(" "); Console.Write("Enter an option:"); try { var response = Console.ReadLine(); int responseParsed; if (CommonFunctions.TryParseInt(response, out responseParsed)) { switch ((CustomerMenu)responseParsed) { case CustomerMenu.displayproducts: HandleProductPurchase(); break; case CustomerMenu.back: _state = State.closed; break; default: WidgetError.DisplayError("Invalid Input"); break; } } else { WidgetError.DisplayError("Invalid Input"); } } catch (Exception e) { WidgetError.DisplayError(e.Message); } }
/// <summary> /// handler for the purchase product workflow /// </summary> private void HandleProductPurchase() { try { //reset the business object int?ProductID = DisplayProducts(); //first input validation: product id if (ProductID != null) { Console.Write("Enter quantity to purchase: "); var input = Console.ReadLine(); int inputParsed; try { // second inut validation, ask for the quantity if (CommonFunctions.TryParseInt(input, out inputParsed)) { // TODO validate the quantity PurchaseProduct(ProductID: (int)ProductID, Quantity: inputParsed); } else { WidgetError.DisplayError("Invalid input"); } } catch (Exception) { throw; } } else { // do nothing, the error msg has already been shown, back to user menu } } catch (Exception e) { WidgetError.DisplayError(e.Message); } }
/// <summary> /// Adds 1 unit of an item that is not in the inventory /// Quantity of item is set to zero /// </summary> public void AddNewInventoryItem() { try { // list stuff thats not in var notInInventory = _store.ListNotInInventory(); DisplayNotInInventory(notInInventory); if (notInInventory.Count() > 0) { // add to list var input = Console.ReadLine(); int inputParsed; if (CommonFunctions.TryParseInt(input, out inputParsed)) { if (notInInventory.Any(item => item.ProductID == inputParsed)) { _store.AddToInventory(ProductID: inputParsed); } else { WidgetError.DisplayError("Invalid Input"); } } else { WidgetError.DisplayError("Invalid Input"); } } else { // do nothing } } catch (Exception e) { WidgetError.DisplayError(e.Message); } }
/// <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; } }
/// <summary> /// 3. if item has less than 20 stock restock to 20 /// </summary> private void ResetInventoryItemStock() { try { var transaction = new Warehouse(); var items = transaction.ListAllOwnerInventory(); //generate header Console.WriteLine("Reset Stock"); Console.WriteLine("Product stock will be reset to " + Constants.OWNERMAXSTOCK); Console.WriteLine(" "); //display the table DisplayOwnerInventoryView(items); Console.WriteLine(" "); Console.Write("Enter product ID to reset:"); var input = Console.ReadLine(); int inputParsed; // validate that the input was integer if (CommonFunctions.TryParseInt(input, out inputParsed)) { transaction.ProcessOwnerInventory(inputParsed); } else { WidgetError.DisplayError("Invalid Input"); } } catch (Exception e) { WidgetError.DisplayError(e.Message); } }