public NewsletterResult SaveNewsletter(NewsletterResult newsletterResult) { if (newsletterResult == null || newsletterResult.NewsletterForm == null) { throw new ArgumentNullException("No NewsletterForm send"); } if (string.IsNullOrEmpty(newsletterResult.NewsletterForm.Email)) { throw new ArgumentException("Empty email", nameof(newsletterResult.NewsletterForm.Email)); } var newsletterDto = NewsletterParse(newsletterResult); if (_newsletterRepository.GetByEmail(newsletterDto.Email) == null) { newsletterDto.Id = 0; newsletterDto = _newsletterRepository.Insert(newsletterDto); } else { newsletterDto = _newsletterRepository.GetByEmail(newsletterDto.Email); } return(NewsletterParse(newsletterDto)); }
public SaveToNewsletterResponse SaveToNewsletter(string email) { SaveToNewsletterResponse returnModel = new SaveToNewsletterResponse(); returnModel.Success = true; if (_newsletterRepository.EmailExistsInNewsletter(email)) { returnModel.Success = false; returnModel.Message = "Email exists"; } else { _newsletterRepository.Insert(new Newsletter { Email = email, RegisterDate = DateTime.UtcNow }); } return(returnModel); }
public void CreateNewsletter(string name, string html) { IEnumerable <Subscription> subscriptions = SubscriptionRepository.Get(s => s.IsConfirmed == true, null, null); Newsletter newsletter = new Newsletter(); newsletter.Name = name; newsletter.DateCreated = DateTime.UtcNow; newsletter.Html = html; newsletter.InProcess = false; foreach (Subscription s in subscriptions) { NewsletterTask newslettertask = new NewsletterTask(); newslettertask.SetNewsletter(newsletter); newslettertask.SetSubscription(s); newsletter.AddNewsletterTask(newslettertask); } NewsletterRepository.Insert(newsletter); NewsletterRepository.UnitOfWork.Commit(); }
public async Task RegistrerSignup(Signup s) { if (s == null) { return; } await _repo.Insert(s); await _bus.Publish( new SendMail { ToName = s.Name, ToEmail = s.Email, Subject = _mailOptions.Subject, Body = _mailOptions.Body.FormatWith(s.Name) }); await _bus.Publish( new NewsletterSubscribed { Name = s.Name, Email = s.Email }); }