private async Task<List<DatabaseModel.Item>> GetUsersItemsAndValidateOfferData ( List<Item> items, DatabaseModel.User user ) { var itemNames = items .Select(item => item.MarketHashName) .GroupBy(name => name) .Select(grp => grp.First()) .ToList(); var itemDescriptions = await _repoServiceFactory.ItemDescriptionRepoService.FindAsync(itemNames); if (itemDescriptions.Count != itemNames.Count) throw new ItemDescriptionNotInDatabase("We does not have the item description for atleast one item"); var settings = await _repoServiceFactory.SettingRepoService.GetSettingsAsync(); if (itemDescriptions.Any(itemDesc => itemDesc.Value < settings.ItemValueLimit)) throw new ItemInOfferNotMatchingLowestValueRuleExecption( $"Atleast one item in the offer does not match the value limit. All items need a value more than {settings.ItemValueLimit}."); var usersItems = await _repoServiceFactory.ItemRepoService.FindAsync(user); if (usersItems.Count + items.Count > settings.InventoryLimit) throw new InventoryLimitExceeded( $"Accepting this offer would put your inventory on {usersItems.Count + items.Count} item, the limit is {settings.InventoryLimit}"); return usersItems; }
private MakeOfferRequest MakeOfferRequest(DatabaseModel.User user, DatabaseModel.Bot bot, IEnumerable<Item> itemsInOffer, bool isDeposit) { var request = new MakeOfferRequest { SendItems = !isDeposit, User = new User { SteamId = user.SteamId, TradeLink = user.TradeLink }, BotName = bot.Name, Items = {itemsInOffer} }; return request; }
private async Task AddPrepareWithdrawOfferToDatabase ( List<Item> itemsInOffer, DatabaseModel.Bot bot, DatabaseModel.User user, MakeOfferResponse offerResponse ) { var offerTransaction = await _offerService.PrepareWithdrawlSteamOffer(itemsInOffer.ToList(), bot, user); if (offerResponse.DataCase == MakeOfferResponse.DataOneofCase.Error || offerResponse.DataCase == MakeOfferResponse.DataOneofCase.None) { await _repoServiceFactory.ItemInOfferTransactionRepoService.Remove(offerTransaction.Id); await _repoServiceFactory.OfferTranascrionRepoService.Remove(offerTransaction.Id); return; } await _repoServiceFactory.OfferTranascrionRepoService.AddSteamIdToOffer(offerTransaction.Id, offerResponse.Offer.SteamOffer.Id); }