Ejemplo n.º 1
0
        ///<inheritdoc cref="IMessageSendService.SendEmail(SmtpClient, Message)"/>
        public async Task SendEmailNow(string smtpServer, IEnumerable <MailMessage> mailMessages, bool isSheduled = false)
        {
            if (isSheduled == false)
            {
                try
                {
                    DataValidate(smtpServer, mailMessages);
                }
                catch (EmailSendServiceException ex)
                {
                    throw ex;
                }
            }

            var sender            = _senderRepository.GetAll().Where(x => x.Email == mailMessages.FirstOrDefault().From.Address).FirstOrDefault().ToDomain();
            var allRecipients     = _recipientRepository.GetAll();
            var messageRecipients = new List <Recipient>();

            using (var client = GetSmtpClient(sender, smtpServer))
            {
                foreach (var mail in mailMessages)
                {
                    var recipient = allRecipients.Where(x => x.Email == mail.To.FirstOrDefault().Address).FirstOrDefault();
                    messageRecipients.Add(recipient.ToDomain());
                    await client.SendMailAsync(mail);
                }
            }

            if (isSheduled == false)
            {
                var sendedMessage = new Message()
                {
                    SenderId     = sender.Id,
                    Body         = mailMessages.FirstOrDefault().Body,
                    Title        = mailMessages.FirstOrDefault().Subject,
                    SendDateTime = DateTime.Now
                };
                _messageRepository.Add(sendedMessage.ToEntity());
            }
            ;

            foreach (var rec in messageRecipients)
            {
                _recipient2MessageRepository.Add(new Recipient2MessageEntity()
                {
                    MessageId   = _messageRepository.GetAll().Select(x => x.Id).LastOrDefault(),
                    RecipientId = rec.Id
                });
            }
        }
Ejemplo n.º 2
0
        private void simpleButtonSave_Click(object sender, EventArgs e)
        {
            ProcessTabKey(true);

            if (Validation() == false)
            {
                return;
            }

            if (_item.Id == 0)
            {
                _item = _repo.Add(_item);
            }
            else
            {
                _repo.Update(_item);
            }

            DialogResult = DialogResult.OK;
        }
Ejemplo n.º 3
0
        public virtual MessageObject <T> Add(T entity)
        {
            MessageObject <T> validationResult = ValidateAdd(entity);

            try
            {
                BasePreProcessing(ref entity, OperationType.Add);
                if (validationResult.ProcessingStatus)
                {
                    validationResult.Data = repo.Add(entity);
                    repo.Commit();

                    BasePostProcessing(ref entity, OperationType.Add);
                }
            }
            catch (Exception ex)
            {
                Utils.Logger.Log(ex, logSource);
                validationResult.AddException(ex);
            }
            return(validationResult);
        }
Ejemplo n.º 4
0
 public void Add(Host host)
 {
     _repository.Add(host.ToEntity());
 }
Ejemplo n.º 5
0
 public void Add(Sender sender)
 {
     _repository.Add(sender.ToEntity());
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 写入实体数据
 /// </summary>
 /// <param name="entity">实体类</param>
 /// <returns></returns>
 public async Task <int> Add(T entity)
 {
     return(await BaseDal.Add(entity));
 }
Ejemplo n.º 7
0
 public void Add(Recipient recipient)
 {
     _repository.Add(recipient.ToEntity());
 }