Exemple #1
0
        public async Task UpdateChapterEmail(Guid currentMemberId, Guid chapterId, EmailType type, UpdateEmail chapterEmail)
        {
            await AssertMemberIsChapterAdmin(currentMemberId, chapterId);

            ChapterEmail existing = await _emailRepository.GetChapterEmail(chapterId, type);

            if (existing == null)
            {
                existing = new ChapterEmail(Guid.Empty, chapterId, type, chapterEmail.Subject, chapterEmail.HtmlContent);
            }
            else
            {
                existing.HtmlContent = chapterEmail.HtmlContent;
                existing.Subject     = chapterEmail.Subject;
            }

            ValidateChapterEmail(existing);

            if (existing.Id != Guid.Empty)
            {
                await _emailRepository.UpdateChapterEmail(existing);
            }
            else
            {
                await _emailRepository.AddChapterEmail(existing);
            }
        }
Exemple #2
0
 public async Task UpdateChapterEmail(ChapterEmail chapterEmail)
 {
     await Context
     .Update <ChapterEmail>()
     .Set(x => x.HtmlContent, chapterEmail.HtmlContent)
     .Set(x => x.Subject, chapterEmail.Subject)
     .Where(x => x.Id).EqualTo(chapterEmail.Id)
     .ExecuteAsync();
 }
Exemple #3
0
        public async Task <Email> GetEmail(EmailType type, Guid chapterId)
        {
            ChapterEmail chapterEmail = await GetChapterEmail(chapterId, type);

            if (chapterEmail != null)
            {
                return(new Email(chapterEmail.Type, chapterEmail.Subject, chapterEmail.HtmlContent));
            }

            return(await GetEmail(type));
        }
Exemple #4
0
        private static void ValidateChapterEmail(ChapterEmail chapterEmail)
        {
            if (!Enum.IsDefined(typeof(EmailType), chapterEmail.Type) || chapterEmail.Type == EmailType.None)
            {
                throw new OdkServiceException("Invalid type");
            }

            if (string.IsNullOrWhiteSpace(chapterEmail.HtmlContent) ||
                string.IsNullOrWhiteSpace(chapterEmail.Subject))
            {
                throw new OdkServiceException("Some required fields are missing");
            }
        }
Exemple #5
0
        public async Task <ChapterEmail> GetChapterEmail(Guid currentMemberId, Guid chapterId, EmailType type)
        {
            await AssertMemberIsChapterAdmin(currentMemberId, chapterId);

            ChapterEmail chapterEmail = await _emailRepository.GetChapterEmail(chapterId, type);

            if (chapterEmail != null)
            {
                return(chapterEmail);
            }

            Email email = await _emailRepository.GetEmail(type, chapterId);

            return(new ChapterEmail(Guid.Empty, chapterId, type, email.Subject, email.HtmlContent));
        }
Exemple #6
0
        public async Task <ChapterEmailApiResponse> GetChapterEmail(Guid id, EmailType type)
        {
            ChapterEmail email = await _emailAdminService.GetChapterEmail(GetMemberId(), id, type);

            return(_mapper.Map <ChapterEmailApiResponse>(email));
        }
Exemple #7
0
 public async Task <Guid> AddChapterEmail(ChapterEmail chapterEmail)
 {
     return(await Context
            .Insert(chapterEmail)
            .GetIdentityAsync());
 }