Beispiel #1
0
        public void CreateMember(int groupId, int profileId, MembershipLevel role)
        {
            var group = _groupRepository.GetById(groupId);

            if (group == null)
            {
                throw new ArgumentException("Group doesn't exist!");
            }
            var user = _profileRepository.GetProfileByPredicate(x => x.ProfileId == profileId);

            if (user == null)
            {
                throw new ArgumentException("Profile doesn't exist!");
            }
            if (IsMember(profileId, group.GroupId))
            {
                throw new ArgumentException("Profile already a member of this group!");
            }
            Member newMember = new Member
            {
                GroupId   = groupId,
                ProfileId = profileId,
                Role      = role
            };

            try
            {
                _memberRepository.CreateMember(newMember);
            }
            catch (Exception e)
            {
                throw new ArgumentException(e.Message);
            }
        }
Beispiel #2
0
        public async Task ImportMembers(Guid currentMemberId, Guid chapterId, CsvFile file)
        {
            await AssertMemberIsChapterAdmin(currentMemberId, chapterId);

            IReadOnlyCollection <ChapterProperty> chapterProperties = await ChapterRepository.GetChapterProperties(chapterId);

            MemberCsvFileHeaders headers = new MemberCsvFileHeaders(chapterProperties);

            IDictionary <string, int> headerIndexes = file.GetColumnIndexes();

            IDictionary <int, Member> members = new Dictionary <int, Member>();

            IDictionary <int, MemberSubscription> membersSubscriptions = new Dictionary <int, MemberSubscription>();

            IDictionary <int, IReadOnlyCollection <MemberProperty> > membersProperties =
                new Dictionary <int, IReadOnlyCollection <MemberProperty> >();

            for (int i = 0; i < file.Rows.Count; i++)
            {
                CsvRow row = file.Rows.ElementAt(i);

                members.Add(i, new Member(Guid.Empty, chapterId,
                                          row.Value(headerIndexes[MemberCsvFileHeaders.Email]),
                                          true,
                                          row.Value(headerIndexes[MemberCsvFileHeaders.FirstName]),
                                          row.Value(headerIndexes[MemberCsvFileHeaders.LastName]),
                                          DateTime.UtcNow,
                                          true,
                                          false,
                                          0));

                if (DateTime.TryParse(row.Value(headerIndexes[MemberCsvFileHeaders.SubscriptionExpiry]), out DateTime subscriptionExpiry))
                {
                    membersSubscriptions.Add(i, new MemberSubscription(Guid.Empty, SubscriptionType.Full, subscriptionExpiry));
                }

                membersProperties.Add(i, chapterProperties
                                      .Select(x => new MemberProperty(Guid.Empty, Guid.Empty, x.Id, row.Value(headerIndexes[x.Label])))
                                      .ToArray());
            }

            // TODO: validate members

            for (int i = 0; i < file.Rows.Count; i++)
            {
                Guid memberId = await _memberRepository.CreateMember(members[i]);

                await _memberRepository.UpdateMemberProperties(memberId, membersProperties[i]);

                if (membersSubscriptions.ContainsKey(i))
                {
                    MemberSubscription subscription = new MemberSubscription(memberId, membersSubscriptions[i].Type, membersSubscriptions[i].ExpiryDate);
                    await _memberRepository.UpdateMemberSubscription(subscription);
                }
            }
        }
Beispiel #3
0
        public async Task <IActionResult> Create(Member member)
        {
            if (ModelState.IsValid)
            {
                _logger.LogWarning(LoggingEvents.CREATE_ITEM, "Creating Member: {member}", member.FirstName);
                await _memberRepository.CreateMember(member);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(member));
        }
        public void CreateMemberIfNotExists(Member member)
        {
            Member possiblyExists = _memberRepository
                                    .GetAllMembers()
                                    .FirstOrDefault(item => item.MemberUserName.ToUpper() == member.MemberUserName.ToUpper());

            if (possiblyExists == null)
            {
                _memberRepository
                .CreateMember(member);
            }
        }
Beispiel #5
0
        public async Task CreateMember(Guid chapterId, CreateMemberProfile profile)
        {
            await ValidateMemberProfile(chapterId, profile);

            ValidateMemberImage(profile.Image.MimeType, profile.Image.ImageData);

            Member existing = await _memberRepository.FindMemberByEmailAddress(profile.EmailAddress);

            if (existing != null)
            {
                return;
            }

            Member create = new Member(Guid.Empty, chapterId, profile.EmailAddress, profile.EmailOptIn, profile.FirstName, profile.LastName,
                                       DateTime.UtcNow, false, false, 0);

            Guid id = await _memberRepository.CreateMember(create);

            ChapterMembershipSettings membershipSettings = await _chapterRepository.GetChapterMembershipSettings(chapterId);

            MemberSubscription subscription = new MemberSubscription(id, SubscriptionType.Trial, create.CreatedDate.AddMonths(membershipSettings.TrialPeriodMonths));
            await _memberRepository.UpdateMemberSubscription(subscription);

            MemberImage image = CreateMemberImage(id, profile.Image.MimeType, profile.Image.ImageData);
            await _memberRepository.AddMemberImage(image);

            IEnumerable <MemberProperty> memberProperties = profile.Properties
                                                            .Select(x => new MemberProperty(Guid.Empty, id, x.ChapterPropertyId, x.Value));

            await _memberRepository.UpdateMemberProperties(id, memberProperties);

            string activationToken = RandomStringGenerator.Generate(64);

            await _memberRepository.AddActivationToken(new MemberActivationToken(id, activationToken));

            Chapter chapter = await _chapterRepository.GetChapter(chapterId);

            string url = _settings.ActivateAccountUrl.Interpolate(new Dictionary <string, string>
            {
                { "chapter.name", chapter.Name },
                { "token", HttpUtility.UrlEncode(activationToken) }
            });

            await _emailService.SendEmail(chapter, create.EmailAddress, EmailType.ActivateAccount, new Dictionary <string, string>
            {
                { "chapter.name", chapter.Name },
                { "url", url }
            });
        }
Beispiel #6
0
 public async Task CreateMember(Member member)
 {
     await _memberRepository.CreateMember(member);
 }
        public async Task <Member> CreateMember(Member member)
        {
            _logger.LogDebug("Creating a new member.");

            return(await _memberRepository.CreateMember(member));
        }