예제 #1
0
        public async Task <ActionResult <GenericResponse> > GamesToRedeemInBackgroundPost(string botNames, [FromBody] BotGamesToRedeemInBackgroundRequest request)
        {
            if (string.IsNullOrEmpty(botNames) || (request == null))
            {
                ASF.ArchiLogger.LogNullError(nameof(botNames) + " || " + nameof(request));

                return(BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(botNames) + " || " + nameof(request)))));
            }

            if (request.GamesToRedeemInBackground.Count == 0)
            {
                return(BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request.GamesToRedeemInBackground)))));
            }

            HashSet <Bot> bots = Bot.GetBots(botNames);

            if ((bots == null) || (bots.Count == 0))
            {
                return(BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botNames))));
            }

            IOrderedDictionary validGamesToRedeemInBackground = Bot.ValidateGamesToRedeemInBackground(request.GamesToRedeemInBackground);

            if ((validGamesToRedeemInBackground == null) || (validGamesToRedeemInBackground.Count == 0))
            {
                return(BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(validGamesToRedeemInBackground)))));
            }

            await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.AddGamesToRedeemInBackground(validGamesToRedeemInBackground)))).ConfigureAwait(false);

            Dictionary <string, IOrderedDictionary> result = new Dictionary <string, IOrderedDictionary>(bots.Count, Bot.BotsComparer);

            foreach (Bot bot in bots)
            {
                result[bot.BotName] = validGamesToRedeemInBackground;
            }

            return(Ok(new GenericResponse <IReadOnlyDictionary <string, IOrderedDictionary> >(result)));
        }
예제 #2
0
        public async Task <ActionResult <GenericResponse <IOrderedDictionary> > > GamesToRedeemInBackgroundPost(string botName, [FromBody] BotGamesToRedeemInBackgroundRequest request)
        {
            if (string.IsNullOrEmpty(botName) || (request == null))
            {
                ASF.ArchiLogger.LogNullError(nameof(botName) + " || " + nameof(request));
                return(BadRequest(new GenericResponse <IOrderedDictionary>(false, string.Format(Strings.ErrorIsEmpty, nameof(botName) + " || " + nameof(request)))));
            }

            if (request.GamesToRedeemInBackground.Count == 0)
            {
                return(BadRequest(new GenericResponse <IOrderedDictionary>(false, string.Format(Strings.ErrorIsEmpty, nameof(request.GamesToRedeemInBackground)))));
            }

            if (!Bot.Bots.TryGetValue(botName, out Bot bot))
            {
                return(BadRequest(new GenericResponse <IOrderedDictionary>(false, string.Format(Strings.BotNotFound, botName))));
            }

            bool result = await bot.ValidateAndAddGamesToRedeemInBackground(request.GamesToRedeemInBackground).ConfigureAwait(false);

            return(Ok(new GenericResponse <IOrderedDictionary>(result, request.GamesToRedeemInBackground)));
        }