Ejemplo n.º 1
0
        public async Task Handle(AddSampleRatings busCommand)
        {
            // Get some user ids and video ids to rate with those users
            List <Guid> userIds = await _sampleDataRetriever.GetRandomSampleUserIds(busCommand.NumberOfRatings).ConfigureAwait(false);

            if (userIds.Count == 0)
            {
                Logger.Warn("No sample users available.  Cannot add sample ratings.");
                return;
            }

            List <Guid> videoIds = await _sampleDataRetriever.GetRandomVideoIds(busCommand.NumberOfRatings).ConfigureAwait(false);

            if (videoIds.Count == 0)
            {
                Logger.Warn("No sample videos available.  Cannot add sample ratings.");
                return;
            }

            // Rate some videos in parallel
            var ratingTasks = new List <Task>();
            var random      = new Random();

            for (int i = 0; i < busCommand.NumberOfRatings; i++)
            {
                ratingTasks.Add(_ratingsService.RateVideo(new RateVideo
                {
                    UserId  = userIds[i],
                    VideoId = videoIds[i],
                    Rating  = random.Next(1, 6)
                }));
            }

            await Task.WhenAll(ratingTasks).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        public async Task <JsonNetResult> Rate(RateVideoViewModel model)
        {
            await _ratings.RateVideo(new RateVideo
            {
                VideoId = model.VideoId,
                UserId  = User.GetCurrentUserId().Value,
                Rating  = model.Rating
            });

            return(JsonSuccess());
        }