コード例 #1
0
        public async Task <ActionResult> AddUserToChannelBlacklist([FromQuery] int roomId,
                                                                   [FromBody] ChannelBlacklistInput input)
        {
            List <ChannelUserBlacklist> allUserInChannelBans =
                _ttsDbContext.ChannelUserBlacklist.Where(cub =>
                                                         cub.ChannelId == roomId &&
                                                         cub.UserId == input.UserId
                                                         ).ToList();

            foreach (ChannelUserBlacklist userInChannelBan in allUserInChannelBans)
            {
                _ttsDbContext.ChannelUserBlacklist.Remove(userInChannelBan);
            }

            await _ttsDbContext.SaveChangesAsync();

            ChannelUserBlacklist cub = new ChannelUserBlacklist
            {
                ChannelId = roomId,
                UserId    = input.UserId,
                AddDate   = DateTime.UtcNow,
                UntilDate = input.UntilDate
            };
            await _ttsDbContext.ChannelUserBlacklist.AddAsync(cub);

            await _ttsDbContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetChannelBlacklist), new { roomId }, new ChannelBlacklistView(cub)));
        }
コード例 #2
0
        public async Task <ActionResult> AddGlobal([FromBody] GlobalBlacklistInput input)
        {
            GlobalUserBlacklist gub = new GlobalUserBlacklist {
                UserId = input.UserId
            };
            await _ttsDbContext.GlobalUserBlacklist.AddAsync(gub);

            await _ttsDbContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetGlobal), null, gub));
        }
コード例 #3
0
        public async Task <ActionResult> Update([FromQuery] int roomId, [FromBody] ChannelUpdateInput input)
        {
            Channel dbChannel = await _ttsDbContext.Channels.FindAsync(roomId);

            if (dbChannel is null || !dbChannel.Enabled)
            {
                return(NotFound());
            }

            try
            {
                bool dbChanged = false;
                foreach (var pi in input.GetType().GetProperties())
                {
                    if (pi.GetValue(input) is null)
                    {
                        continue;
                    }

                    PropertyInfo piDb = dbChannel.GetType().GetProperty(pi.Name);
                    piDb?.SetValue(dbChannel, pi.GetValue(input));
                    dbChanged = true;
                }

                if (dbChanged)
                {
                    await _ttsDbContext.SaveChangesAsync();
                }

                return(NoContent());
            }
            catch (Exception e)
            {
                _logger.LogError("{E}", e);
                return(Problem("Saving data failed.", null, (int)HttpStatusCode.InternalServerError));
            }
        }
コード例 #4
0
        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 }