public MarketItemCollection GetItems(int offset, int size)
        {
            var collection      = new MarketItemCollection();
            var marketItemCount = gameData.GetMarketItemCount();
            var items           = gameData.GetMarketItems(offset, size);

            collection.Offset = offset;
            collection.Total  = marketItemCount;
            collection.AddRange(
                items.Select(x =>
            {
                var character     = gameData.GetCharacter(x.SellerCharacterId);
                var user          = gameData.GetUser(character.UserId);
                var item          = DataMapper.Map <Models.MarketItem, DataModels.MarketItem>(x);
                item.SellerUserId = user.UserId;
                return(item);
            }));

            return(collection);
        }
        public async Task <MarketItemCollection> GetItemsAsync(
            int offset, int size)
        {
            using (var db = dbProvider.Get())
            {
                var collection      = new MarketItemCollection();
                var marketItemCount = await db.MarketItem.CountAsync();

                var items = await db.MarketItem.Include(x => x.SellerCharacter).ThenInclude(x => x.User).Skip(offset).Take(size).ToListAsync();

                collection.Offset = offset;
                collection.Total  = marketItemCount;
                collection.AddRange(
                    items.Select(x =>
                {
                    var item          = DataMapper.Map <Models.MarketItem, DataModels.MarketItem>(x);
                    item.SellerUserId = x.SellerCharacter.User.UserId;
                    return(item);
                }));

                return(collection);
            }
        }
Esempio n. 3
0
        public MarketItemCollection GetItems(int offset, int size)
        {
            try
            {
                var collection      = new MarketItemCollection();
                var marketItemCount = gameData.GetMarketItemCount();
                var items           = gameData.GetMarketItems(offset, size);

                collection.Offset = offset;
                collection.Total  = marketItemCount;
                collection.AddRange(
                    items.Select(x =>
                {
                    var character = gameData.GetCharacter(x.SellerCharacterId);
                    if (character == null)
                    {
                        return(null);
                    }
                    var user = gameData.GetUser(character.UserId);
                    if (user == null)
                    {
                        return(null);
                    }
                    var item          = DataMapper.Map <Models.MarketItem, DataModels.MarketItem>(x);
                    item.SellerUserId = user.UserId;
                    return(item);
                })
                    .Where(x => x != null));

                return(collection);
            }
            catch (Exception exc)
            {
                logger.LogError(exc.ToString());
                return(null);
            }
        }