Ejemplo n.º 1
0
        public async Task <IActionResult> SendRakeItemToBot([FromBody] SendRakeItemsModel sendRakeItemsModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(sendRakeItemsModel));
            }

            var dict = CreateOfferWithBotAndItems(sendRakeItemsModel);

            var botLoginDetails = await _steamService.GetBotLoginInfo(new GetBotLoginInfoRequest { Bot = new Bot {
                                                                                                       BotType = botType.Opskins
                                                                                                   } });

            if (botLoginDetails.DataCase == GetBotLoginInfoResponse.DataOneofCase.Error)
            {
                return new ObjectResult($"Botlogin request returned error: {botLoginDetails.Error.Message}")
                       {
                           StatusCode = 502
                       }
            }
            ;

            var opskinBot = botLoginDetails.BotInfo;

            var listRespoinse    = new List <MakeOfferResponse>();
            var makeOfferRequset = new List <MakeOfferRequest>();

            foreach (var kvp in dict)
            {
                var bot = await _repoServiceFactory.BotRepoService.FindAsync(kvp.Key);

                makeOfferRequset.Add(new MakeOfferRequest
                {
                    User = new User
                    {
                        SteamId   = opskinBot.Bot.SteamId,
                        TradeLink = opskinBot.TradeLink,
                    },
                    BotName   = bot.Name,
                    SendItems = true,
                    Message   = "sendSellRakeOffer",
                    Items     = { kvp.Value }
                });
            }

            foreach (var offerRequest in makeOfferRequset)
            {
                MakeOfferResponse res;
                try
                {
                    res = await _steamService.MakeOfferAsync(offerRequest);
                }
                catch (Exception e)
                {
                    e.Data.Add("MakeOfferRequest", offerRequest);
                    throw;
                }

                listRespoinse.Add(res);
            }

            return(Ok(listRespoinse));
        }