public async Task CreateDefaultAsync(string userId) { var user = await _userRepository.GetAsync(userId); if (user.HasNoValue) { throw new ArgumentException($"User with id: {userId} has not been found."); } var defaultPlan = await _paymentPlanRepository.GetDefaultAsync(); if (defaultPlan.HasNoValue) { throw new ServiceException("Default payment plan has not been found."); } var userPlan = new UserPaymentPlan(user.Value, defaultPlan.Value); userPlan.AddMonthlySubscription(DateTime.UtcNow, userPlan.Features); await _userPaymentPlanRepository.AddAsync(userPlan); user.Value.SetPaymentPlan(userPlan); await _userRepository.UpdateAsync(user.Value); }
public async Task AddAsync(UserPaymentPlan paymentPlan) => await _database.UserPaymentPlans().InsertOneAsync(paymentPlan);
public async Task UpdateAsync(UserPaymentPlan paymentPlan) => await _database.UserPaymentPlans().ReplaceOneAsync(x => x.Id == paymentPlan.Id, paymentPlan);