Пример #1
0
        public async Task <bool> HandleAsync(RegisterConfirmationEventRequest message, IOutputPort <RegisterConfirmationEventResponse> outputPort)
        {
            var response = await _eventRepository.PostConfirmationEvent(message);

            outputPort.Handle(response.Success ? new RegisterConfirmationEventResponse(response.Confirmation, true, response.Message) :
                              new RegisterConfirmationEventResponse(response.Errors, false, response.Message));
            return(response.Success);
        }
        public async Task <RegisterConfirmationEventResponse> PostConfirmationEvent(RegisterConfirmationEventRequest registerUserEventRequest)
        {
            Task <RegisterConfirmationEventResponse> registerConfirmation = null;

            try
            {
                var userInEvent = DbContext.Registers.Include(x => x.Event).FirstOrDefault(x => x.Id == registerUserEventRequest.RegisterId);

                if (userInEvent != null)
                {
                    if (DateTime.Now > userInEvent.Event.Date)
                    {
                        registerConfirmation  = Task.FromResult(new RegisterConfirmationEventResponse(false, true, "Data do evento expirada."));
                        userInEvent.Confirmed = false;
                        return(await registerConfirmation);
                    }

                    if (userInEvent.Confirmed)
                    {
                        registerConfirmation = Task.FromResult(new RegisterConfirmationEventResponse(false, true, "Usuário já confirmado no evento."));
                        return(await registerConfirmation);
                    }

                    userInEvent.Confirmed = true;

                    await DbContext.SaveChangesAsync();

                    registerConfirmation = Task.FromResult(new RegisterConfirmationEventResponse(true, true));
                }
                else
                {
                    registerConfirmation = Task.FromResult(new RegisterConfirmationEventResponse(false, false, "Usuário não está cadastrado no evento."));
                }

                return(await registerConfirmation);
            }
            catch (Exception ex)
            {
                List <string> errors = new List <string>();
                errors.Add(ex.Message);
                return(new RegisterConfirmationEventResponse(errors, false, null));;
            }
        }