public async Task <ResponseApi> Handle(UpdateChampionshipCommand request, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Update Championship : { JsonSerializer.Serialize(request)}");
            try
            {
                var validate = request.Validate(_championshipRepository, _teamRepository);
                if (!validate.IsValid)
                {
                    _logger.LogInformation($"ERROR - Update Championship : { JsonSerializer.Serialize(validate.Errors.Select(x => new { Campo = x.PropertyName, Erro = x.ErrorMessage }).ToList())}");
                    return(new ResponseApi(false, "Erro ao atualizar o campeonato", validate.Errors.Select(x => new { Campo = x.PropertyName, Erro = x.ErrorMessage }).ToList()));
                }

                Championship championship = new Championship(request.Id, request.ChampionshipName);
                championship.AddTeams(request.GetTeams());
                await _championshipRepository.Update(championship);

                var response = new { Id = championship.Id, ChampionshipName = championship.ChampionshipName, TeamIds = request.TeamsIds, isActive = championship.IsActive };
                _logger.LogInformation($"SUCCESS - Update Championship : { JsonSerializer.Serialize(response)}");

                return(new ResponseApi(true, "Campeonato Atualizado com Sucesso",
                                       response));
            }
            catch (Exception e)
            {
                _logger.LogInformation($"ERROR - Create Championship : { JsonSerializer.Serialize(e)}");
                return(new ResponseApi(false, "Erro ao inserir o campeonato", e.InnerException.ToString()));
            }
        }
Ejemplo n.º 2
0
        public void Update(ChampionshipViewModel championshipViewModel)
        {
            string[] symbol = championshipViewModel.Picture.Split('/');

            if (symbol[0] != "data:image")
            {
                championshipViewModel.Picture = symbol[symbol.Count() - 1];
            }
            else
            {
                championshipViewModel.Picture = Divers.Base64ToImage(championshipViewModel.Picture, "CHAMPIONSHIP");
            }

            _championshipRepository.Update(_mapper.Map <Championship>(championshipViewModel));
        }