public Tuple <int, int> PurchaseProducts(int userId, string cardNumber, string month, string year, string holder, string ccv, string id, string name, string address, string city, string country, string zip) { int collection, delivery; int multiCartId = UserManagment.AllRegisteredUsers.GetInstance().GetUser(userId).GetMultiCart(); RemoveProductsFromStore(GetMultiCart(multiCartId)); try { if (!CheckSellingPolicies(userId)) { throw new ErrorMessageException("Not All selling policies pass"); } } catch (ErrorMessageException e) { ReturnProductsToStore(GetMultiCart(multiCartId)); throw e; } int sum = SumOfCartPrice(userId); collection = moneyCollectionSystem.CollectFromAccount(cardNumber, month, year, holder, ccv, id); delivery = deliverySystem.Deliver(name, address, city, country, zip); if (collection == -1 || delivery == -1) { ReturnProductsToStore(GetMultiCart(multiCartId)); return(new Tuple <int, int>(-1, -1)); } try { MultiCart multicart = System.GetInstance().GetMultiCart(multiCartId); for (int i = 0; i < multicart.GetCarts().Count; i++) { string message = "the products in store" + multicart.GetCarts().ElementAt(i).GetStore().GetName() + ":\n"; for (int j = 0; j < multicart.GetCarts().ElementAt(i).GetProducts().Count; j++) { message = message + " id:" + multicart.GetCarts().ElementAt(i).GetProducts().ElementAt(j).Key.GetId() + ",name:" + multicart.GetCarts().ElementAt(i).GetProducts().ElementAt(j).Key.GetName() + "\n"; } message += "were sold\n"; for (int k = 0; k < UserManagment.AllRegisteredUsers.GetInstance().GetAllUserNames().Count; k++) { if (UserManagment.AllRegisteredUsers.GetInstance().GetUserInfo(UserManagment.AllRegisteredUsers.GetInstance().GetAllUserNames().ElementAt(k)).GetOwner(multicart.GetCarts().ElementAt(i).GetStore().GetName()) != null) { Notifications.Notification.GetInstance().SendMessageToUser(UserManagment.AllRegisteredUsers.GetInstance().GetAllUserNames().ElementAt(k), message); } if (UserManagment.AllRegisteredUsers.GetInstance().GetUserInfo(UserManagment.AllRegisteredUsers.GetInstance().GetAllUserNames().ElementAt(k)).GetManager(multicart.GetCarts().ElementAt(i).GetStore().GetName()) != null) { Notifications.Notification.GetInstance().SendMessageToUser(UserManagment.AllRegisteredUsers.GetInstance().GetAllUserNames().ElementAt(k), message); } } } } catch (Exception) { } ResetMultiCart(UserManagment.AllRegisteredUsers.GetInstance().GetUser(userId).GetMultiCart()); return(new Tuple <int, int>(collection, delivery)); }
public bool AddProductsToCart(int productId, int amount) { ProductAmountCart product = null; foreach (ProductAmountInventory productAmount in System.GetInstance().GetStore(storeName).GetInventory()) { if (productAmount.productId.Equals(productId)) { product = new ProductAmountCart(this, productAmount.product, amount); break; } } if (product == null) { throw new ErrorMessageException("Product Id dosent exist in store"); } if ((System.GetInstance().GetStore(storeName).GetProductAmount(product.product).amount < amount) || (CheckExsit(productId) && (GetProducts()[product.product] + amount > System.GetInstance().GetStore(storeName).GetProductAmount(product.product).amount))) { throw new ErrorMessageException("Product has less than the given amount"); } if (CheckExsit(productId)) { foreach (ProductAmountCart p in productAmount) { if (p.product.Id.Equals(productId)) { p.amount += amount; } } } else { productAmount.AddLast(product); } return(true); }
public Store GetStore() { return(System.GetInstance().GetStore(storeName)); }