Beispiel #1
0
        public ActionResult delete(int id)
        {
            var idbg = _emailRepository.GetById(id);

            _emailRepository.Delete(idbg);
            _unitOfWork.Commit();
            return(RedirectToAction("Index"));
        }
        public async Task <Response <string> > Handle(GetEmailStatusQuery request, CancellationToken cancellationToken)
        {
            EmailEntity email = emailRepo.GetById(request.EmailId);

            if (email == null)
            {
                return(Response.Fail <string>(EmailResult.NotExists));
            }
            return(Response.Ok <string>(email.Status.ToString()));
        }
Beispiel #3
0
        public async Task <Response <EmailDto> > Handle(GetEmailDetailsQuery request, CancellationToken cancellationToken)
        {
            EmailEntity email = emailRepo.GetById(request.EmailId);

            if (email == null)
            {
                return(Response.Fail <EmailDto>(EmailResult.NotExists));
            }
            return(Response.Ok <EmailDto>(EmailDto.Make(email)));
        }
Beispiel #4
0
        public EmailDTO GetById(int id)
        {
            var email = _emailRepository.GetById(id).FirstOrDefault();

            if (email == null)
            {
                return(null);
            }

            return(new EmailMapping().ToEmailDTOMap(email));
        }
Beispiel #5
0
        public bool Invoke(Guid emailId)
        {
            if (emailId == Guid.Empty)
            {
                return(false);
            }

            var emailToDelete = emailRepository.GetById(emailId);

            if (emailToDelete == null)
            {
                return(false);
            }

            emailRepository.Delete(emailToDelete);
            _unitOfWork.Save();

            return(true);
        }
        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);
        }
 public Email GetById(int id)
 {
     return repository.GetById(id);
 }
        private async Task MessageRecieved(object sender, BasicDeliverEventArgs e)
        {
            try
            {
                var body = e.Body;

                var message = JsonSerializer.Deserialize <UpdateStoredEmailStatusMessage>(body.Span);

                _logger.LogInformation($"Recieved message to update status for stored email with id: { message.EventPayload.Id }" +
                                       $" to status: { message.Status }, request recieved at: { message.RecievedAt }");

                if (message.EventPayload.Trackable)
                {
                    using (var unitOfWork = UnitOfWorkFactory.CreateWithoutRoot("Status update worker"))
                    {
                        var storedEmail = _emailRepository.GetById(unitOfWork, message.EventPayload.Id);

                        if (storedEmail != null)
                        {
                            _logger.LogInformation($"Found Email: { storedEmail.Id }, externalId { storedEmail.ExternalId }, status { storedEmail.State }");

                            if (storedEmail.StateChangeDate < message.RecievedAt)
                            {
                                try
                                {
                                    var newStatus = ConvertFromMailjetStatus(message.Status);

                                    if (newStatus == StoredEmailStates.Undelivered || newStatus == StoredEmailStates.SendingError)
                                    {
                                        storedEmail.AddDescription(message.ErrorInfo);
                                    }

                                    storedEmail.State           = newStatus;
                                    storedEmail.StateChangeDate = message.RecievedAt;
                                    storedEmail.ExternalId      = message.MailjetMessageId;

                                    unitOfWork.Save(storedEmail);
                                    unitOfWork.Commit();

                                    _logger.LogInformation($"Email: { storedEmail.Id }, externalId { storedEmail.ExternalId }, status changed to { storedEmail.State }");
                                }
                                catch (ArgumentOutOfRangeException)
                                {
                                    _logger.LogInformation($"Skipped event for emaid with id: { storedEmail.Id }, externalId { storedEmail.ExternalId } for status change to { message.Status }");
                                }
                            }
                        }
                        else
                        {
                            _logger.LogWarning($"Stored Email with id: { message.EventPayload.Id } not found");
                        }
                    }
                }

                _channel.BasicAck(e.DeliveryTag, false);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw;
            }
        }