public async Task <NotificationResultDto> Handle(UpdateAudienceCommand command, CancellationToken cancellationToken)
        {
            try
            {
                if (!command.Valid())
                {
                    return(_handlerResponse.Response(command.IsValid, command.Notifications));
                }

                var audienceEntites = await _audienceRepository.GetByIdAsync(command.Id);

                if (audienceEntites != null)
                {
                    var audience = await _audienceRepository.GetAudienceByBroadcasterAndDateTimeAsync(command.AudienceBroadcaster, command.AudienceDateTime);

                    if (audience != null)
                    {
                        audienceEntites.AudienceRegister();
                    }

                    if (audienceEntites.IsValid)
                    {
                        audienceEntites.Update(command.AudienceBroadcaster, command.AudiencePoints, command.AudienceDateTime);

                        if (audienceEntites.IsValid)
                        {
                            await _audienceRepository.UpdateAsync(audienceEntites);
                        }
                    }

                    AddNotifications(audienceEntites);
                }
                else
                {
                    var audience = new Audience();
                    audience.NotAudienceForUpdate();
                    AddNotifications(audience);
                }
            }
            catch (Exception ex)
            {
                AddNotification("500", ex.Message);
            }

            return(_handlerResponse.Response(IsValid, Notifications));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Put([FromBody] UpdateAudienceCommand command)
        {
            var notificationResult = await _audienceAppService.UpdatedAsync(command);

            return(Response(notificationResult));
        }
Exemplo n.º 3
0
 public async Task <NotificationResultDto> UpdatedAsync(UpdateAudienceCommand command)
 => await _mediator.Send(command);