コード例 #1
0
        public async Task <int?> RateVolume(string userId, RateApiRequestModel model)
        {
            var volume = this.dbContext.Volumes.Find(model.Id);

            if (volume != null)
            {
                var userVolume = volume.UsersVolumes.FirstOrDefault(ua => ua.UserId == userId);

                if (userVolume == null)
                {
                    userVolume = new UserVolume
                    {
                        UserId   = userId,
                        VolumeId = model.Id,
                        Score    = model.Score,
                    };

                    volume.UsersVolumes.Add(userVolume);

                    this.dbContext.Update(volume);
                    await this.dbContext.SaveChangesAsync();
                }
                else
                {
                    userVolume.Score = model.Score;

                    this.dbContext.Update(volume);
                    await this.dbContext.SaveChangesAsync();
                }

                return(model.Score);
            }

            return(null);
        }
コード例 #2
0
        public async Task RemoveVolumeFromList(string userId, int id)
        {
            var volume = this.dbContext.Volumes.Find(id);

            if (volume == null)
            {
                throw new KeyNotFoundException("Volume with given id does not exist.");
            }

            var user = this.dbContext.Users
                       .Include(u => u.UsersVolumes)
                       .FirstOrDefault(u => u.Id == userId);

            if (!user.UsersVolumes.Any(uv => uv.Volume == volume))
            {
                throw new InvalidOperationException("User does not have given volume in their list.");
            }

            var userVolume = new UserVolume {
                User = user, Volume = volume
            };

            user.UsersVolumes.Remove(userVolume);
            await this.dbContext.SaveChangesAsync();
        }
コード例 #3
0
        private void Sl_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            var slider = (Slider)e.Source;
            var vol    = (UserVolume)slider.DataContext;
            var newVol = new UserVolume(vol.UserID, (float)slider.Value);

            VolumeChanged?.Invoke(sender, newVol);
        }
コード例 #4
0
        public async Task AddVolumeToList(string userId, int id)
        {
            var volume = this.dbContext.Volumes.Find(id);

            if (volume == null)
            {
                throw new KeyNotFoundException("Volume with given id does not exist.");
            }

            if (volume.UsersVolumes.Any(ua => ua.UserId == userId))
            {
                throw new InvalidOperationException("User has already added given volume to their list.");
            }

            var userVolume = new UserVolume { UserId = userId, Volume = volume };

            volume.UsersVolumes.Add(userVolume);
            await this.dbContext.SaveChangesAsync();
        }
コード例 #5
0
ファイル: TSPlugin.cs プロジェクト: lukaskabc/TeamCord
 private void Control_VolumeChanged(object sender, UserVolume e)
 {
     ConnectionHandler.CurrentVoiceChannelService.ChangeVolume(e);
 }