private ITenantWorkspace CreateWorkspaceCore(Tenant tenant) { var connectionString = PersistenceHelper.GenerateConnectionString(tenant.Server, tenant.Database, tenant.UserName, tenant.Password); if (string.IsNullOrEmpty(tenant.Server) || string.IsNullOrEmpty(tenant.Database)) { connectionString = tenant.Name; } var context = new TenantDataContext(connectionString); var workspace = new EntityFrameworkTenantWorkspace(context); return(workspace); }
public void GetFranchiseeDataForUpdate(int labId, out FranchiseeTenant outfranchiseeTenant, out FranchiseeConfiguration outfranchiseeConfiguration) { outfranchiseeTenant = null; outfranchiseeConfiguration = null; outfranchiseeTenant = _franchiseeTenantRepository.GetById(labId); if (outfranchiseeTenant != null) { // change the connection var connectionString = PersistenceHelper.GenerateConnectionString(outfranchiseeTenant.Server, outfranchiseeTenant.Database, outfranchiseeTenant.UserName, outfranchiseeTenant.Password); _franchiseeConfigurationRepository.ChangeConnectionString(connectionString); outfranchiseeConfiguration = _franchiseeConfigurationRepository.FirstOrDefault(); } }
public BusinessRuleResult Execute(IEntity instance) { var failed = false; var franchisee = instance as Framework.DomainModel.Entities.FranchiseeTenant; var validationResult = new List <ValidationResult>(); // var franchiseeConfig = instance as Framework.DomainModel.Entities.FranchiseeConfiguration; if (franchisee != null) { if (string.IsNullOrEmpty(franchisee.Name)) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "Name"); validationResult.Add(new ValidationResult(mess)); failed = true; } else if (!string.IsNullOrEmpty(franchisee.Name) && _franchiseeTenantRepository.CheckExist(o => o.Name == franchisee.Name && o.Id != franchisee.Id)) { var mess = string.Format(SystemMessageLookup.GetMessage("ExistsTextResourceKey"), "Name"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (string.IsNullOrEmpty(franchisee.Address1)) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "Address 1"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (string.IsNullOrEmpty(franchisee.City)) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "City"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (string.IsNullOrEmpty(franchisee.State)) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "State"); validationResult.Add(new ValidationResult(mess)); failed = true; } int i = 0; if (string.IsNullOrEmpty(franchisee.Zip)) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "Zip"); validationResult.Add(new ValidationResult(mess)); failed = true; } else if (int.TryParse(franchisee.Zip, out i) == false) { var mess = string.Format(SystemMessageLookup.GetMessage("FieldInvalidText"), "Zip"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (string.IsNullOrEmpty(franchisee.OfficePhone)) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "Office Phone"); validationResult.Add(new ValidationResult(mess)); failed = true; } else if (franchisee.OfficePhone.Length < 10) { var mess = string.Format(SystemMessageLookup.GetMessage("PhoneValid"), "Office Phone"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (string.IsNullOrEmpty(franchisee.FaxNumber)) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "Fax Number"); validationResult.Add(new ValidationResult(mess)); failed = true; } else if (franchisee.FaxNumber.Length < 10) { var mess = string.Format(SystemMessageLookup.GetMessage("PhoneValid"), "Fax Number"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (string.IsNullOrEmpty(franchisee.Server)) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "Server"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (string.IsNullOrEmpty(franchisee.Database)) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "Database"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (string.IsNullOrEmpty(franchisee.UserName)) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "Username"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (string.IsNullOrEmpty(franchisee.Password)) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "Password"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (!string.IsNullOrEmpty(franchisee.LicenseKey) && _franchiseeTenantRepository.CheckExist( o => o.LicenseKey == franchisee.LicenseKey && o.Id != franchisee.Id)) { var mess = string.Format(SystemMessageLookup.GetMessage("ExistsTextResourceKey"), "License Key"); validationResult.Add(new ValidationResult(mess)); failed = true; } //Primary Contact if (string.IsNullOrEmpty(franchisee.FranchiseeContact)) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "Frachisee Contact"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (string.IsNullOrEmpty(franchisee.PrimaryContactPhone)) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "Phone"); validationResult.Add(new ValidationResult(mess)); failed = true; } else if (franchisee.PrimaryContactPhone.Length < 10 || franchisee.PrimaryContactPhone.Contains("_")) { var mess = string.Format(SystemMessageLookup.GetMessage("PhoneValid"), "Phone"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (!string.IsNullOrEmpty(franchisee.PrimaryContactEmail)) { if (Regex.IsMatch(franchisee.PrimaryContactEmail, "[A-Z]")) { var mess = string.Format(SystemMessageLookup.GetMessage("EmailValid"), "Email"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (!EmailValidateHelper.IsValidEmail(franchisee.PrimaryContactEmail)) { var mess = string.Format(SystemMessageLookup.GetMessage("EmailValid"), "Email"); validationResult.Add(new ValidationResult(mess)); failed = true; } } if (!string.IsNullOrEmpty(franchisee.PrimaryContactFax)) { if (franchisee.PrimaryContactFax.Length < 10 || franchisee.PrimaryContactFax.Contains("_")) { var mess = string.Format(SystemMessageLookup.GetMessage("PhoneValid"), "Fax"); validationResult.Add(new ValidationResult(mess)); failed = true; } } if (!string.IsNullOrEmpty(franchisee.PrimaryContactCellNumber)) { if (franchisee.PrimaryContactCellNumber.Length < 10 || franchisee.PrimaryContactCellNumber.Contains("_")) { var mess = string.Format(SystemMessageLookup.GetMessage("PhoneValid"), "Cell Number"); validationResult.Add(new ValidationResult(mess)); failed = true; } } //license key if (franchisee.StartActiveDate == null) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "Start Active Date"); validationResult.Add(new ValidationResult(mess)); failed = true; } else if (((DateTime)(franchisee.StartActiveDate)).Year == 1) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "Start Active Date"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (franchisee.EndActiveDate == null) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "End Active Date"); validationResult.Add(new ValidationResult(mess)); failed = true; } else if (((DateTime)(franchisee.EndActiveDate)).Year == 1) { var mess = string.Format(SystemMessageLookup.GetMessage("RequiredTextResourceKey"), "End Active Date"); validationResult.Add(new ValidationResult(mess)); failed = true; } if (franchisee.EndActiveDate != null && franchisee.StartActiveDate != null) { if (((DateTime)(franchisee.EndActiveDate)) < ((DateTime)(franchisee.StartActiveDate))) { var mess = string.Format(SystemMessageLookup.GetMessage("MustGreaterThan"), "End Active Date", "StartActiveDate"); validationResult.Add(new ValidationResult(mess)); failed = true; } } // Check connection string if (!string.IsNullOrEmpty(franchisee.Server) && !string.IsNullOrEmpty(franchisee.Database) && !string.IsNullOrEmpty(franchisee.UserName) && !string.IsNullOrEmpty(franchisee.Password)) { var connectionString = PersistenceHelper.GenerateConnectionString(franchisee.Server, franchisee.Database, franchisee.UserName, franchisee.Password); if (!_franchiseeTenantRepository.CheckConnectionString(connectionString)) { var mess = string.Format(SystemMessageLookup.GetMessage("ConnectionStringInvalid")); validationResult.Add(new ValidationResult(mess)); failed = true; } } var result = new BusinessRuleResult(failed, "", instance.GetType().Name, instance.Id, PropertyNames, Name) { ValidationResults = validationResult }; return(result); } return(new BusinessRuleResult()); }
public int SetupFranchisee(FranchiseeTenant franchiseeTenant, FranchiseeConfiguration franchiseeConfiguration) { using (var scope = new TransactionScope()) { //Add Franchise ValidateBusinessRules(franchiseeTenant); _franchiseeTenantRepository.Add(franchiseeTenant); _franchiseeTenantRepository.Commit(); int i = 0; var connectionString = PersistenceHelper.GenerateConnectionString(franchiseeTenant.Server, franchiseeTenant.Database, franchiseeTenant.UserName, franchiseeTenant.Password); var database = franchiseeTenant.Database; // Create franchisee configuaration // Check franchisee configuaration has exists #region _franchiseeConfigurationRepository.DeleteAllFranchiseeConfigurationBySqlString(database); var franchiseeId = PasswordHelper.HashString(franchiseeTenant.Id.ToString(), franchiseeTenant.Name); var licenseKey = franchiseeTenant.LicenseKey; var franchiseeContact = franchiseeConfiguration.FranchiseeContact; var primaryContactPhone = franchiseeConfiguration.PrimaryContactPhone; var primaryContactEmail = franchiseeConfiguration.PrimaryContactEmail; var primaryContactFax = franchiseeConfiguration.PrimaryContactFax; var primaryContactCellNumber = franchiseeConfiguration.PrimaryContactCellNumber; var name = franchiseeConfiguration.Name; var city = franchiseeConfiguration.City; var state = franchiseeConfiguration.State; var zip = franchiseeConfiguration.Zip; var address1 = franchiseeConfiguration.Address1; var address2 = franchiseeConfiguration.Address2; var officePhone = franchiseeConfiguration.OfficePhone; var faxNumber = franchiseeConfiguration.FaxNumber; var industryId = franchiseeConfiguration.IndustryId; var logo = franchiseeConfiguration.Logo; var franchiseeconfig = new FranchiseeConfiguration { FranchiseeId = franchiseeId, LicenseKey = licenseKey, FranchiseeContact = franchiseeContact, PrimaryContactPhone = primaryContactPhone, PrimaryContactEmail = primaryContactEmail, PrimaryContactFax = primaryContactFax, PrimaryContactCellNumber = primaryContactCellNumber, Name = name, City = city, State = state, Zip = zip, Address1 = address1, Address2 = address2, OfficePhone = officePhone, FaxNumber = faxNumber, Logo = logo, IndustryId = industryId }; _franchiseeConfigurationRepository.AddFranchiseeConfigurationBySqlString(franchiseeconfig, database); #endregion // Create a franchisee admin role #region _userRoleRepository.ChangeConnectionString(connectionString); var franchiseeAdminRole = _userRoleRepository.FirstOrDefault(o => o.AppRoleName == AppRole.GlobalAdmin.ToString()); var idFranchiseeAdminRole = 0; if (franchiseeAdminRole == null) { // Create franchisee admin role var franchiseeAdminRoleAdd = new UserRole { Name = "Franchisee Admin", AppRoleName = AppRole.GlobalAdmin.ToString(), UserRoleFunctions = new List <UserRoleFunction>() }; // Create list userRoleFunction for franchisee admin var objListDocumentType = _userRoleRepository.GetAllDocumentType(); foreach (var documentType in objListDocumentType) { var objViewAdd = new UserRoleFunction { DocumentTypeId = documentType.Id, SecurityOperationId = (int)OperationAction.View }; franchiseeAdminRoleAdd.UserRoleFunctions.Add(objViewAdd); //Implement View insert var objInsertAdd = new UserRoleFunction { DocumentTypeId = documentType.Id, SecurityOperationId = (int)OperationAction.Add, }; franchiseeAdminRoleAdd.UserRoleFunctions.Add(objInsertAdd); //Implement View update var objUpdateAdd = new UserRoleFunction { DocumentTypeId = documentType.Id, SecurityOperationId = (int)OperationAction.Update, }; franchiseeAdminRoleAdd.UserRoleFunctions.Add(objUpdateAdd); //Implement View delete var objDeleteAdd = new UserRoleFunction { DocumentTypeId = documentType.Id, SecurityOperationId = (int)OperationAction.Delete, }; franchiseeAdminRoleAdd.UserRoleFunctions.Add(objDeleteAdd); var objProcessAdd = new UserRoleFunction { DocumentTypeId = documentType.Id, SecurityOperationId = (int)OperationAction.Process, }; franchiseeAdminRoleAdd.UserRoleFunctions.Add(objProcessAdd); } _userRoleRepository.Add(franchiseeAdminRoleAdd); _userRoleRepository.Commit(); idFranchiseeAdminRole = franchiseeAdminRoleAdd.Id; } else { idFranchiseeAdminRole = franchiseeAdminRole.Id; } #endregion // Create franchisee admin user // Check user admin has exists #region _userRepository.ChangeConnectionString(connectionString); var isExistsUserFranchiseeAdmin = _userRepository.CheckExist(o => o.UserRoleId == idFranchiseeAdminRole); if (!isExistsUserFranchiseeAdmin) { var randomPassword = "******"; string username = franchiseeTenant.Name.Replace(" ", ""); var password = PasswordHelper.HashString(randomPassword, username); var phoneNumber = franchiseeConfiguration.PrimaryContactPhone; // "1111111111"; var email = franchiseeConfiguration.PrimaryContactEmail; // "*****@*****.**"; var cellPhone = franchiseeConfiguration.PrimaryContactCellNumber; // "1111111111"; // Create user franchisee admin var userFranchiseeAdmin = new User { UserName = username, Password = password, UserRoleId = idFranchiseeAdminRole, IsActive = true, FirstName = "Admin", LastName = "Franchisee", HomePhone = phoneNumber, MobilePhone = cellPhone, Email = email, }; _userRepository.AddUserBySqlString(userFranchiseeAdmin, database); } #endregion scope.Complete(); return(franchiseeTenant.Id); } }
public byte[] UpdateFranchisee(FranchiseeTenant franchiseeTenant, FranchiseeConfiguration franchiseeConfiguration) { using (var scope = new TransactionScope()) { ValidateBusinessRules(franchiseeTenant); _franchiseeTenantRepository.Update(franchiseeTenant); _franchiseeTenantRepository.Commit(); // change the connection var connectionString = PersistenceHelper.GenerateConnectionString(franchiseeTenant.Server, franchiseeTenant.Database, franchiseeTenant.UserName, franchiseeTenant.Password); var database = franchiseeTenant.Database; _franchiseeConfigurationRepository.ChangeConnectionString(connectionString); _franchiseeConfigurationRepository.DeleteAllFranchiseeConfigurationBySqlString(database); // Create franchisee configuaration //Add new Franchisee Configuration var franchiseeId = PasswordHelper.HashString(franchiseeTenant.Id.ToString(), franchiseeTenant.Name); var licenseKey = franchiseeTenant.LicenseKey; var franchiseeContact = franchiseeConfiguration.FranchiseeContact; var primaryContactPhone = franchiseeConfiguration.PrimaryContactPhone; var primaryContactEmail = franchiseeConfiguration.PrimaryContactEmail; var primaryContactFax = franchiseeConfiguration.PrimaryContactFax; var primaryContactCellNumber = franchiseeConfiguration.PrimaryContactCellNumber; var name = franchiseeConfiguration.Name; var city = franchiseeConfiguration.City; var state = franchiseeConfiguration.State; var zip = franchiseeConfiguration.Zip; var address1 = franchiseeConfiguration.Address1; var address2 = franchiseeConfiguration.Address2; var officePhone = franchiseeConfiguration.OfficePhone; var faxNumber = franchiseeConfiguration.FaxNumber; var logo = franchiseeConfiguration.Logo; var industryId = franchiseeConfiguration.IndustryId; var franchiseeconfig = new FranchiseeConfiguration { FranchiseeId = franchiseeId, LicenseKey = licenseKey, FranchiseeContact = franchiseeContact, PrimaryContactPhone = primaryContactPhone, PrimaryContactEmail = primaryContactEmail, PrimaryContactFax = primaryContactFax, PrimaryContactCellNumber = primaryContactCellNumber, Name = name, City = city, State = state, Zip = zip, Address1 = address1, Address2 = address2, OfficePhone = officePhone, FaxNumber = faxNumber, Logo = logo, IndustryId = industryId }; _franchiseeConfigurationRepository.AddFranchiseeConfigurationBySqlString(franchiseeconfig, database); scope.Complete(); return(franchiseeTenant.LastModified); } }