public string CreateTenantCompany(string tenantId, string tenantName, string email, string phoneNumber)
        {
            var     id      = Guid.NewGuid().ToString();
            Company company = new Company()
            {
                Active     = true,
                Created    = DateTime.Now,
                CreatedBy  = null,
                Modified   = null,
                ModifiedBy = null,
                Id         = id,

                Name             = tenantName,
                TenantId         = tenantId,
                Email            = email,
                IsEmailConfirmed = false,
                IsPhoneConfirmed = false,
                Phone            = phoneNumber,
                Web = TenantHelper.GetTenantBaseUrl(tenantName.ToTenancyName())
            };

            _companyRepository.CreateAsHost(company);
            _companyRepository.Commit();

            CreateTenantCompanySettings(tenantId, company);

            return(id);
        }
Esempio n. 2
0
        public async Task ExecuteNotify()
        {
            using (var db = new BusinessDbContext())
            {
                var tenants = await db.Tenants.AsNoTracking()
                              .Where(x => x.IsActive && x.Active && !x.IsDeleted && x.SubscriptionEndTime >= DateTime.Today).ToListAsync();

                foreach (var tenant in tenants)
                {
                    var company = await db.Companies.AsNoTracking().FirstOrDefaultAsync(x => x.TenantId == tenant.Id);

                    if (company != null)
                    {
                        if (tenant.SubscriptionEndTime.HasValue)
                        {
                            var fiveDaysToExpire = tenant.SubscriptionEndTime.GetValueOrDefault().Date == DateTime.Today.AddDays(5);
                            var oneDayToExpire   = tenant.SubscriptionEndTime.GetValueOrDefault().Date == DateTime.Today.AddDays(1);
                            if (fiveDaysToExpire || oneDayToExpire)
                            {
                                string href = $"{TenantHelper.GetTenantBaseUrl(tenant.TenancyName)}/{StaticResource.Private.MultiTenant.ManageSubscription.Path.PrefixAngularHashUri()}";

                                string subject = oneDayToExpire
                                    ? $"Renew your subscription within tomorrow"
                                    : $"Your subscription will expire soon";
                                string body =
                                    $"Your subscription will expire on {tenant.SubscriptionEndTime: dd/MM/yyyy}. To continue with {AppSettings.ApplicationName.ToLower().RemoveSpace()} you need to renew or upgrade your subscription. <br/> You can upgrade to a new package or you can renew your existing subscription from <a href='{href}'>Manage Subscription</a><br/>.";


                                await _emailSender.SendSecurityEmailAsync(company.Email, company.Name, subject, body);

                                if (oneDayToExpire && company.IsPhoneConfirmed)
                                {
                                    _smsService.SendOneToOneSingleSmsUsingApi(company.Phone,
                                                                              SmsHelper.SubscriptionExpireMessage);
                                }
                            }
                        }
                    }
                }
            }
        }