Beispiel #1
0
 public ShopPrice(ShopPriceEntity entity)
 {
     Id         = entity.Id;
     PeriodType = (ItemPeriodType)entity.PeriodType;
     Period     = (ushort)entity.Period;
     Price      = entity.Price;
     CanRefund  = entity.IsRefundable;
     Durability = entity.Durability;
     IsEnabled  = entity.IsEnabled;
 }
        public async Task NewPrice(ShopPriceGroup priceGroup)
        {
            using (var db = _databaseService.Open <GameContext>())
            {
                var priceEntity = new ShopPriceEntity
                {
                    PriceGroupId = priceGroup.Id
                };
                db.Prices.Add(priceEntity);
                await db.SaveChangesAsync();

                priceGroup.Prices.Add(new ShopPrice(priceGroup, priceEntity));
            }
        }
Beispiel #3
0
        public ShopPrice(ShopPriceGroup priceGroup, ShopPriceEntity entity)
        {
            Id           = entity.Id;
            PriceGroup   = priceGroup;
            PeriodType   = new ReactiveProperty <ItemPeriodType>((ItemPeriodType)entity.PeriodType);
            Period       = new ReactiveProperty <uint>((uint)entity.Period);
            Price        = new ReactiveProperty <int>(entity.Price);
            IsRefundable = new ReactiveProperty <bool>(entity.IsRefundable);
            Durability   = new ReactiveProperty <int>(entity.Durability);
            IsEnabled    = new ReactiveProperty <bool>(entity.IsEnabled);

            this.WhenAnyValue(x => x.PeriodType.Value)
            .Select(x =>
            {
                bool hasDurability;
                switch (x)
                {
                case ItemPeriodType.Hours:
                case ItemPeriodType.Days:
                case ItemPeriodType.Units:
                    hasDurability = false;
                    break;

                default:
                    hasDurability = true;
                    break;
                }

                if (hasDurability && Durability.Value < 0)
                {
                    return(0);
                }

                if (!hasDurability)
                {
                    return(-1);
                }

                return(Durability.Value);
            })
            .BindTo(this, x => x.Durability.Value);

            this.WhenAnyValue(x => x.PeriodType.Value)
            .Select(x =>
            {
                bool hasPeriod;
                switch (x)
                {
                case ItemPeriodType.Days:
                case ItemPeriodType.Hours:
                    hasPeriod = true;
                    break;

                default:
                    hasPeriod = false;
                    break;
                }

                return(hasPeriod ? Period.Value : 0);
            })
            .BindTo(this, x => x.Period.Value);
        }