Beispiel #1
0
        public RewardView(Reward reward, TwitchCustomRewards twitchCustomRewards)
        {
            if (reward is not null)
            {
                RewardId       = reward.RewardId;
                ChannelId      = reward.ChannelId;
                VoiceId        = reward.VoiceId;
                VoiceEngine    = reward.VoiceEngine;
                IsConversation = reward.IsConversation;
                IsSubOnly      = reward.IsSubOnly;
                Cooldown       = reward.Cooldown;
            }

            TwitchCustomRewards = twitchCustomRewards;
        }
        public async Task <ActionResult <RewardView> > Create([FromQuery] int roomId,
                                                              [FromBody] RewardCreateInput input)
        {
            Channel channel = _ttsDbContext.Channels.FirstOrDefault(c => c.RoomId == roomId);

            if (channel is null)
            {
                return(NotFound());
            }

            TwitchCustomRewardsInputCreate twitchInput = new()
            {
                Title               = input.Title,
                Prompt              = input.Prompt,
                Cost                = input.Cost,
                IsEnabled           = true,
                IsUserInputRequired = true,
                ShouldRedemptionsSkipRequestQueue = false
            };

            DataHolder <TwitchCustomRewards> dataHolder =
                await _customRewards.CreateCustomReward(channel, twitchInput);

            if (dataHolder.Data is { Count : > 0 })
            {
                TwitchCustomRewards twitchCustomRewards = dataHolder.Data.First();
                if (twitchCustomRewards?.Id is null)
                {
                    return(Problem(null, null, (int)HttpStatusCode.ServiceUnavailable));
                }
                Reward newReward = new()
                {
                    RewardId    = twitchCustomRewards.Id,
                    ChannelId   = int.Parse(twitchCustomRewards.BroadcasterId),
                    VoiceId     = input.VoiceId,
                    VoiceEngine = input.VoiceEngine
                };
                _ttsDbContext.Rewards.Add(newReward);
                await _ttsDbContext.SaveChangesAsync();

                return(Created($"{@Url.Action("Get")}/{twitchCustomRewards.Id}",
                               new RewardView(newReward, twitchCustomRewards)));
            }

            return(dataHolder is { Status : (int)HttpStatusCode.BadRequest, Message : ErrorDuplicateReward }