Beispiel #1
0
        public virtual Result <bool> CanSellToVendor(ICustomer <T> customer, IVendorProduct <T> product, int amount = 1)
        {
            if (product.sellPrice.Length == 0)
            {
                return(new Result <bool>(false, Errors.VendorProductHasNoPrice));
            }

            //
            // Vendor
            //
            var canAdd = vendorCollection.CanAdd(product, amount);

            if (canAdd.result == false)
            {
                return(canAdd);
            }

            // Vendor doesn't have enough currency
            foreach (var c in product.sellPrice)
            {
                var canRemoveCurrency = vendorCurrencies.CanRemove(c.currency, c.amount * amount * config.sellToVendorPriceMultiplier);
                if (canRemoveCurrency.result == false)
                {
                    return(canRemoveCurrency);
                }
            }


            //
            // Customer
            //
            var canRemoveCustomer = customer.CanRemoveItem(product.item, amount);

            if (canRemoveCustomer.result == false)
            {
                return(canRemoveCustomer);
            }

            foreach (var c in product.sellPrice)
            {
                var canAddCurrency = customer.CanAddCurrency(c.currency, c.amount * amount * config.sellToVendorPriceMultiplier);
                if (canAddCurrency.result == false)
                {
                    return(canAddCurrency);
                }
            }

            return(true);
        }