コード例 #1
0
        private void initEntityless(MarketOfferModel offer, bool deleteable, bool showDetails, WebServices.structs.OfferCost cost)
        {
            ProductTypeEnum productType = (ProductTypeEnum)offer.ProductID;

            CurrencyID  = offer.CurrencyID;
            OfferID     = offer.OfferID;
            ProductName = productType.ToHumanReadable().FirstUpper();
            Quality     = offer.Quality;

            Price            = cost.BasePrice + cost.VatCost;
            Amount           = offer.Amount;
            IsPostedOnMarket = offer.CountryID > 0;

            if (IsPostedOnMarket)
            {
                MarketCountryName = offer.CompanyCountryName;
            }

            CompanyID     = offer.Company.EntityID;
            CompanyName   = offer.Company.Name;
            ProductImage  = Images.GetProductImage(productType).VM;
            ProductAvatar = getProductAvatar(offer);

            var currency = Persistent.Currencies.GetById(offer.CurrencyID);

            PriceSymbol = currency.Symbol;

            Deleteable  = deleteable;
            ShowDetails = showDetails;

            IProductService productService = DependencyResolver.Current.GetService <IProductService>();

            Tax = (int)(productService.GetAllTaxesForProduct(offer.ProductID, offer.CompanyCountryID, null).VAT * 100m);
        }
コード例 #2
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);
        }
コード例 #3
0
        public MarketOfferViewModel(Entity entity, MarketOfferModel offer, IMarketService marketService, bool deleteable = false, bool showDetails = false)
        {
            var cost = marketService.GetOfferCost(offer, entity, 1);

            initEntityless(offer, deleteable, showDetails, cost);

            initSelf(offer, entity, marketService, cost);
        }
コード例 #4
0
        private ImageViewModel getProductAvatar(MarketOfferModel offer)
        {
            if (offer.Company.ImgUrl == null)
            {
                return(new ImageViewModel(Images.GetProductImageHighRes((ProductTypeEnum)offer.ProductID)));
            }

            return(new ImageViewModel(offer.Company.ImgUrl));
        }
コード例 #5
0
        private void initSelf(MarketOfferModel offer, Entity entity, IMarketService marketService, WebServices.structs.OfferCost cost)
        {
            CanBuy = marketService.CanBuy(offer.OfferID, entity, offer.Company).isSuccess;

            if ((EntityTypeEnum)entity.EntityTypeID != EntityTypeEnum.Citizen && (EntityTypeEnum)entity.EntityTypeID != EntityTypeEnum.Newspaper)
            {
                FuelPrice = cost.FuelCost;
            }

            if (marketService.CanUseFuel(entity))
            {
                FuelPricePer = marketService.GetFuelCostForOffer(offer, entity);

                if (FuelPricePer.HasValue)
                {
                    FuelPricePer = Math.Round(FuelPricePer.Value, 2);
                }
            }
        }
コード例 #6
0
        public decimal?GetFuelCostForOffer(MarketOfferModel offer, Entity buyer)
        {
            var entityType = (EntityTypeEnum)buyer.EntityTypeID;

            if (entityType == EntityTypeEnum.Citizen || entityType == EntityTypeEnum.Newspaper)
            {
                return(null);
            }

            var buyerRegion = buyer.GetCurrentRegion();

            var companyRegion  = Persistent.Regions.GetById(offer.CompanyRegionID);
            var companyCountry = Persistent.Countries.GetById(offer.CompanyCountryID);

            var path = regionService.GetPathBetweenRegions(buyerRegion, companyRegion, new TradeRegionSelector(companyCountry, buyer.GetCurrentCountry(), embargoRepository));

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

            return(GetFuelCostForOffer(offer, path, 1));
        }
コード例 #7
0
 private decimal GetFuelCostForOffer(MarketOfferModel offer, Path path, int amount)
 {
     return(productService.GetFuelCostForTranposrt(path, (ProductTypeEnum)offer.ProductID, offer.Quality, amount));
 }