public bool UpdateTenantSubscriptionInfo(string tenantId, string editionId, string subscriptionId) { var tenant = _repository.GetById(tenantId); var currentSubscription = _subscriptionRepository.AsNoTracking().SingleOrDefault(x => x.Id == subscriptionId); var subscriptions = _subscriptionRepository.AsNoTracking() .Where(x => x.TenantId == tenantId && x.ExpireOn > DateTime.Today).ToList(); //int CurrentSubscriptionEquivalentDays(int convertibleDays, int convertibleAmount) //{ // return convertibleDays / (convertibleAmount * currentSubscription.NoOfShowroom) + 1; //} //int GetPackageDays(SubscriptionPackage package) //{ // int packageDays = 0; // if (package == SubscriptionPackage.Trial) packageDays = 14; // else if (package == SubscriptionPackage.Monthly) packageDays = 30; // else if (package == SubscriptionPackage.Quarter) packageDays = 365 / 4; // else if (package == SubscriptionPackage.HalfYearly) packageDays = 365 / 2; // else if (package == SubscriptionPackage.Annual) packageDays = 365; // return packageDays; //} var days = 0; foreach (var subscription in subscriptions) { if (subscription.ExpireOn.HasValue) { var convertibleDays = (subscription.ExpireOn.GetValueOrDefault() - DateTime.Today).Days; days += (convertibleDays * subscription.NoOfShowroom) / currentSubscription.NoOfShowroom + 1; } } tenant.SubscriptionEndTime = DateTime.Today.AddDays(days + 1).AddSeconds(-1); if (currentSubscription != null) { tenant.SubscriptionEndTime = currentSubscription.Package == SubscriptionPackage.LifeTime ? null : tenant.SubscriptionEndTime; tenant.SubscriptionId = currentSubscription.Id; tenant.NoOfShowroom = currentSubscription.NoOfShowroom; tenant.Package = currentSubscription.Package; } tenant.EditionId = editionId; tenant.IsInTrialPeriod = false; _repository.EditAsTenant(tenant); return(_repository.Commit()); }