Ejemplo n.º 1
0
        public void AddMetaData(MetaData metaData)
        {
            if (metaData != null)
            {
                if (metaData.Catalog != null)
                {
                    Catalogs.AddRange(metaData.Catalog);
                }

                if (metaData.PriceGroups != null)
                {
                    PriceGroups.AddRange(metaData.PriceGroups);
                }

                if (metaData.NomenclatureGroups != null)
                {
                    NomenclatureGroups.AddRange(metaData.NomenclatureGroups);
                }

                if (metaData.Brands != null)
                {
                    Brands.AddRange(metaData.Brands);
                }

                if (metaData.TypesOfPrices != null)
                {
                    TypesOfPrices.AddRange(metaData.TypesOfPrices);
                }

                if (metaData.CommodityDirections != null)
                {
                    CommodityDirections.AddRange(metaData.CommodityDirections);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task Delete(ShopPriceGroup priceGroup)
        {
            using (var db = _databaseService.Open <GameContext>())
                await db.PriceGroups.Where(x => x.Id == priceGroup.Id).DeleteAsync();

            PriceGroups.Remove(priceGroup);
        }
Ejemplo n.º 3
0
        public async Task LoadFromDatabase()
        {
            PriceGroups.Clear();
            EffectGroups.Clear();
            Items.Clear();
            using (var db = _databaseService.Open <GameContext>())
            {
                var priceGroupEntities = await db.PriceGroups.Include(x => x.ShopPrices).ToArrayAsync();

                var priceGroups         = priceGroupEntities.Select(x => new ShopPriceGroup(x));
                var effectGroupEntities = await db.EffectGroups.Include(x => x.ShopEffects).ToArrayAsync();

                var effectGroups = effectGroupEntities.Select(x => new ShopEffectGroup(x));

                // I know this is ugly but somehow I cant get decent performance with joins 🤔
                IEnumerable <ShopItemEntity> itemEntities = await db.Items.ToArrayAsync();

                var itemInfoEntities = await db.ItemInfos.ToArrayAsync();

                itemEntities = itemEntities.GroupJoin(itemInfoEntities, x => x.Id, x => x.ShopItemId, (item, itemInfos) =>
                {
                    item.ItemInfos = itemInfos.ToList();
                    return(item);
                });

                RxApp.MainThreadScheduler.Schedule(() =>
                {
                    PriceGroups.AddRange(priceGroups);
                    EffectGroups.AddRange(effectGroups);
                    Items.AddRange(itemEntities.Select(x => new ShopItem(x)));
                });
            }
        }
Ejemplo n.º 4
0
        public async Task NewItemInfo(ShopItem item)
        {
            using (var db = _databaseService.Open <GameContext>())
            {
                var itemInfoEntity = new ShopItemInfoEntity
                {
                    ShopItemId    = item.ItemNumber,
                    EffectGroupId = EffectGroups.First().Id,
                    PriceGroupId  = PriceGroups.First().Id
                };
                db.ItemInfos.Add(itemInfoEntity);
                await db.SaveChangesAsync();

                item.ItemInfos.Add(new ShopItemInfo(item, itemInfoEntity));
            }
        }
Ejemplo n.º 5
0
        public async Task NewPriceGroup()
        {
            using (var db = _databaseService.Open <GameContext>())
            {
                var priceGroupEntity = new ShopPriceGroupEntity
                {
                    Name      = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(),
                    PriceType = (byte)ItemPriceType.None
                };

                db.PriceGroups.Add(priceGroupEntity);
                await db.SaveChangesAsync();

                PriceGroups.Add(new ShopPriceGroup(priceGroupEntity));
            }
        }