Exemplo n.º 1
0
        public OfferCost GetOfferCost(MarketOfferModel offer, Entity buyer, int amount)
        {
            OfferCost cost          = new OfferCost();
            var       sellerRegion  = Persistent.Regions.GetById(offer.CompanyRegionID);
            var       sellerCountry = Persistent.Countries.GetById(offer.CompanyCountryID);

            if (CanUseFuel(buyer))
            {
                var buyerRegion = buyer.GetCurrentRegion();
                var path        = regionService.GetPathBetweenRegions(buyerRegion, sellerRegion, new TradeRegionSelector(sellerCountry, buyer.GetCurrentCountry(), embargoRepository));

                if (path == null)
                {
                    return(null);
                }

                cost.FuelCost = GetFuelCostForOffer(offer, path, amount);
            }

            cost.Set(CalculateProductCost(amount, offer.Price, offer.CompanyCountryID, buyer.GetCurrentCountry().ID, (ProductTypeEnum)offer.ProductID));
            cost.CurrencyID = offer.CurrencyID;



            cost.FuelCost = Math.Round(cost.FuelCost, 2);

            return(cost);
        }
Exemplo n.º 2
0
        public OfferCost GetOfferCost(MarketOffer offer, int amount, Region destinationRegion, bool useFuel)
        {
            var destinationCountry = destinationRegion.Country;

            OfferCost cost         = new OfferCost();
            var       sellerRegion = offer.Company.Entity.GetCurrentRegion();


            if (useFuel)
            {
                var buyerRegion = destinationRegion;
                var path        = regionService.GetPathBetweenRegions(buyerRegion, sellerRegion, new TradeRegionSelector(offer.Company.Region.Country, destinationCountry, embargoRepository));

                if (path == null)
                {
                    return(null);
                }

                cost.FuelCost = GetFuelCostForOffer(offer, path, amount);
            }

            cost.Set(CalculateProductCost(amount, offer.Price, offer.Company.Region.CountryID, destinationCountry.ID, (ProductTypeEnum)offer.ProductID));
            cost.CurrencyID = offer.CurrencyID;



            cost.FuelCost = Math.Round(cost.FuelCost, 2);

            return(cost);
        }