private async Task UpdateMatch(StartMatchUpdateCommand command, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Starting video conversion for match ({0})", command.MatchId);

            try
            {
                var trimResult = await _videoConverter.TrimVideoAsync(command.MatchId.ToString(),
                                                                      command.Video,
                                                                      command.Start,
                                                                      command.End);

                var updateCommand = new UpdateMatchCommand
                {
                    MatchId = command.MatchId,
                    UserId  = command.UserId,
                    Thumb   = trimResult.Thumb,
                    Video   = trimResult.Video,
                    Move    = command.Move,
                };

                using (var scope = _serviceProvider.CreateScope())
                {
                    var mediator = scope.ServiceProvider.GetRequiredService <IMediator>();
                    await mediator.Send(updateCommand, cancellationToken);

                    var notificationSender =
                        scope.ServiceProvider.GetRequiredService <IMatchUpdaterNotifications>();
                    await notificationSender.NotifyMatchUpdated(command.UserId, command.MatchId);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Failed to update match ({0})", command.MatchId);
            }
        }
Exemple #2
0
        public string Manage(MatchFeedModel feedModel, string tournamentId, string homeTeamId, string awayTeamId)
        {
            IEnumerable <int> keys = new List <int>()
            {
                feedModel.Key
            };
            EntitiesByKeyQuery <Match> matchQuery = new EntitiesByKeyQuery <Match>(keys);
            Match match = queryDispatcher.Dispatch <EntitiesByKeyQuery <Match>, IEnumerable <Match> >(matchQuery).FirstOrDefault();

            if (match != null)
            {
                UpdateMatchCommand updateCommand = Mapper.Map <UpdateMatchCommand>(feedModel);
                updateCommand.Id = match.Id;

                return(commandDispatcher.Dispatch <UpdateMatchCommand, string>(updateCommand));
            }

            CreateMatchCommand createCommand = Mapper.Map <CreateMatchCommand>(feedModel);

            createCommand.TournamentId = tournamentId;
            createCommand.HomeTeamId   = homeTeamId;
            createCommand.AwayTeamId   = awayTeamId;

            return(commandDispatcher.Dispatch <CreateMatchCommand, string>(createCommand));
        }
        public async Task <IActionResult> Update(int id, [FromBody] UpdateMatchCommand command)
        {
            command.Id = id;

            await Mediator.Send(command);

            return(NoContent());
        }
Exemple #4
0
        public async Task <IActionResult> UpdateMatch(int matchId, [FromBody] UpdateMatchCommand command)
        {
            command.MatchId = matchId;
            command.UserId  = UserId;

            var response = await Mediator.Send(command);

            return(Ok(response));
        }
        public async Task <ActionResult> Update(int id, UpdateMatchCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }