Exemplo n.º 1
0
        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));
        }