private static float CheckProducts(Dictionary <string, int> products, OrdinaryShop ordinaryShop) { float checkAmount = 0; foreach (var product in products) { checkAmount += CheckOrdinaryProduct(product, ordinaryShop); } return(checkAmount); }
public static float Buy(Dictionary <string, int> products, OrdinaryShop ordinaryShop) { float checkAmount = 0; foreach (var product in products) { checkAmount += BuyOrdinaryProduct(product, ordinaryShop); } return(checkAmount); }
private static bool TryCheckProducts(Dictionary <string, int> products, OrdinaryShop ordinaryShop) { bool res = true; try { CheckProducts(products, ordinaryShop); } catch { res = false; } return(res); }
private static bool TryToBuyProduct(KeyValuePair <string, int> product, OrdinaryShop ordinaryShop) { bool result = false; var productId = product.Key; var productAmount = product.Value; if (ordinaryShop.ManagerOfShopProducts.Build().TrackedProducts.ContainsKey(productId)) { if (ordinaryShop.ManagerOfShopProducts.Build().TrackedProducts[productId].Count - productAmount >= 0) { result = true; } } return(result); }
public static string Find(float amount, OrdinaryShop ordinaryShop) { string resultProducts = ""; foreach (var product in ordinaryShop.ManagerOfShopProducts.Build(). TrackedProducts.Values) { if (product.Price < amount) { var count = HowManyProducts(product.Price, amount); resultProducts += MakeStr(product, count); } } return(resultProducts); }
private static float CheckOrdinaryProduct(KeyValuePair <string, int> product, OrdinaryShop ordinaryShop) { float checkAmount = 0; if (TryToCheckOrdinaryProduct(product, ordinaryShop)) { var productId = product.Key; var productAmount = product.Value; checkAmount += ordinaryShop.ManagerOfShopProducts.Build() .TrackedProducts[productId].Price * productAmount; } else { throw new BuyException(); } return(checkAmount); }
public static string Find(Dictionary <string, int> products, ShopManager manager) { float minCheck = float.MaxValue; Shop resultOrdinaryShop = new OrdinaryShop(""); foreach (var shop in manager.TrackedShops.Values) { if (TryCheckProducts(products, shop)) { var checkFromEachShop = CheckProducts(products, shop); if (checkFromEachShop < minCheck) { minCheck = checkFromEachShop; resultOrdinaryShop = shop; } } } string result = resultOrdinaryShop.Name ?? "No shop"; return(result); }
public OrdinaryShopProductPriceBuilder(OrdinaryShop ordinaryShop) : base(ordinaryShop) { }
public OrdinaryShopProductCountBuilder(OrdinaryShop ordinaryShop) : base(ordinaryShop) { }
private static bool TryId(OrdinaryShop ordinaryShop, string productId) { return(ordinaryShop.ManagerOfShopProducts.Build().TrackedProducts.ContainsKey(productId)); }
public FindProductsForSpecifyAmount(OrdinaryShop ordinaryShop) : base(ordinaryShop) { }
protected OrdinaryShopBuilder(OrdinaryShop ordinaryShop) => OrdinaryShop = ordinaryShop;
public BuyProducts(OrdinaryShop ordinaryShop) : base(ordinaryShop) { OrdinaryShop = ordinaryShop; }