コード例 #1
0
        private static IEnumerable <string> GetMissingMemberProfileProperties(UpdateMemberProfile profile, IEnumerable <ChapterProperty> chapterProperties,
                                                                              IEnumerable <UpdateMemberProperty> memberProperties)
        {
            if (string.IsNullOrWhiteSpace(profile.FirstName))
            {
                yield return("First name");
            }

            if (string.IsNullOrWhiteSpace(profile.LastName))
            {
                yield return("First name");
            }

            IDictionary <Guid, string> memberPropertyDictionary = memberProperties.ToDictionary(x => x.ChapterPropertyId, x => x.Value);

            foreach (ChapterProperty chapterProperty in chapterProperties.Where(x => x.Required))
            {
                string value = memberPropertyDictionary.ContainsKey(chapterProperty.Id)
                    ? memberPropertyDictionary[chapterProperty.Id]
                    : null;

                if (string.IsNullOrWhiteSpace(value))
                {
                    yield return(chapterProperty.Label);
                }
            }
        }
コード例 #2
0
        private async Task ValidateMemberProfile(Guid chapterId, UpdateMemberProfile profile)
        {
            IReadOnlyCollection <ChapterProperty> chapterProperties = await _chapterRepository.GetChapterProperties(chapterId);

            IReadOnlyCollection <string> missingProperties = GetMissingMemberProfileProperties(profile, chapterProperties, profile.Properties).ToArray();

            if (missingProperties.Count > 0)
            {
                throw new OdkServiceException($"The following properties are required: {string.Join(", ", missingProperties)}");
            }
        }
コード例 #3
0
        private static void UpdateMemberProfile(MemberProfile existing, UpdateMemberProfile update)
        {
            existing.EmailOptIn = update.EmailOptIn;
            existing.FirstName  = update.FirstName.Trim();
            existing.LastName   = update.LastName.Trim();

            foreach (MemberProperty memberProperty in existing.MemberProperties)
            {
                UpdateMemberProperty updateProperty = update.Properties?.FirstOrDefault(x => x.ChapterPropertyId == memberProperty.ChapterPropertyId);
                if (updateProperty == null)
                {
                    continue;
                }

                string value = updateProperty.Value;
                memberProperty.Update(value);
            }
        }
コード例 #4
0
        public async Task <MemberProfile> UpdateMemberProfile(Guid id, UpdateMemberProfile profile)
        {
            Member member = await GetMember(id);

            await ValidateMemberProfile(member.ChapterId, profile);

            MemberProfile existing = await GetMemberProfile(id);

            UpdateMemberProfile(existing, profile);

            await _memberRepository.UpdateMember(id, existing.EmailOptIn, existing.FirstName, existing.LastName);

            await _memberRepository.UpdateMemberProperties(id, existing.MemberProperties);

            IReadOnlyCollection <Member> members = await _memberRepository.GetMembers(member.ChapterId);

            long version = await _memberRepository.GetMembersVersion(member.ChapterId);

            _cacheService.UpdatedVersionedCollection(members, version, member.ChapterId);

            _cacheService.RemoveVersionedItem <Member>(member.Id);

            return(existing);
        }