public bool CanCreateProject(Guid companyId) { var projects = _projectDao.ReadProjectsForCompanyId(companyId); var subscription = _companyDao.ReadSubscriptionByCompanyId(companyId); return(subscription.Quantity > projects.Count); }
public void Activate(FastSpringNotificationParameter parameter) { var subscription = RetrieveSubscription(parameter.SubscriptionReference); _log.InfoFormat("Subscription {0} ACTIVATE request recieved.", subscription); if (subscription.ProductName.StartsWith("Basic")) { subscription.Quantity = 1; } else if (subscription.ProductName.StartsWith("Standard")) { subscription.Quantity = 5; } else if (subscription.ProductName.StartsWith("Large")) { subscription.Quantity = 15; } var user = _userDao.ReadByEmail(subscription.Customer.Email); if (user == null) { var newUser = _subscriptionUtils.CreateSubscription(subscription, subscription.Customer.Email); //send EMail InvitationEmailSender.SendNewCustomerInvitation(newUser.EMail, newUser.Password); _log.InfoFormat("Subscription ID:{0}, email sent. Activation finished successfully.", subscription.SubscriptionReference); } else { var subscriptionDo = _companyDao.ReadSubscriptionByCompanyId(user.CompanyId); if (user.IsCompanyAdmin && (subscriptionDo.Test || (subscriptionDo.Status == SubscriptionStatus.Inactive))) { var newSubscriptionDo = _mapper.Map <SubscriptionDO>(subscription); _log.InfoFormat("Subscription ID:{0}, subscription created in DB. {1}", subscription.SubscriptionReference, subscriptionDo); var company = _companyDao.ReadCompanyById(user.CompanyId); company.SubscriptionReference = newSubscriptionDo.SubscriptionReference; company.Subscription = newSubscriptionDo; _companyDao.Update(company); _log.InfoFormat("Subscription ID:{0}, company updated in DB. {1}", subscription.SubscriptionReference, company); _subscriptionDao.Delete(subscriptionDo); if (subscriptionDo.Test) { InvitationEmailSender.SendTrialToSubscription(user.EMail, user.Password); } else if (subscriptionDo.Status == SubscriptionStatus.Inactive) { InvitationEmailSender.WellcomeBack(user.EMail); } _log.InfoFormat("Subscription ID:{0}, email sent. Activation finished successfully.", newSubscriptionDo.SubscriptionReference); } else { var originalEmail = subscription.Customer.Email; subscription.Customer.Email = FindNewCustomerLoginEmail(originalEmail); var newUser = _subscriptionUtils.CreateSubscription(subscription, originalEmail); //send EMail InvitationEmailSender.SendNewCustomerDuplicateInvitation(originalEmail, newUser.EMail, newUser.Password); _log.InfoFormat("Subscription ID:{0}, email sent. Activation finished successfully.", subscription.SubscriptionReference); } } }