public void DisplayUserBuysProduct(BuyTransaction transaction) { Console.Clear(); Console.WriteLine("Buy transation:"); Console.WriteLine(transaction.ToString()); Console.ReadKey(); }
public void ParsePurchase(string command) { string[] split = command.Split(new[] { ' ' }); User u = User.FindBy("Username", split[0]); try { int pid; Product p = null; if (u == null) { throw new UserNotFoundException(split[0]); } if (split.Length == 1) { UI.DisplayUserInfo(u); } else if (split.Length == 2) { if (int.TryParse(split[2], out pid)) { p = Product.Find(pid); } BuyTransaction purchase = new BuyTransaction(user: u, product: p); purchase.Execute(); } else { if (int.TryParse(split[2], out pid)) { p = Product.Find(pid); } int count = int.Parse(split[1]); if (count < 1) { throw new ProductCountInvalidException(count); } for (int i = 0; i < count; i++) { BuyTransaction purchase = new BuyTransaction(user: u, product: p); purchase.Execute(); } UI.DisplayUserBuysProduct(product: p, user: u, count: count); } } catch (InsufficientCreditsException e) { UI.DisplayInsufficientCash(e.User); } catch (UserNotFoundException e) { UI.DisplayUserNotFound(e.Username); } catch (ProductInactiveException e) { UI.DisplayProductInactive(e.Product); } catch (ProductCountInvalidException e) { UI.DisplayGeneralError($"You cannot buy {e.Count} of those."); } catch (NullReferenceException) { UI.DisplayProductNotFound(split[split.Length == 2 ? 1 : 2]); // Ternary for the if above.. } }
public void DisplayUserBuysProduct(BuyTransaction transaction) { Console.WriteLine(transaction); if (transaction.User.Balance < 50) { DisplayBalanceBelowFifty(); } }
public void DisplayUserBuysProduct(int count, BuyTransaction transaction) { Console.Clear(); Console.WriteLine($"Buy transaction. nr {count}"); Console.WriteLine(transaction.ToString()); Console.ReadKey(); }
private void MultibuyItem(string[] paramaters) { string userName = paramaters[0]; string countstr = paramaters[1]; string id = paramaters[2]; if (countstr.All(c => char.IsDigit(c))) { int count = int.Parse(countstr); if (id.All(c => char.IsDigit(c))) { User user = _stregsystem.GetUserByUsername(userName); if (user != null) { Product product = _stregsystem.GetProductByID(int.Parse(id)); if (product != null) { try { if (product.IsActive) { for (int i = 0; i < count; i++) { BuyTransaction bt = _stregsystem.BuyProduct(user, product); _ui.DisplayUserBuysProduct(i + 1, bt); } } else { _ui.DisplayProductNotFound(id); } } catch (InsufficentCreditsException) { _ui.DisplayInsufficientCash(user, product); } } else { _ui.DisplayProductNotFound(id); } } else { _ui.DisplayUserNotFound(userName); } } else { _ui.DisplayGeneralError($"Product id was not a number, you wrote: {id}"); } } else { _ui.DisplayGeneralError($"The count was not a number, you wrote: {countstr}"); } }
// A user buying a product (a transaction is made) public BuyTransaction BuyProduct(User user, Product product) { BuyTransaction buytransaction = new BuyTransaction(user, DateTime.Now, product); ExecuteTransaction(buytransaction); _writingfiles.WritingUsersFile(buytransaction); user.NumberOfTransactions++; return(buytransaction); }
public BuyTransaction BuyProduct(User user, Product product) { BuyTransaction buyTrans = new BuyTransaction(user, product.Price, product); _transactionList.Add(buyTrans); if (user.Balance < 50) { OnUserBalanceWarning(user, user.Balance); } LogTransaction(buyTrans.ToString()); return(buyTrans); }
/// <summary> /// Takes a user and a product and returns a BuyTransaction /// </summary> /// <param name="user"></param> /// <param name="product"></param> /// <returns></returns> public BuyTransaction BuyProduct(User user, Product product) { Transaction transaction = new BuyTransaction(_logFile.LinesInFile + 1, user, product); ExecuteTransaction(transaction); if (user.Balance < 50) { UserBalanceWarning(user, user.Balance); } return(transaction as BuyTransaction); }
// The transaction is handled here public void Receipt(string username, int productID, int quantity) { User user; Product product; // Checks whether a username as the given, exists if (_stregsystem.GetUserByUsername(username) != null) { user = _stregsystem.GetUserByUsername(username); // Checks whether a product ID as the given, exists if (_stregsystem.GetProductByID(productID) != null) { product = _stregsystem.GetProductByID(productID); // Checks whether the product is active if (product.Active) { // Checks if the user can afford the product and the quantity of it, and if not, if the product can be bought on credit if (product.Price * quantity <= user.Balance || product.CanBeBoughtOnCredit) { BuyTransaction purchase = null; for (int i = 0; i < quantity; i++) { purchase = _stregsystem.BuyProduct(user, product); } ConsoleReceipt receipt = new ConsoleReceipt(purchase, quantity, false); receipt.Print(); } else { _ui.DisplayInsufficientCash(user, product); } } else { _ui.DisplayProductNotActive($"{product.ID}"); } } else { _ui.DisplayProductNotFound(); } } else { _ui.DisplayUserNotFound(username); } }
private void BuyOneItem(string[] parameters) { string userName = parameters[0]; string id = parameters[1]; if (id.All(c => char.IsDigit(c))) { User user = _stregsystem.GetUserByUsername(userName); if (user != null) { Product product = _stregsystem.GetProductByID(int.Parse(id)); if (product != null) { try { if (product.IsActive) { BuyTransaction bt = _stregsystem.BuyProduct(user, product); _ui.DisplayUserBuysProduct(bt); } else { _ui.DisplayProductNotFound(id); } } catch (InsufficentCreditsException) { _ui.DisplayInsufficientCash(user, product); } catch (Exception message) { _ui.DisplayGeneralError(message.Message); } } else { _ui.DisplayProductNotFound(id); } } else { _ui.DisplayUserNotFound(userName); } } else { _ui.DisplayGeneralError($"Product id was not a number, you wrote: {id}"); } }
public int BuyProduct(User user, Product product) { try { BuyTransaction buyTransaction = new BuyTransaction(user, product.Price); TrackTransaction(buyTransaction); Logger.WriteMessage(buyTransaction.ToString() + " Product Name & ID: " + product.Name + product.Id); } catch (InsufficientCreditsException e) { Logger.WriteMessage("ID:" + user.Id + " There were not enough credits on the user's account"); return(1); } // Trigger event to notify user if (user.Money <= 2000) { PushNotification?.Invoke(this, new UserBalanceNotificationArgs(user.Money)); } return(0); }
/// <summary> /// Displays a succesfull transaction and the amount of products /// </summary> /// <param name="count"></param> /// <param name="transaction"></param> public void DisplayUserBuysProduct(int count, BuyTransaction transaction) { Console.WriteLine($"---\n{transaction} Amount: {count}\n---"); }
/// <summary> /// Displays a succesfull transaction /// </summary> /// <param name="transaction"></param> public void DisplayUserBuysProduct(BuyTransaction transaction) { Console.WriteLine($"---\n{transaction.TransactionUser.UserName} bought {transaction.ProductToBuy.Name} for {transaction.Amount} dkr\n---"); }
public BuyTransaction BuyProduct(User user, Product product, List <User> UserList, List <Product> ProductList) { BuyTransaction Transaction = new BuyTransaction(user, product, DateTime.Now, product.Price, UserList); return(Transaction); }
public void DisplayUserBuysProduct(BuyTransaction transaction) { Console.WriteLine($"{transaction.user.Firstname} bought a product\nUser balance: {transaction.user.Balance}"); }
public ConsoleReceipt(BuyTransaction transaction, int amount, bool isQuickbuy) { this.Transaction = transaction; this.Amount = amount; this.IsQuickbuy = isQuickbuy; }