Esempio n. 1
0
        public Task <Unit> Handle(CreateEmailCommand request, CancellationToken cancellationToken)
        {
            var id = emailRepo.CreateNew(request.Subjet, request.Author, request.Body);

            responder.SetResult(EmailResult.Success);
            return(Unit.Task);
        }
Esempio n. 2
0
        public async Task <Unit> Handle(SendAllPendingCommand request, CancellationToken cancellationToken)
        {
            IEnumerable <EmailEntity> emails = emailRepo.GetPendingEmails();

            if (!emails.Any())
            {
                responder.SetResult(EmailResult.NothingToSend);
                return(await Unit.Task);
            }

            foreach (var e in emails)
            {
                await emailClient.Send(e);

                e.SetStatus(EmailStatus.sent);
                await emailRepo.Update(e);
            }

            responder.SetResult(EmailResult.Success);
            return(await Unit.Task);
        }
Esempio n. 3
0
        public Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next)
        {
            var context  = new ValidationContext <TRequest>(request);
            var failures = validators
                           .Select(x => x.Validate(context))
                           .SelectMany(x => x.Errors)
                           .Where(x => x != null)
                           .ToList();

            if (failures.Any())
            {
                responder.SetResult(EmailResult.ValidationError);
                return(Task.FromResult <TResponse>(default));
        public Task <Unit> Handle(AddRecipientCommand request, CancellationToken cancellationToken)
        {
            EmailEntity email = emailRepo.GetById(request.EmailId);

            if (email == null)
            {
                responder.SetResult(EmailResult.NotExists);
                return(Unit.Task);
            }

            var existingToEmail = email.GetRecipients();
            var toAdd           = request.Recipients.Where(x => !existingToEmail.Any(y => y.Address == x.Address)).ToList();

            if (!toAdd.Any())
            {
                responder.SetResult(EmailResult.AlreadyExists);
                return(Unit.Task);
            }
            email.AddRecipients(toAdd.Select(x => new EmailAddress(x.Address, x.Name)).ToList());
            emailRepo.Update(email);

            responder.SetResult(EmailResult.Success);
            return(Unit.Task);
        }
        public Task <Unit> Handle(AddSenderCommand request, CancellationToken cancellationToken)
        {
            EmailEntity email = emailRepo.GetById(request.EmailId);

            if (email == null)
            {
                responder.SetResult(EmailResult.NotExists);
                return(Unit.Task);
            }

            EmailAddress sender = email.GetSender();

            if (sender != null)
            {
                responder.SetResult(EmailResult.AlreadyExists);
                return(Unit.Task);
            }

            email.AddSender(new EmailAddress(request.Sender.Address, request.Sender.Name));
            emailRepo.Update(email);

            responder.SetResult(EmailResult.Success);
            return(Unit.Task);
        }