Beispiel #1
0
        public async Task <MemberSubscription> PurchaseSubscription(Guid memberId, Guid chapterSubscriptionId, string cardToken)
        {
            ChapterSubscription chapterSubscription = await _chapterRepository.GetChapterSubscription(chapterSubscriptionId);

            if (chapterSubscription == null)
            {
                throw new OdkServiceException("Subscription not found");
            }

            Member member = await GetMember(memberId);

            await _authorizationService.AssertMemberIsChapterMember(member, chapterSubscription.ChapterId);

            await _paymentService.MakePayment(member, chapterSubscription.Amount, cardToken, chapterSubscription.Title);

            MemberSubscription memberSubscription = await _memberRepository.GetMemberSubscription(member.Id);

            DateTime expiryDate = (memberSubscription?.ExpiryDate ?? DateTime.UtcNow).AddMonths(chapterSubscription.Months);

            memberSubscription = new MemberSubscription(member.Id, chapterSubscription.Type, expiryDate);

            await _memberRepository.UpdateMemberSubscription(memberSubscription);

            MemberSubscriptionRecord record = new MemberSubscriptionRecord(memberId, chapterSubscription.Type, DateTime.UtcNow,
                                                                           chapterSubscription.Amount, chapterSubscription.Months);
            await _memberRepository.AddMemberSubscriptionRecord(record);

            _cacheService.UpdatedVersionedItem(memberSubscription, memberId);
            _cacheService.RemoveVersionedCollection <Member>(member.ChapterId);

            return(memberSubscription);
        }