├── .gitattributes ├── .gitignore ├── ConsoleTests ├── App.config ├── ConsoleTests.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── IoCContainers ├── MultiTenancyFramework.SimpleInjector │ ├── BaseContainer.cs │ ├── MultiTenancyFramework.SimpleInjector.csproj │ ├── MultiTenancyFramework.SimpleInjector.nuspec │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config └── MultiTenancyFramework.Unity │ ├── BaseContainer.cs │ ├── MultiTenancyFramework.Unity.csproj │ ├── Properties │ └── AssemblyInfo.cs │ └── packages.config ├── MVC5 ├── MultiTenancyFramework.Mvc.Core │ ├── Alert.cs │ ├── AllowAccessToParentAttribute.cs │ ├── DisplayHintAttribute.cs │ ├── Extensions │ │ ├── AreaRegistrationContextExtensions.cs │ │ ├── HtmlHelperExtensions.cs │ │ ├── MvcFormExtension.cs │ │ ├── RouteCollectionExtensions.cs │ │ └── UrlHelperExtensions.cs │ ├── IModelAttribute.cs │ ├── KeepAliveController.cs │ ├── KeepAliveFilter.cs │ ├── LowerCaseRoute.cs │ ├── MultiTenancyFramework.Mvc.Core.csproj │ ├── MultiTenancyFramework.Mvc.Core.nuspec │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── TrimModelBinder.cs │ ├── UsernameAndPasswordRule.cs │ ├── ValidateAntiForgeryTokenOnPost.cs │ ├── ValidateUsingPrivilegeForActionAttribute.cs │ ├── ViewNotFoundException.cs │ └── packages.config ├── MultiTenancyFramework.Mvc.NHibernate │ ├── EndRequestFilter.cs │ ├── Maps │ │ └── ActionAccessPrivilegeMap.cs │ ├── MultiTenancyFramework.Mvc.NHibernate.csproj │ ├── MultiTenancyFramework.Mvc.NHibernate.nuspec │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Queries │ │ ├── GetActionAccessPrivilegesByGridSearchParamsQueryHandler.cs │ │ ├── GetActionsQueryHandler.cs │ │ ├── GetAreasQueryHandler.cs │ │ ├── GetControllersQueryHandler.cs │ │ └── GetUsersWithThesePrivilegesQueryHandler.cs │ ├── RegisterAssemblyHttpModule.cs │ ├── app.config │ ├── packages.config │ ├── readme.txt │ └── web.config.transform └── MultiTenancyFramework.Mvc │ ├── BaseMvcHttpApplication.cs │ ├── Data │ └── Queries │ │ ├── GetActionAccessPrivilegesByGridSearchParamsQuery.cs │ │ ├── GetActionsQuery.cs │ │ ├── GetAreasQuery.cs │ │ ├── GetControllersQuery.cs │ │ └── GetUsersWithThesePrivilegesQuery.cs │ ├── EmailMessage.cs │ ├── EmailService.cs │ ├── Entities │ ├── ActionAccessPrivilege.cs │ ├── IdentityUser.cs │ └── InstitutionAccessValidationResult.cs │ ├── Extensions │ ├── EntityExtensionsMvc.cs │ ├── IIdentityExtensions.cs │ ├── IOExtensions.cs │ └── MvcExtensions.cs │ ├── IO │ ├── ExcelWriter.cs │ ├── PropertyByName.cs │ └── PropertyManager.cs │ ├── Identity │ ├── ApplicationSignInManager.cs │ ├── ApplicationUserManager.cs │ ├── MultiTenancyFrameworkSettings.cs │ ├── SystemWebCookieManager.cs │ └── UserStore.cs │ ├── Logic │ ├── ActionAccessPrivilegeLogic.cs │ ├── AuditLogLogic.cs │ └── DataCacheMVC.cs │ ├── MultiTenancyFramework.Mvc.csproj │ ├── MultiTenancyFramework.Mvc.nuspec │ ├── MvcUtils │ ├── AppStartInitializer.cs │ ├── CoreController.cs │ ├── EndRequestFilter.cs │ ├── ErrorController.cs │ ├── ErrorMessageModel.cs │ ├── GlobalAuthorizeAttribute.cs │ ├── GlobalExceptionFilterAttribute.cs │ ├── InstitutionFilterConfig.cs │ ├── InstitutionRouteConfig.cs │ ├── MvcUtility.cs │ ├── MyModelMetadataProvider.cs │ ├── MyRazorViewEngine.cs │ ├── ReLoginModel.cs │ ├── ScheduledTaskApiController.cs │ ├── ValidateUsingPrivilegeForActionAttribute.cs │ └── WebHelper.cs │ ├── MyMvcServiceLocator.cs │ ├── PerRequestCacheManager.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── SmsService.cs │ ├── WebUtilities.cs │ ├── app.config │ └── packages.config ├── MultiTenancyFramework.Core.Test ├── Class1.cs ├── MultiTenancyFramework.Core.Test.csproj ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── MultiTenancyFramework.Core ├── Attributes │ ├── CompositeMappingModifyFieldNamesAttribute.cs │ └── IgnoreInAuditLogAttribute.cs ├── Commands │ ├── BaseCommand.cs │ ├── CommandProcessor.cs │ ├── ICommand.cs │ ├── ICommandHandler.cs │ └── ICommandProcessor.cs ├── Data │ ├── IAppUserDAO.cs │ ├── ICoreDAO.BulkInsert.cs │ ├── ICoreDAO.General.cs │ ├── ICoreDAO.Reads.cs │ ├── ICoreDAO.ReadsAsync.cs │ ├── ICoreDAO.UnitOfWork.cs │ ├── ICoreDAO.Writes.cs │ ├── ICoreDAO.cs │ ├── ICoreGridPagingDAO.cs │ ├── IDataInitializer.cs │ ├── IDbSessionCleanup.cs │ ├── IInstitutionDAO.cs │ ├── IPrivilegeDAO.cs │ ├── MyDataColumn.cs │ ├── MyDataRow.cs │ ├── MyDataTable.cs │ ├── Queries │ │ ├── DbPagingQuery.cs │ │ ├── DbQueryProcessor.cs │ │ ├── GetAppUserByUserRoleQuery.cs │ │ ├── GetAppUserByUsernameQuery.cs │ │ ├── GetAppUsersByGridSearchParamsQuery.cs │ │ ├── GetDatabaseConnectionByNameAndConnectionStringQuery.cs │ │ ├── GetEntitiesAppearingInAuditLogsQuery.cs │ │ ├── GetIAppUserByEmailQuery.cs │ │ ├── GetInstitutionByCodeQuery.cs │ │ ├── GetPhotosByOwnerIdAndImageTypeQuery.cs │ │ ├── GetPrivilegesByGridSearchParamsQuery.cs │ │ ├── GetUserClaimsByUserIdQuery.cs │ │ ├── GetUserLoginByLoginProviderKeyAndUserIdQuery.cs │ │ ├── GetUserLoginsByUserIdQuery.cs │ │ ├── GetUserRoleByNameQuery.cs │ │ ├── IDbQuery.cs │ │ ├── IDbQueryHandler.cs │ │ └── IDbQueryProcessor.cs │ └── RetrievedData.cs ├── Entities │ ├── AppUser.cs │ ├── AuditLog.cs │ ├── DatabaseConnection.cs │ ├── EmailAndSmtpSetting.cs │ ├── Entity.cs │ ├── IAmHostedCentrally.cs │ ├── IDoNotNeedAudit.cs │ ├── IEntity.cs │ ├── Institution.cs │ ├── Log.cs │ ├── Person.cs │ ├── Photo.cs │ ├── Privilege.cs │ ├── SystemSetting.cs │ ├── TrailItem.cs │ ├── UserClaim.cs │ ├── UserLogin.cs │ ├── UserRole.cs │ └── UsernameAndPasswordRule.cs ├── Enums.cs ├── Exceptions │ ├── ForceChangeOfPasswordException.cs │ ├── GeneralException.cs │ └── LogOutUserException.cs ├── Extensions │ ├── EntityExtensions.cs │ ├── ExceptionExtensions.cs │ ├── FileExportExtensions.cs │ ├── IEnumerableExtensions.cs │ ├── IIdentityExtensions.cs │ ├── MvcExtensions.cs │ ├── OtherExtensions.cs │ └── ReflectionExtensions.cs ├── IO │ ├── CsvWriter.cs │ └── IOManager.cs ├── IoC │ └── IoCUtility.cs ├── Logic │ ├── AppUserLogic.cs │ ├── CoreBaseLogic.cs │ ├── CoreLogic.Async.cs │ ├── CoreLogic.cs │ ├── IAuditTrailLogger.cs │ ├── LogLogic.cs │ ├── SystemSettingLogic.cs │ ├── UserClaimLogic.cs │ ├── UserLoginLogic.cs │ └── UserRoleLogic.cs ├── MultiTenancyFramework.Core.csproj ├── MultiTenancyFramework.Core.nuspec ├── NLog.config ├── NLog.xsd ├── Properties │ └── AssemblyInfo.cs ├── TaskManager │ ├── GetTaskByTypeQuery.cs │ ├── ScheduledTask.cs │ ├── ScheduledTaskEngine.cs │ ├── ScheduledTaskManager.cs │ ├── ScheduledTaskRunner.cs │ ├── TaskThread.cs │ └── Tasks │ │ ├── ClearLogTask.cs │ │ ├── EmailAccount.cs │ │ ├── EmailAccountLogic.cs │ │ ├── IRunnableTask.cs │ │ ├── KeepAliveTask.cs │ │ ├── QueuedEmail.cs │ │ ├── QueuedEmailLogic.cs │ │ ├── QueuedMessagesSendTask.cs │ │ └── SearchQueuedEmailsQuery.cs ├── Utility │ ├── CacheTest.cs │ ├── CommonHelper.cs │ ├── EmailSender.cs │ ├── Emailer.cs │ ├── IPResolver.cs │ ├── Logger.cs │ ├── LoggerConfigurationManager.cs │ ├── SimpleWebHelper.cs │ └── Utilities.cs ├── app.config.install.xdt ├── app.config.transform ├── app.config.uninstall.xdt ├── packages.config ├── web.config.install.xdt ├── web.config.transform └── web.config.uninstall.xdt ├── MultiTenancyFramework.CoreTests ├── Extensions │ └── OtherExtensionsTests.cs ├── MultiTenancyFramework.CoreTests.csproj ├── Properties │ └── AssemblyInfo.cs ├── Utility │ └── EmailerTests.cs └── packages.config ├── MultiTenancyFramework.NHibernate ├── AppUserDAO.cs ├── Audit │ ├── AuditLogSerializer.cs │ ├── GlobalTrackingConfig.cs │ ├── PropertyConfigKey.cs │ ├── PropertyTracking.cs │ └── TrackingDataStore.cs ├── CoreDAO.ReadsAsync.cs ├── CoreDAO.cs ├── CoreGeneralDAO.cs ├── CoreGeneralWithGridPagingDAO.cs ├── CoreGridPagingDAO.cs ├── DataInitializer.cs ├── InstitutionDAO.cs ├── Maps │ ├── AuditLogMap.cs │ ├── EntityMap.cs │ ├── IdentityUserMap.cs │ ├── InstitutionMap.cs │ ├── NHMapsExtensions.cs │ ├── PersonMap.cs │ ├── PrivilegeMap.cs │ ├── SystemSettingMap.cs │ └── UserRoleMap.cs ├── MultiTenancyFramework.NHibernate.csproj ├── MultiTenancyFramework.NHibernate.nuspec ├── NHManager │ ├── AutomappingConfiguration.cs │ ├── Conventions │ │ ├── ClassMappingConvention.cs │ │ ├── EnumMappingConvention.cs │ │ ├── InstitutionCodePropertyConvention.cs │ │ └── ReferencesConvention.cs │ ├── DbSessionCleanup.cs │ ├── ISessionStorage.cs │ ├── Listeners │ │ ├── AppFilterDefinition.cs │ │ ├── AuditLogEventListener.cs │ │ └── MySqlExceptionConverter.cs │ ├── NHSessionHttpModule.cs │ ├── NHSessionManager.cs │ ├── NonWebSessionStorage.cs │ └── WebSessionStorage.cs ├── NHUtils.cs ├── NhNLogImpl.cs ├── PrivilegeDAO.cs ├── Properties │ └── AssemblyInfo.cs ├── Queries │ ├── GetAppUserByUserRoleQueryHandler.cs │ ├── GetAppUserByUsernameQueryHandler.cs │ ├── GetAppUsersByGridSearchParamsQueryHandler.cs │ ├── GetDatabaseConnectionByNameAndConnectionStringQueryHandler.cs │ ├── GetEntitiesAppearingInAuditLogsQueryHandler.cs │ ├── GetIAppUserByEmailQueryHandler.cs │ ├── GetInstitutionByCodeQueryHandler.cs │ ├── GetPhotosByOwnerIdAndImageTypeQueryHandler.cs │ ├── GetPrivilegesByGridSearchParamsQueryHandler.cs │ ├── GetUserClaimsByUserIdQueryHandler.cs │ ├── GetUserLoginByLoginProviderKeyAndUserIdQueryHandler.cs │ ├── GetUserLoginssByUserIdQueryHandler.cs │ └── GetUserRoleByNameQueryHandler.cs ├── SqlManipulations.cs ├── TaskManager │ ├── GetTaskByTypeQueryHandler.cs │ ├── ScheduleTaskMap.cs │ ├── SearchQueuedEmailsQueryHandler.cs │ └── Tasks │ │ ├── LogMap.cs │ │ └── QueuedEmailMap.cs ├── app.config ├── app.config.install.xdt ├── app.config.transform ├── app.config.uninstall.xdt ├── packages.config ├── web.config.install.xdt ├── web.config.transform └── web.config.uninstall.xdt ├── MultiTenancyFramework.Utils ├── Caching │ ├── ICacheManager.cs │ ├── MemoryCacheManager.cs │ └── NopNullCache.cs ├── EnumDescriptionAttribute.cs ├── Extensions │ ├── CacheExtensions.cs │ ├── DateTimeExtensions.cs │ ├── IEnumerableExtensions.cs │ ├── IQueryableExtensions.cs │ ├── NumberExtensions.cs │ ├── OtherExtensions.cs │ ├── ReflectionExtensions.cs │ └── StringExtensions.cs ├── MultiTenancyFramework.Utils.csproj ├── MultiTenancyFramework.Utils.nuspec ├── Properties │ └── AssemblyInfo.cs └── Utility │ ├── AppDomainTypeFinder.cs │ ├── AsyncHelper.cs │ ├── BackgroundTaskRunner.cs │ ├── CacheTest.cs │ ├── ConfigurationHelper.cs │ ├── EnumHelper.cs │ ├── ILogger.cs │ └── MyServiceLocator.cs ├── MultiTenancyFramework.sln ├── README.md ├── SolutionItems ├── ArchitectureDiagram.odg └── SolutionArchitecture.PNG ├── Tests └── MultiTenancyFramework.Core.Tests │ ├── Class1.cs │ ├── Extensions │ ├── NumberExtensionsTests.cs │ ├── OtherExtensionsTests.cs │ ├── ReflectionExtensionsTests.cs │ └── StringExtensionsTests.cs │ ├── MultiTenancyFramework.Core.Tests.csproj │ ├── Properties │ └── AssemblyInfo.cs │ ├── Utility │ └── EmailerTests.cs │ └── packages.config ├── WebAPI └── MultiTenancyFramework.WebAPI │ ├── GlobalAuthorizeAttribute.cs │ ├── GlobalExceptionFilterAttribute.cs │ ├── GlobalExceptionHandler.cs │ ├── GlobalExceptionLogger.cs │ ├── GlobalWebApiConfig.cs │ ├── GlobalWebApiRoutesConfig.cs │ ├── MultiTenancyFramework.WebAPI.csproj │ ├── PreAndPostActionHandler.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── app.config │ └── packages.config ├── WebApiTest ├── App_Start │ ├── BundleConfig.cs │ ├── FilterConfig.cs │ ├── IdentityConfig.cs │ ├── RouteConfig.cs │ ├── Startup.Auth.cs │ └── WebApiConfig.cs ├── Areas │ └── HelpPage │ │ ├── ApiDescriptionExtensions.cs │ │ ├── App_Start │ │ └── HelpPageConfig.cs │ │ ├── Controllers │ │ └── HelpController.cs │ │ ├── HelpPage.css │ │ ├── HelpPageAreaRegistration.cs │ │ ├── HelpPageConfigurationExtensions.cs │ │ ├── ModelDescriptions │ │ ├── CollectionModelDescription.cs │ │ ├── ComplexTypeModelDescription.cs │ │ ├── DictionaryModelDescription.cs │ │ ├── EnumTypeModelDescription.cs │ │ ├── EnumValueDescription.cs │ │ ├── IModelDocumentationProvider.cs │ │ ├── KeyValuePairModelDescription.cs │ │ ├── ModelDescription.cs │ │ ├── ModelDescriptionGenerator.cs │ │ ├── ModelNameAttribute.cs │ │ ├── ModelNameHelper.cs │ │ ├── ParameterAnnotation.cs │ │ ├── ParameterDescription.cs │ │ └── SimpleTypeModelDescription.cs │ │ ├── Models │ │ └── HelpPageApiModel.cs │ │ ├── SampleGeneration │ │ ├── HelpPageSampleGenerator.cs │ │ ├── HelpPageSampleKey.cs │ │ ├── ImageSample.cs │ │ ├── InvalidSample.cs │ │ ├── ObjectGenerator.cs │ │ ├── SampleDirection.cs │ │ └── TextSample.cs │ │ ├── Views │ │ ├── Help │ │ │ ├── Api.cshtml │ │ │ ├── DisplayTemplates │ │ │ │ ├── ApiGroup.cshtml │ │ │ │ ├── CollectionModelDescription.cshtml │ │ │ │ ├── ComplexTypeModelDescription.cshtml │ │ │ │ ├── DictionaryModelDescription.cshtml │ │ │ │ ├── EnumTypeModelDescription.cshtml │ │ │ │ ├── HelpPageApiModel.cshtml │ │ │ │ ├── ImageSample.cshtml │ │ │ │ ├── InvalidSample.cshtml │ │ │ │ ├── KeyValuePairModelDescription.cshtml │ │ │ │ ├── ModelDescriptionLink.cshtml │ │ │ │ ├── Parameters.cshtml │ │ │ │ ├── Samples.cshtml │ │ │ │ ├── SimpleTypeModelDescription.cshtml │ │ │ │ └── TextSample.cshtml │ │ │ ├── Index.cshtml │ │ │ └── ResourceModel.cshtml │ │ ├── Shared │ │ │ └── _Layout.cshtml │ │ ├── Web.config │ │ └── _ViewStart.cshtml │ │ └── XmlDocumentationProvider.cs ├── Content │ ├── Site.css │ ├── bootstrap-theme.css │ ├── bootstrap-theme.css.map │ ├── bootstrap-theme.min.css │ ├── bootstrap-theme.min.css.map │ ├── bootstrap.css │ ├── bootstrap.css.map │ ├── bootstrap.min.css │ └── bootstrap.min.css.map ├── Controllers │ ├── AccountController.cs │ ├── HomeController.cs │ └── ValuesController.cs ├── Global.asax ├── Global.asax.cs ├── Models │ ├── AccountBindingModels.cs │ ├── AccountViewModels.cs │ └── IdentityModels.cs ├── Project_Readme.html ├── Properties │ └── AssemblyInfo.cs ├── Providers │ └── ApplicationOAuthProvider.cs ├── Results │ └── ChallengeResult.cs ├── Scripts │ ├── _references.js │ ├── bootstrap.js │ ├── bootstrap.min.js │ ├── jquery-1.10.2.intellisense.js │ ├── jquery-3.1.1.intellisense.js │ ├── jquery-3.1.1.js │ ├── jquery-3.1.1.min.js │ ├── jquery-3.1.1.min.map │ ├── jquery-3.1.1.slim.js │ ├── jquery-3.1.1.slim.min.js │ ├── jquery-3.1.1.slim.min.map │ ├── jquery.validate-vsdoc.js │ ├── jquery.validate.js │ ├── jquery.validate.min.js │ ├── jquery.validate.unobtrusive.js │ ├── jquery.validate.unobtrusive.min.js │ ├── modernizr-2.6.2.js │ ├── modernizr-2.8.3.js │ ├── respond.js │ ├── respond.matchmedia.addListener.js │ ├── respond.matchmedia.addListener.min.js │ └── respond.min.js ├── Startup.cs ├── Views │ ├── Home │ │ └── Index.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ └── _Layout.cshtml │ ├── Web.config │ └── _ViewStart.cshtml ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── WebApiTest.csproj ├── favicon.ico ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 └── packages.config ├── WebTests ├── 404.html ├── 500.html ├── App_Start │ ├── NHibernateProfilerBootstrapper.cs │ ├── RouteConfig.cs │ └── Startup.Auth.cs ├── Areas │ └── Samples │ │ ├── SamplesAreaRegistration.cs │ │ └── Views │ │ └── web.config ├── Content │ ├── Site.css │ ├── bootstrap-theme.css │ ├── bootstrap-theme.css.map │ ├── bootstrap-theme.min.css │ ├── bootstrap-theme.min.css.map │ ├── bootstrap.css │ ├── bootstrap.css.map │ ├── bootstrap.min.css │ └── bootstrap.min.css.map ├── Controllers │ └── HomeController.cs ├── Global.asax ├── Global.asax.cs ├── LoggingConfig.xml ├── Properties │ └── AssemblyInfo.cs ├── Scripts │ ├── bootstrap.js │ ├── bootstrap.min.js │ ├── jquery-3.1.1.intellisense.js │ ├── jquery-3.1.1.js │ ├── jquery-3.1.1.min.js │ ├── jquery-3.1.1.min.map │ ├── jquery-3.1.1.slim.js │ ├── jquery-3.1.1.slim.min.js │ ├── jquery-3.1.1.slim.min.map │ └── modernizr-2.8.3.js ├── Startup.cs ├── Views │ ├── Home │ │ └── Index.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ └── _Layout.cshtml │ ├── _ViewStart.cshtml │ └── web.config ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── WebTests.csproj ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 └── packages.config └── WebTestsNuget ├── App_Start └── RouteConfig.cs ├── Global.asax ├── Global.asax.cs ├── Properties └── AssemblyInfo.cs ├── Views └── web.config ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── WebTestsNuget.csproj ├── packages.config └── readme.txt /ConsoleTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("ConsoleTests")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("ConsoleTests")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("a32a9e74-3af6-4adf-9e31-edff25be049a")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /ConsoleTests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /IoCContainers/MultiTenancyFramework.SimpleInjector/MultiTenancyFramework.SimpleInjector.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | 1.1.0.0 6 | $title$ 7 | $author$ 8 | $author$ 9 | http://codedrum.blogspot.com/2016/08/MultiTenancyFramework.html 10 | false 11 | $description$ 12 | Read more at https://github.com/smbadiwe/MultiTenancyFramework/wiki. Drop a note if need be. 13 | $copyright$ 14 | SaaS MultiTenant MultiTenancy Framework Software-as-a-Service IoC SimpleInjector 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /IoCContainers/MultiTenancyFramework.SimpleInjector/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /IoCContainers/MultiTenancyFramework.Unity/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.Core/Alert.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Mvc 2 | { 3 | /// 4 | /// Represents alert messages for MVC 5 | /// 6 | public class Alert 7 | { 8 | public const string TempDataKey = "TempDataAlerts"; 9 | 10 | public string AlertStyle { get; set; } 11 | public string Message { get; set; } 12 | public bool Dismissable { get; set; } 13 | } 14 | 15 | /// 16 | /// Boootstrap alert styles 17 | /// 18 | public static class AlertStyles 19 | { 20 | public const string Success = "success"; 21 | public const string Information = "info"; 22 | public const string Warning = "warning"; 23 | public const string Danger = "danger"; 24 | } 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.Core/AllowAccessToParentAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MultiTenancyFramework.Mvc 4 | { 5 | /// 6 | /// When institution code indicates that the parent (central) institution is accessing the action, 7 | /// we use this to check whether or not the central institution can access the action. 8 | /// Use this on actions and/or controllers. This is only triggered if action or controller is not anonymous. 9 | /// Our default is to assume most of the actions can be accessed by tenants only; but we know there are a few 10 | /// that should be availabe to both tenants and Core. Normally we use privileges and roles to control what a user can access; this is just an extra level of enforcement 11 | /// 12 | /// 13 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] 14 | public class AllowAccessToParentAttribute : Attribute 15 | { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.Core/DisplayHintAttribute.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | 4 | namespace MultiTenancyFramework.Mvc 5 | { 6 | /// 7 | /// Initializes a new instance of the class, supplying both hint and a display name for the model. 8 | /// 9 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] 10 | public class DisplayHintAttribute : Attribute, IModelAttribute 11 | { 12 | /// 13 | /// Initializes a new instance of the class, supplying both hint and a display name for the model. 14 | /// 15 | /// The hint. 16 | public DisplayHintAttribute(string hint) 17 | { 18 | Hint = hint; 19 | } 20 | 21 | public string Hint { get; set; } 22 | 23 | public string Name 24 | { 25 | get { return "DisplayHintAttribute"; } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.Core/IModelAttribute.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace MultiTenancyFramework.Mvc 3 | { 4 | public interface IModelAttribute 5 | { 6 | string Name { get; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.Core/KeepAliveController.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace MultiTenancyFramework.Mvc 4 | { 5 | /// 6 | /// A scheduled task calls this keepalive/index to, you know, keep the app alive. 7 | /// 8 | /// 9 | [AllowAnonymous] 10 | public class KeepAliveController : Controller 11 | { 12 | public virtual ActionResult Index() 13 | { 14 | return new EmptyResult(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.Core/KeepAliveFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Web.Mvc; 3 | 4 | namespace MultiTenancyFramework.Mvc 5 | { 6 | public class KeepAliveFilter : IActionFilter 7 | { 8 | public string UrlPath { get; set; } 9 | public KeepAliveFilter(string urlPath = "keepalive/index") 10 | { 11 | UrlPath = urlPath; 12 | } 13 | public void OnActionExecuting(ActionExecutingContext filterContext) 14 | { 15 | if (filterContext.HttpContext.Request.RawUrl.Contains(UrlPath)) 16 | { 17 | filterContext.Result = new EmptyResult(); 18 | } 19 | } 20 | 21 | public void OnActionExecuted(ActionExecutedContext filterContext) 22 | { 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.Core/MultiTenancyFramework.Mvc.Core.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $id$ 5 | 1.1.0.0 6 | $title$ 7 | $author$ 8 | $author$ 9 | http://codedrum.blogspot.com/2016/08/MultiTenancyFramework.html 10 | false 11 | $description$ 12 | Read more at https://github.com/smbadiwe/MultiTenancyFramework/wiki. Drop a note if need be. 13 | $copyright$ 14 | SaaS MultiTenant MultiTenancy Framework Software-as-a-Service 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.Core/TrimModelBinder.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace MultiTenancyFramework.Mvc 4 | { 5 | public class TrimModelBinder : IModelBinder 6 | { 7 | public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) 8 | { 9 | // First check if request validation is required 10 | var shouldPerformRequestValidation = controllerContext.Controller.ValidateRequest 11 | && bindingContext.ModelMetadata.RequestValidationEnabled; 12 | 13 | var unvalidatedValueProvider = bindingContext.ValueProvider as IUnvalidatedValueProvider; 14 | var value = (unvalidatedValueProvider != null) 15 | ? unvalidatedValueProvider.GetValue(bindingContext.ModelName, !shouldPerformRequestValidation) 16 | : bindingContext.ValueProvider.GetValue(bindingContext.ModelName); 17 | 18 | var attemptedValue = value?.AttemptedValue?.Trim(); 19 | 20 | return attemptedValue; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.Core/ValidateAntiForgeryTokenOnPost.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Web.Helpers; 4 | using System.Web.Mvc; 5 | 6 | namespace MultiTenancyFramework.Mvc 7 | { 8 | public class ValidateAntiForgeryTokenOnPost : FilterAttribute, IAuthorizationFilter 9 | { 10 | public virtual void OnAuthorization(AuthorizationContext filterContext) 11 | { 12 | if (filterContext.HttpContext.Request.HttpMethod.Equals("POST", StringComparison.OrdinalIgnoreCase)) 13 | { 14 | try 15 | { 16 | var ignoreToken = filterContext.ActionDescriptor.GetCustomAttributes(typeof(IgnoreAntiForgeryTokenAttribute), true) 17 | .Cast().FirstOrDefault(); 18 | if (ignoreToken == null) 19 | { 20 | AntiForgery.Validate(); 21 | } 22 | } 23 | catch (HttpAntiForgeryException) 24 | { 25 | if (filterContext.RequestContext.HttpContext.Request.IsAuthenticated) 26 | { 27 | throw; 28 | } 29 | } 30 | } 31 | } 32 | } 33 | 34 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 35 | public class IgnoreAntiForgeryTokenAttribute : Attribute 36 | { 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.Core/ValidateUsingPrivilegeForActionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MultiTenancyFramework.MvcUtils //Attributes 4 | { 5 | /// 6 | /// MVC-specific; when two or more actions share the same privilege, point the actions to one using this attribute 7 | /// 8 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 9 | public class ValidateUsingPrivilegeForActionAttribute : Attribute 10 | { 11 | private string _actionNames; 12 | public string[] ActionNames 13 | { 14 | get 15 | { 16 | return _actionNames.Split(','); 17 | } 18 | } 19 | 20 | /// 21 | /// 22 | /// 23 | /// Comma-separated list of the relevant action names 24 | public ValidateUsingPrivilegeForActionAttribute(string actionNames) 25 | { 26 | if (string.IsNullOrWhiteSpace(actionNames)) throw new ArgumentNullException(actionNames); 27 | _actionNames = actionNames; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.Core/ViewNotFoundException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MultiTenancyFramework.Mvc 4 | { 5 | /// 6 | /// Throw this when view (.cshtml) file is not found 7 | /// 8 | /// 9 | public class ViewNotFoundException : InvalidOperationException 10 | { 11 | public ViewNotFoundException(string virtualPath) : base(virtualPath + " could not be found") 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.Core/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.NHibernate/Maps/ActionAccessPrivilegeMap.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | using MultiTenancyFramework.NHibernate.Maps; 3 | 4 | namespace MultiTenancyFramework.Mvc.NHibernate.Maps 5 | { 6 | public class ActionAccessPrivilegeMap : PrivilegeMap 7 | { 8 | public ActionAccessPrivilegeMap() 9 | { 10 | Map(x => x.Action); 11 | Map(x => x.Controller); 12 | Map(x => x.Area); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.NHibernate/MultiTenancyFramework.Mvc.NHibernate.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | 1.1.0.0 6 | $title$ 7 | $author$ 8 | $author$ 9 | http://codedrum.blogspot.com/2016/08/MultiTenancyFramework.html 10 | false 11 | $description$ 12 | Read more at https://github.com/smbadiwe/MultiTenancyFramework/wiki. Drop a note if need be. 13 | $copyright$ 14 | SaaS MultiTenant MultiTenancy Framework Software-as-a-Service MVC5 NHibernate FluentNHibernate 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.NHibernate/Queries/GetActionAccessPrivilegesByGridSearchParamsQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using MultiTenancyFramework.Data.Queries; 3 | using MultiTenancyFramework.Entities; 4 | using NHibernate.Criterion; 5 | 6 | namespace MultiTenancyFramework.NHibernate.Queries 7 | { 8 | public class GetActionAccessPrivilegesByGridSearchParamsQueryHandler : CoreGeneralWithGridPagingDAO, IDbQueryHandler> 9 | { 10 | public RetrievedData Handle(GetActionAccessPrivilegesByGridSearchParamsQuery theQuery) 11 | { 12 | var session = BuildSession(); 13 | var query = session.QueryOver(); 14 | if (!string.IsNullOrWhiteSpace(theQuery.Name)) 15 | { 16 | query = query.Where(x => x.DisplayName.IsInsensitiveLike(theQuery.Name, MatchMode.Anywhere) 17 | || x.Name.IsInsensitiveLike(theQuery.Name, MatchMode.Anywhere)); 18 | } 19 | if (theQuery.AccessScope.HasValue && theQuery.AccessScope.Value > 0) 20 | { 21 | query = query.Where(x => x.Scope == theQuery.AccessScope.Value); 22 | } 23 | return RetrieveUsingPaging(query, theQuery.PageIndex, theQuery.PageSize); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.NHibernate/Queries/GetActionsQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using NHibernate.Criterion; 4 | using System.Collections.Generic; 5 | 6 | namespace MultiTenancyFramework.NHibernate.Queries 7 | { 8 | public class GetActionsQueryHandler : CoreGeneralDAO, IDbQueryHandler> 9 | { 10 | public IList Handle(GetActionsQuery theQuery) 11 | { 12 | var session = BuildSession(); 13 | var query = session.QueryOver() 14 | .Select(Projections.Distinct(Projections.Property(x => x.Action))); 15 | return query.List(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.NHibernate/Queries/GetAreasQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using NHibernate.Criterion; 4 | using System.Collections.Generic; 5 | 6 | namespace MultiTenancyFramework.NHibernate.Queries 7 | { 8 | public class GetAreasQueryHandler : CoreGeneralDAO, IDbQueryHandler> 9 | { 10 | public IList Handle(GetAreasQuery theQuery) 11 | { 12 | var session = BuildSession(); 13 | var query = session.QueryOver() 14 | .Select(Projections.Distinct(Projections.Property(x => x.Area))); 15 | return query.List(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.NHibernate/Queries/GetControllersQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using NHibernate.Criterion; 4 | using System.Collections.Generic; 5 | 6 | namespace MultiTenancyFramework.NHibernate.Queries 7 | { 8 | public class GetControllersQueryHandler : CoreGeneralDAO, IDbQueryHandler> 9 | { 10 | public IList Handle(GetControllersQuery theQuery) 11 | { 12 | var session = BuildSession(); 13 | var query = session.QueryOver() 14 | .Select(Projections.Distinct(Projections.Property(x => x.Controller))); 15 | return query.List(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.NHibernate/RegisterAssemblyHttpModule.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.NHibernate.NHManager; 2 | using System.Web; 3 | 4 | namespace MultiTenancyFramework.Mvc.NHibernate 5 | { 6 | /// 7 | /// This module simply adds 'MultiTenancyFramework.Mvc' to the list of entity assemblies 8 | /// and "MultiTenancyFramework.Mvc.NHibernate" to the list of mapping assemblies 9 | /// 10 | public class RegisterAssemblyHttpModule : IHttpModule 11 | { 12 | public void Dispose() 13 | { 14 | 15 | } 16 | 17 | public void Init(HttpApplication context) 18 | { 19 | NHSessionManager.AddEntityAssemblies(new[] { "MultiTenancyFramework.Mvc" }); 20 | NHSessionManager.AddMappingAssemblies(new[] { "MultiTenancyFramework.Mvc.NHibernate" }); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.NHibernate/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.NHibernate/readme.txt: -------------------------------------------------------------------------------- 1 | Thank you for installing the MultiTenancy Framework using MVC5 and NHibernate! 2 | You can now easily build SaaS using MVC5 and NHibernate. 3 | Learn more on https://github.com/smbadiwe/MultiTenancyFramework/wiki 4 | 5 | A few things to note: 6 | - Your config file will be modified. Here are the ones that need your attention: 7 | - The NHibernate section. Modify accordingly 8 | - AppSettings: the key 'SiteUrl' added. Modify the URL accordingly 9 | - AppSettings: the key 'EntityAssemblies' where you may add the assembly names (comma separated) of the assemblies where your entities reside 10 | 11 | Feel free to contriute, raise an issue, suggest improvements or provide general feedback on the Github page for the framework -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc.NHibernate/web.config.transform: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/Data/Queries/GetActionAccessPrivilegesByGridSearchParamsQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.Data.Queries 4 | { 5 | public class GetActionAccessPrivilegesByGridSearchParamsQuery : DbPagingQuery, IDbQuery> 6 | { 7 | public string Name { get; set; } 8 | public AccessScope? AccessScope { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/Data/Queries/GetActionsQuery.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace MultiTenancyFramework.Data.Queries 4 | { 5 | public class GetActionsQuery : IDbQuery> 6 | { 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/Data/Queries/GetAreasQuery.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace MultiTenancyFramework.Data.Queries 4 | { 5 | public class GetAreasQuery : IDbQuery> 6 | { 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/Data/Queries/GetControllersQuery.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace MultiTenancyFramework.Data.Queries 4 | { 5 | public class GetControllersQuery : IDbQuery> 6 | { 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/Data/Queries/GetUsersWithThesePrivilegesQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using System.Collections.Generic; 4 | 5 | namespace MultiTenancyFramework.Mvc.Data.Queries 6 | { 7 | public class GetUsersWithThesePrivilegesQuery : IDbQuery> 8 | { 9 | /// 10 | /// Gets or sets the name of the preferred entity. THis entity will typically be a child class of AppUser. Leave null if not available 11 | /// 12 | /// 13 | /// The name of the preferred entity. 14 | /// 15 | public string PreferredEntityName { get; set; } 16 | public string[] Privileges { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/EmailMessage.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNet.Identity; 2 | using System.Collections.Generic; 3 | 4 | namespace MultiTenancyFramework.Mvc 5 | { 6 | public class EmailMessage : IdentityMessage 7 | { 8 | public string SenderDisplayName { get; set; } 9 | public string SenderEmail { get; set; } 10 | public string CC { get; set; } = string.Empty; 11 | public string BCC { get; set; } = string.Empty; 12 | /// 13 | /// Default is true. 14 | /// 15 | public bool IsBodyHtml { get; set; } = true; 16 | public IList EmailAttachments { get; set; } = new List(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/Entities/ActionAccessPrivilege.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | using Microsoft.AspNet.Identity; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | 6 | namespace MultiTenancyFramework.Entities 7 | { 8 | /// 9 | /// Access to (MVC) actions and, by extension, app functionalities 10 | /// 11 | [Table("Privileges")] 12 | public class ActionAccessPrivilege : Privilege, IRole 13 | { 14 | /// 15 | /// Introducing IRole forced me to map Name RoleName since it's what we used to call it in the old model 16 | /// It's a combination of , and . Therefore, it should NOT be set 17 | /// 18 | /// The name of the role. 19 | public override string Name { get { return $"{Action}-{Controller}-{Area}"; } set { } } 20 | 21 | /// 22 | /// The (MVC) Action name 23 | /// 24 | public virtual string Action { get; set; } 25 | /// 26 | /// The (MVC) Controller name 27 | /// 28 | public virtual string Controller { get; set; } 29 | /// 30 | /// The (MVC) Area name 31 | /// 32 | public virtual string Area { get; set; } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/Entities/IdentityUser.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNet.Identity; 2 | 3 | namespace MultiTenancyFramework.Entities 4 | { 5 | public class IdentityUser : AppUser, IUser 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/Entities/InstitutionAccessValidationResult.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Entities 2 | { 3 | public class InstitutionAccessValidationResult 4 | { 5 | public bool AllowAccess { get; set; } 6 | 7 | /// 8 | /// if is false, the reason for the denial will usually be learnt from this property 9 | /// 10 | public string Remarks { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/Extensions/IOExtensions.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using MultiTenancyFramework.IO; 3 | using System.Collections.Generic; 4 | using System.Threading.Tasks; 5 | 6 | namespace MultiTenancyFramework 7 | { 8 | public static class IOExtensions 9 | { 10 | public static async Task ToCSV(this MyDataTable dtable, IDictionary headerItems = null, bool replaceNullsWithDefaultValue = false, string delimiter = ",") 11 | { 12 | return await CsvWriter.CreateCSVfile(dtable, headerItems, replaceNullsWithDefaultValue, delimiter); 13 | } 14 | 15 | public static async Task ToExcel(this MyDataTable dtable, IDictionary headerItems = null, bool replaceNullsWithDefaultValue = false, string delimiter = ",") 16 | { 17 | var writer = new ExcelWriter(); 18 | return await writer.ExportToXlsx(dtable, headerItems, replaceNullsWithDefaultValue); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/MultiTenancyFramework.Mvc.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | 1.1.0.0 6 | $title$ 7 | $author$ 8 | $author$ 9 | http://codedrum.blogspot.com/2016/08/MultiTenancyFramework.html 10 | false 11 | $description$ 12 | Read more at https://github.com/smbadiwe/MultiTenancyFramework/wiki. Drop a note if need be. 13 | $copyright$ 14 | SaaS MultiTenant MultiTenancy Framework Software-as-a-Service MVC5 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/MvcUtils/AppStartInitializer.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | using System.Web.Routing; 3 | 4 | namespace MultiTenancyFramework.Mvc.MvcUtils 5 | { 6 | public class AppStartInitializer 7 | { 8 | /// 9 | /// This registers the Areas, Filters and Routes, as well as sets the View Engines to only use Razor and .cshtml files 10 | /// 11 | public static void Initialize(bool useLowercaseRoutes = true) 12 | { 13 | AreaRegistration.RegisterAllAreas(); 14 | ModelBinders.Binders.Add(typeof(string), new TrimModelBinder()); 15 | ModelMetadataProviders.Current = new MyModelMetadataProvider(); 16 | InstitutionFilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 17 | 18 | InstitutionRouteConfig.RegisterRoutes(RouteTable.Routes, useLowercaseRoutes); 19 | MvcHandler.DisableMvcResponseHeader = true; 20 | 21 | ViewEngines.Engines.Clear(); 22 | ViewEngines.Engines.Add(new RazorViewEngine { FileExtensions = new[] { "cshtml" } }); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/MvcUtils/EndRequestFilter.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using MultiTenancyFramework.Logic; 3 | using System.Web.Mvc; 4 | 5 | namespace MultiTenancyFramework.Mvc 6 | { 7 | public class EndRequestFilter : IResultFilter 8 | { 9 | public void OnResultExecuted(ResultExecutedContext filterContext) 10 | { 11 | // Save log entries 12 | var logLogic = new LogLogic(); 13 | logLogic.FlushRequestLogs(); 14 | 15 | // Stop if static resource 16 | var webHelper = new WebHelper(filterContext.HttpContext); 17 | if (webHelper.IsStaticResource()) 18 | { 19 | return; 20 | } 21 | 22 | // Close DB connections 23 | var mgr = MyServiceLocator.GetInstance(); 24 | mgr.CloseDbConnections(); 25 | } 26 | 27 | public void OnResultExecuting(ResultExecutingContext filterContext) 28 | { 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/MvcUtils/InstitutionFilterConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace MultiTenancyFramework.Mvc 4 | { 5 | /// 6 | /// My custom Filter Config 7 | /// 8 | public class InstitutionFilterConfig 9 | { 10 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 11 | { 12 | filters.Add(new KeepAliveFilter()); 13 | filters.Add(new GlobalAuthorizeAttribute()); 14 | filters.Add(new GlobalExceptionFilterAttribute()); 15 | filters.Add(new ValidateAntiForgeryTokenOnPost()); 16 | filters.Add(new EndRequestFilter()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/MvcUtils/MyRazorViewEngine.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace MultiTenancyFramework.Mvc 4 | { 5 | public class MyRazorViewEngine : RazorViewEngine 6 | { 7 | protected override bool FileExists(ControllerContext controllerContext, string virtualPath) 8 | { 9 | if (base.FileExists(controllerContext, virtualPath)) 10 | { 11 | return true; 12 | } 13 | throw new ViewNotFoundException(virtualPath); 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/MvcUtils/ReLoginModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MultiTenancyFramework.Mvc 4 | { 5 | public class ReLoginModel 6 | { 7 | [Required] 8 | public string Password { get; set; } 9 | public string Username { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/MvcUtils/ScheduledTaskApiController.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Core.TaskManager; 2 | using System.Threading.Tasks; 3 | using System.Web.Mvc; 4 | 5 | namespace MultiTenancyFramework.Mvc.MvcUtils 6 | { 7 | /// 8 | /// A thread does an API call to this controller/action and expects nothing in return. 9 | /// It's not meant to be used or browsed. 10 | /// 11 | /// 12 | [AllowAnonymous] 13 | public class ScheduledTaskApiController : Controller 14 | { 15 | [HttpPost] 16 | [IgnoreAntiForgeryToken] 17 | public async Task RunTask(string taskType, string instCode) 18 | { 19 | try 20 | { 21 | var processor = Utilities.QueryProcessor; 22 | processor.InstitutionCode = instCode; 23 | ScheduledTask scheduledTask = await processor.ProcessAsync(new GetTaskByTypeQuery { Type = taskType }); 24 | if (scheduledTask != null) 25 | { 26 | var task = new ScheduledTaskRunner(scheduledTask); 27 | await task.Execute(); 28 | } 29 | } 30 | catch (System.Exception ex) 31 | { 32 | Utilities.Logger.Log("ScheduledTaskApi/RunTask: " + ex.GetFullExceptionMessage()); 33 | } 34 | return new EmptyResult(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/MvcUtils/ValidateUsingPrivilegeForActionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MultiTenancyFramework.Mvc 4 | { 5 | /// 6 | /// MVC-specific; when two or more actions share the same privilege, point the actions to one using this attribute 7 | /// 8 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 9 | public class ValidateUsingPrivilegeForActionAttribute : Attribute 10 | { 11 | private string _actionNames; 12 | public string[] ActionNames 13 | { 14 | get 15 | { 16 | return _actionNames.Split(','); 17 | } 18 | } 19 | 20 | /// 21 | /// 22 | /// 23 | /// Comma-separated list of the relevant action names 24 | public ValidateUsingPrivilegeForActionAttribute(string actionNames) 25 | { 26 | if (string.IsNullOrWhiteSpace(actionNames)) throw new ArgumentNullException(actionNames); 27 | _actionNames = actionNames; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/SmsService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNet.Identity; 2 | using System.Threading.Tasks; 3 | 4 | namespace MultiTenancyFramework.Mvc 5 | { 6 | public class SmsService : IIdentityMessageService 7 | { 8 | public virtual Task SendAsync(IdentityMessage message) 9 | { 10 | // Plug in your SMS service here to send a text message. 11 | return Task.FromResult(0); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /MVC5/MultiTenancyFramework.Mvc/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core.Test/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MultiTenancyFramework.Core.Test 8 | { 9 | public class Class1 10 | { 11 | public void V() 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Attributes/IgnoreInAuditLogAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MultiTenancyFramework 4 | { 5 | /// 6 | /// When used, it specifies that the entity property should be ignored by audit trail. 7 | /// 8 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] 9 | public sealed class IgnoreInAuditLogAttribute : Attribute 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Commands/BaseCommand.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Commands 2 | { 3 | /// 4 | /// Inherit from this base class if your command execution is going to affect tenants (institutions) 5 | /// 6 | public abstract class BaseCommand : ICommand 7 | { 8 | public string InstitutionCode { get; set; } 9 | private ILogger _logger; 10 | /// 11 | /// Logger to log errors and/or messages 12 | /// 13 | public virtual ILogger Logger 14 | { 15 | get 16 | { 17 | if (_logger == null) 18 | { 19 | _logger = Utilities.Logger; 20 | _logger.SetNLogLogger(GetType().FullName); 21 | } 22 | return _logger; 23 | } 24 | } 25 | 26 | } 27 | 28 | public abstract class BaseCommandAsync : ICommandAsync 29 | { 30 | public string InstitutionCode { get; set; } 31 | private ILogger _logger; 32 | /// 33 | /// Logger to log errors and/or messages 34 | /// 35 | public virtual ILogger Logger 36 | { 37 | get 38 | { 39 | if (_logger == null) 40 | { 41 | _logger = Utilities.Logger; 42 | _logger.SetNLogLogger(GetType().FullName); 43 | } 44 | return _logger; 45 | } 46 | } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Commands/CommandProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace MultiTenancyFramework.Commands 7 | { 8 | public sealed class CommandProcessor : ICommandProcessor 9 | { 10 | private IServiceProvider _serviceProvider; 11 | public CommandProcessor(IServiceProvider serviceProvider) 12 | { 13 | _serviceProvider = serviceProvider; 14 | } 15 | 16 | [DebuggerStepThrough] 17 | public void Process(ICommand command) 18 | { 19 | if (command == null) throw new ArgumentNullException("command"); 20 | 21 | var handlerType = 22 | typeof(ICommandHandler<>).MakeGenericType(command.GetType()); 23 | 24 | dynamic handler = _serviceProvider.GetService(handlerType); 25 | handler.Handle((dynamic)command); 26 | } 27 | 28 | [DebuggerStepThrough] 29 | public Task ProcessAsync(ICommandAsync command, CancellationToken token = default(CancellationToken)) 30 | { 31 | if (command == null) throw new ArgumentNullException("command"); 32 | 33 | var handlerType = 34 | typeof(ICommandHandlerAsync<>).MakeGenericType(command.GetType()); 35 | 36 | dynamic handler = _serviceProvider.GetService(handlerType); 37 | return handler.Handle((dynamic)command, (dynamic)token); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Commands/ICommand.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Commands 2 | { 3 | /// 4 | /// Commands to be processed by the handler must implement this interface 5 | /// 6 | public interface ICommand 7 | { 8 | 9 | } 10 | 11 | /// 12 | /// Commands to be processed by the handler must implement this interface 13 | /// 14 | public interface ICommandAsync 15 | { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Commands/ICommandHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace MultiTenancyFramework.Commands 5 | { 6 | public interface ICommandHandler where TCommand : ICommand 7 | { 8 | void Handle(TCommand command); 9 | } 10 | 11 | public interface ICommandHandlerAsync where TCommand : ICommandAsync 12 | { 13 | Task Handle(TCommand command, CancellationToken token = default(CancellationToken)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Commands/ICommandProcessor.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace MultiTenancyFramework.Commands 5 | { 6 | public interface ICommandProcessor 7 | { 8 | void Process(ICommand command); 9 | Task ProcessAsync(ICommandAsync command, CancellationToken token = default(CancellationToken)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/IAppUserDAO.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.Data 4 | { 5 | public interface IAppUserDAO : IAppUserDAO 6 | { 7 | 8 | } 9 | 10 | public interface IAppUserDAO : ICoreDAO where T : AppUser 11 | { 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/ICoreDAO.UnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace MultiTenancyFramework.Data 5 | { 6 | public interface ICoreUnitOfWorkDAO 7 | { 8 | /// 9 | /// Commits the changes. 10 | /// 11 | void CommitChanges(); 12 | 13 | /// 14 | /// Rollbacks the changes. 15 | /// 16 | void RollbackChanges(); 17 | Task CommitChangesAsync(CancellationToken token = default(CancellationToken)); 18 | Task RollbackChangesAsync(CancellationToken token = default(CancellationToken)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/ICoreDAO.Writes.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | using System; 3 | 4 | namespace MultiTenancyFramework.Data 5 | { 6 | public interface ICoreWritesDAO : ICoreGeneralDAO, ICoreUnitOfWorkDAO where T : IBaseEntity where idT : IEquatable 7 | { 8 | void Refresh(T obj); 9 | 10 | /// 11 | /// Updates the specified obj. 12 | /// 13 | /// The obj. 14 | void Update(T obj); 15 | 16 | /// 17 | /// Saves the specified obj. 18 | /// 19 | /// The obj. 20 | void Save(T obj); 21 | 22 | void SaveOrUpdate(T obj); 23 | 24 | /// 25 | /// Deletes the specified obj. 26 | /// 27 | /// The obj. 28 | void Delete(T obj); 29 | 30 | /// 31 | /// Actually deletes the specified obj from the db. 32 | /// 33 | /// The obj. 34 | void TakeOutPermanently(T obj); 35 | 36 | T Merge(T entity); 37 | 38 | void Evict(T entity); 39 | 40 | } 41 | 42 | public interface ICoreWritesDAO : ICoreWritesDAO where T : IEntity 43 | { 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/ICoreDAO.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | using System; 3 | 4 | namespace MultiTenancyFramework.Data 5 | { 6 | /// 7 | /// This holds the minimum data requirements for each entity. It does not include list retrievals and SQL bulk inserts 8 | /// 9 | /// 10 | /// 11 | public interface ICoreDAO : ICoreReadsDAO, ICoreGridPagingDAO, ICoreBulkInsertDAO, ICoreWritesDAO where T : class, IBaseEntity where idT : IEquatable 12 | { 13 | 14 | } 15 | 16 | /// 17 | /// This holds the minimum data requirements for each entity. It does not include list retrievals and SQL bulk inserts 18 | /// 19 | /// 20 | public interface ICoreDAO : ICoreDAO where T : class, IBaseEntity 21 | { 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/ICoreGridPagingDAO.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | using System; 3 | using System.Linq; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace MultiTenancyFramework.Data 8 | { 9 | public interface ICoreGridPagingDAO : ICoreGridPagingDAO where T : class, IBaseEntity 10 | { 11 | } 12 | public interface ICoreGridPagingDAO where T : class, IBaseEntity where idT : IEquatable 13 | { 14 | RetrievedData RetrieveUsingPaging(IQueryable theQueryOver, int startIndex, int maxRows, bool hasOrderBy = false); 15 | Task> RetrieveUsingPagingAsync(IQueryable theQueryOver, int startIndex, int maxRows, bool hasOrderBy = false, CancellationToken token = default(CancellationToken)); 16 | RetrievedData RetrieveUsingPaging(IQueryable theQueryOver, int startIndex, int maxRows, bool hasOrderBy = false) 17 | where TTransform : class; 18 | Task> RetrieveUsingPagingAsync(IQueryable theQueryOver, int startIndex, int maxRows, bool hasOrderBy = false, CancellationToken token = default(CancellationToken)) 19 | where TTransform : class; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/IDataInitializer.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Data 2 | { 3 | public interface IDataInitializer 4 | { 5 | /// 6 | /// This picks session factory parameters from the web.config file 7 | /// 8 | /// 9 | void Init(bool isWeb = true); 10 | 11 | void Terminate(bool isWeb = true); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/IDbSessionCleanup.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Data 2 | { 3 | public interface IDbSessionCleanup 4 | { 5 | void CloseDbConnections(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/IInstitutionDAO.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.Data 4 | { 5 | public interface IInstitutionDAO : IInstitutionDAO 6 | { 7 | } 8 | public interface IInstitutionDAO : ICoreDAO where T : Institution 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/IPrivilegeDAO.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.Data 4 | { 5 | public interface IPrivilegeDAO : IPrivilegeDAO 6 | { 7 | } 8 | 9 | public interface IPrivilegeDAO : ICoreDAO where T : Privilege 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/MyDataRow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace MultiTenancyFramework.Data 5 | { 6 | public class MyDataRow : Dictionary 7 | { 8 | internal MyDataRow(MyDataTable table) 9 | { 10 | if (table == null) throw new ArgumentNullException("table"); 11 | if (table.Columns.Count == 0) throw new InvalidOperationException("The given table has no columns."); 12 | foreach (var col in table.Columns) 13 | { 14 | Add(col.Key, col.Value.DataType?.GetDefaultValue()); 15 | } 16 | Table = table; 17 | } 18 | 19 | public MyDataTable Table { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/MyDataTable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace MultiTenancyFramework.Data 4 | { 5 | /// 6 | /// A very minimal version of the usual DataTable. This is all I need, not that over-bloated one from System.Data 7 | /// 8 | public class MyDataTable 9 | { 10 | /// 11 | /// A very minimal version of the usual DataTable. This is all I need, not that over-bloated one from System.Data 12 | /// 13 | public MyDataTable(string tableName) 14 | { 15 | TableName = tableName; 16 | Rows = new List(); 17 | Columns = new Dictionary(); 18 | } 19 | 20 | /// 21 | /// Return a new row 22 | /// 23 | /// 24 | public MyDataRow NewRow() 25 | { 26 | return new MyDataRow(this); 27 | } 28 | 29 | /// 30 | /// Get or set the table name 31 | /// 32 | public string TableName { get; set; } 33 | 34 | /// 35 | /// Get the rows of the data table 36 | /// 37 | public List Rows { get; private set; } 38 | 39 | /// 40 | /// Get the columns of the data table. NB: Key is . 41 | /// 42 | public Dictionary Columns { get; private set; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/DbPagingQuery.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Data.Queries 2 | { 3 | public abstract class DbPagingQuery 4 | { 5 | /// 6 | /// Think of it as the page number, but here, 0 represents 1st page, etc. 7 | /// 8 | public int PageIndex { get; set; } 9 | /// 10 | /// How many records to return. Set to a value less than zero inorder to return all 11 | /// 12 | public int PageSize { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/GetAppUserByUserRoleQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | using System.Collections.Generic; 3 | 4 | namespace MultiTenancyFramework.Data.Queries 5 | { 6 | public class GetAppUserByUserRoleQuery : IDbQuery> 7 | { 8 | public long UserRoleId { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/GetAppUserByUsernameQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.Data.Queries 4 | { 5 | public class GetAppUserByUsernameQuery : IDbQuery 6 | { 7 | public string Username { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/GetAppUsersByGridSearchParamsQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.Data.Queries 4 | { 5 | public class GetAppUsersByGridSearchParamsQuery : DbPagingQuery, IDbQuery> 6 | { 7 | public string LastName { get; set; } 8 | public string OtherNames { get; set; } 9 | public string Username { get; set; } 10 | public long UserRole { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/GetDatabaseConnectionByNameAndConnectionStringQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.Data.Queries 4 | { 5 | public class GetDatabaseConnectionByNameAndConnectionStringQuery : IDbQuery 6 | { 7 | public string Name { get; set; } 8 | public string ConnectionString { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/GetEntitiesAppearingInAuditLogsQuery.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace MultiTenancyFramework.Data.Queries 4 | { 5 | /// 6 | /// This query, when run, returns list of all the entities that has been logged at some point in time in the audit logs table 7 | /// 8 | public class GetEntitiesAppearingInAuditLogsQuery : IDbQuery> 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/GetIAppUserByEmailQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.Data.Queries 4 | { 5 | public class GetAppUserByEmailQuery : IDbQuery 6 | { 7 | public string Email { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/GetInstitutionByCodeQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.Data.Queries 4 | { 5 | public class GetInstitutionByCodeQuery : IDbQuery 6 | { 7 | public string Code { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/GetPhotosByOwnerIdAndImageTypeQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | using System.Collections.Generic; 3 | 4 | namespace MultiTenancyFramework.Data.Queries 5 | { 6 | public sealed class GetPhotosByOwnerIdAndImageTypeQuery : IDbQuery> 7 | { 8 | public string OwnerID { get; set; } 9 | public ImageType ImageType { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/GetPrivilegesByGridSearchParamsQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.Data.Queries 4 | { 5 | /// 6 | /// Seaches params: Name and Access Scope 7 | /// 8 | public class GetPrivilegesByGridSearchParamsQuery : DbPagingQuery, IDbQuery> 9 | { 10 | public string Name { get; set; } 11 | public AccessScope? AccessScope { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/GetUserClaimsByUserIdQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | using System.Collections.Generic; 3 | 4 | namespace MultiTenancyFramework.Data.Queries 5 | { 6 | public class GetUserClaimsByUserIdQuery : IDbQuery> 7 | { 8 | public long UserId { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/GetUserLoginByLoginProviderKeyAndUserIdQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.Data.Queries 4 | { 5 | public class GetUserLoginByLoginProviderKeyAndUserIdQuery : IDbQuery 6 | { 7 | public long UserID { get; set; } 8 | public string LoginProvider { get; set; } 9 | public string ProviderKey { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/GetUserLoginsByUserIdQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | using System.Collections.Generic; 3 | 4 | namespace MultiTenancyFramework.Data.Queries 5 | { 6 | public class GetUserLoginsByUserIdQuery : IDbQuery> 7 | { 8 | public long UserId { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/GetUserRoleByNameQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.Data.Queries 4 | { 5 | public class GetUserRoleByNameQuery : IDbQuery 6 | { 7 | public string Name { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/IDbQuery.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Data.Queries 2 | { 3 | public interface IDbQuery 4 | { 5 | } 6 | 7 | public interface IDbQueryAsync 8 | { 9 | } 10 | } -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/IDbQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace MultiTenancyFramework.Data.Queries 5 | { 6 | public interface IDbQueryHandler where TQuery : IDbQuery 7 | { 8 | string InstitutionCode { get; set; } 9 | TResult Handle(TQuery theQuery); 10 | } 11 | 12 | public interface IDbQueryHandlerAsync where TQuery : IDbQueryAsync 13 | { 14 | string InstitutionCode { get; set; } 15 | Task Handle(TQuery theQuery, CancellationToken token = default(CancellationToken)); 16 | } 17 | } -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/Queries/IDbQueryProcessor.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace MultiTenancyFramework.Data.Queries 5 | { 6 | /// 7 | /// NB: It is advisable to register this entity in IoC as a singleton 8 | /// 9 | public interface IDbQueryProcessor 10 | { 11 | string InstitutionCode { get; set; } 12 | TResult Process(IDbQuery query); 13 | Task ProcessAsync(IDbQueryAsync query, CancellationToken token = default(CancellationToken)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Data/RetrievedData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace MultiTenancyFramework.Data 4 | { 5 | public sealed class RetrievedData 6 | { 7 | /// 8 | /// The batch returned; usually not everything in the DB 9 | /// 10 | public IList DataBatch { get; set; } = new List(); 11 | 12 | /// 13 | /// Total in the DB; not usually the same as DataBatch.Count 14 | /// 15 | public int TotalCount { get; set; } 16 | 17 | /// 18 | /// Gets the Count of the DataBatch 19 | /// 20 | public int Count 21 | { 22 | get { return DataBatch == null ? 0 : DataBatch.Count; } 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Entities/DatabaseConnection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace MultiTenancyFramework.Entities 5 | { 6 | public class DatabaseConnection : Entity, IAmHostedCentrally 7 | { 8 | public virtual string ConnectionString { get; set; } 9 | /// 10 | /// Comma-separated values of the InstitutionCode of the tenants whose data is on this DB 11 | /// 12 | public virtual string TenantsOnIt { get; set; } 13 | /// 14 | /// The InstitutionCode of the tenants whose data is on this DB 15 | /// 16 | public virtual HashSet TenantCodes 17 | { 18 | get 19 | { 20 | if (string.IsNullOrWhiteSpace(TenantsOnIt)) return new HashSet(); 21 | 22 | var splitted = TenantsOnIt.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); 23 | HashSet userRoles = new HashSet(splitted); 24 | return userRoles; 25 | } 26 | } 27 | public virtual int MaximumNumberOfInstitutionsHosted { get; set; } = 1; 28 | public virtual int NumberOfInstitutionsCurrentlyHosted { get; set; } = 1; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Entities/IAmHostedCentrally.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Entities 2 | { 3 | /// 4 | /// Use this on entities that are hosted centrally for all institutions to use 5 | /// 6 | public interface IAmHostedCentrally 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Entities/IDoNotNeedAudit.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Entities 2 | { 3 | /// 4 | /// Entities implementing this will not be eligible for audit 5 | /// 6 | public interface IDoNotNeedAudit 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Entities/Institution.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Entities 2 | { 3 | public class Institution : Entity, IAmHostedCentrally 4 | { 5 | /// 6 | /// True means the modification was done by the system (the landlord'). 7 | /// False means the owning institution modified their data themselves. 8 | /// Null means it has not been modified 9 | /// 10 | public virtual bool? LastModificationDoneByUs { get; set; } = null; 11 | 12 | public virtual string Code { get; set; } 13 | 14 | public virtual string Email { get; set; } 15 | 16 | public virtual string Phone { get; set; } 17 | 18 | public virtual string ShortName { get; set; } 19 | 20 | public virtual long DatabaseConnectionId { get; set; } 21 | 22 | /// 23 | /// Username for initial login before DB is alloted to institution 24 | /// 25 | public virtual string TempUserName { get; set; } 26 | 27 | /// 28 | /// Username for initial login before DB is alloted to institution 29 | /// 30 | public virtual string TempPassword { get; set; } 31 | 32 | public override string ToString() 33 | { 34 | return $"Id: {Id}; Name: {Name}; Code: {Code}"; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Entities/Person.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Entities 2 | { 3 | 4 | public abstract class Person : BaseEntity 5 | { 6 | /// 7 | /// Passport is what I have in mind here 8 | /// 9 | public virtual Photo Photo { get; set; } 10 | public virtual string LastName { get; set; } 11 | public virtual string OtherNames { get; set; } 12 | /// 13 | /// Returns the full name of the person. 14 | /// 15 | public virtual string Name { get { return FullNames; } } 16 | public virtual string FullNames { get { return $"{LastName}, {OtherNames}"; } } 17 | public virtual string Email { get; set; } 18 | public virtual string PhoneNumber { get; set; } 19 | public virtual Gender Gender { get; set; } 20 | public virtual bool IsFemale { get { return Gender == Gender.Female; } } 21 | public virtual bool IsMale { get { return Gender == Gender.Male; } } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Entities/Photo.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Entities 2 | { 3 | /// 4 | /// A person's photo record 5 | /// 6 | public class Photo : Entity 7 | { 8 | public Photo() 9 | { 10 | SkipAudit = true; 11 | } 12 | 13 | /// 14 | /// The ID representing the person that owns this photo record 15 | /// 16 | public virtual string OwnerID { get; set; } 17 | 18 | /// 19 | /// The image, as byte array, typically to be saved in the Database 20 | /// 21 | public virtual byte[] Image { get; set; } 22 | 23 | /// 24 | /// Url (filepath) of the image, use when you're saving the image to disk, not database 25 | /// 26 | public virtual string ImageUrl { get; set; } 27 | 28 | /// 29 | /// Image type 30 | /// 31 | public virtual ImageType ImageType { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Entities/SystemSetting.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Entities 2 | { 3 | /// 4 | /// Captures settings that apply globally, i.e. independent of the institutions using the system 5 | /// 6 | public class SystemSetting : BaseEntity, IAmHostedCentrally 7 | { 8 | public virtual string ApplicationName { get; set; } 9 | public virtual bool EmailLogMessages { get; set; } 10 | public virtual UsernameAndPasswordRule UsernameAndPasswordRule { get; set; } = new UsernameAndPasswordRule(); 11 | public virtual EmailAndSmtpSetting EmailAndSmtpSetting { get; set; } = new EmailAndSmtpSetting(); 12 | 13 | /// 14 | /// The folder where institutions' logo images will be stored 15 | /// 16 | public virtual string LogoImageFolder { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Entities/TrailItem.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework 2 | { 3 | public class TrailItem 4 | { 5 | public TrailItem(string propertyName, string valueBefore, string valueAfter) 6 | { 7 | Property = propertyName; 8 | Before = valueBefore; 9 | After = valueAfter; 10 | } 11 | 12 | public TrailItem() 13 | : this("", "", "") 14 | { 15 | } 16 | 17 | public TrailItem(string propertyName) 18 | : this(propertyName, "", "") 19 | { 20 | } 21 | 22 | /// 23 | /// The name of the property we're trailing 24 | /// 25 | public string Property { get; set; } 26 | 27 | /// 28 | /// The value before the change 29 | /// 30 | public string Before { get; set; } 31 | 32 | /// 33 | /// The value after the change 34 | /// 35 | public string After { get; set; } 36 | 37 | /// 38 | /// Gets a value indicating hether or not the value of the property was modified 39 | /// 40 | public bool Changed { get { return Before != After; } } 41 | 42 | public override string ToString() 43 | { 44 | return $"Before: {Before}; After: {After}; Changed: {Changed}"; 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Entities/UserLogin.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Entities 2 | { 3 | /// 4 | /// Mirrows Microsoft.AspNet.Identity.UserLoginInfo. Used to track external logins 5 | /// 6 | public class UserLogin : Entity, IDoNotNeedAudit 7 | { 8 | // 9 | // Summary: 10 | // Provider for the linked login, i.e. Facebook, Google, etc. 11 | public virtual string LoginProvider { get; set; } 12 | // 13 | // Summary: 14 | // User specific key for the login provider 15 | public virtual string ProviderKey { get; set; } 16 | 17 | public virtual long UserId { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Entities/UsernameAndPasswordRule.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace MultiTenancyFramework.Entities 3 | { 4 | // Maintain exact copy with .Mvc.UsernameAndPasswordRule 5 | // w.r.t property names and types 6 | [System.ComponentModel.DataAnnotations.Schema.ComplexType] 7 | public class UsernameAndPasswordRule 8 | { 9 | /// 10 | /// Only allow [A-Za-z0-9@_] in UserNames 11 | /// 12 | public virtual bool AllowOnlyAlphanumericUserNames { get; set; } 13 | /// 14 | /// If true, enforces that emails are non empty, valid, and unique 15 | /// 16 | public virtual bool RequireUniqueEmail { get; set; } = true; 17 | public virtual bool UserLockoutEnabledByDefault { get; set; } = true; 18 | public virtual int MaxFailedAccessAttemptsBeforeLockout { get; set; } = 5; 19 | public virtual int DefaultAccountLockoutTimeSpanInMinutes { get; set; } = 5; 20 | public virtual int PasswordRequiredLength { get; set; } = 8; 21 | 22 | public virtual bool PasswordRequireNonLetterOrDigit { get; set; } = true; 23 | public virtual bool PasswordRequireDigit { get; set; } = true; 24 | public virtual bool PasswordRequireLowercase { get; set; } = true; 25 | public virtual bool PasswordRequireUppercase { get; set; } = true; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Enums.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework 2 | { 3 | /// 4 | /// For AuditLog; what happened to the entity 5 | /// 6 | public enum EventType 7 | { 8 | Added = 0, 9 | Modified = 1, 10 | SoftDeleted = 2, 11 | UnDeleted = 3, 12 | DeletedForReal = 4, 13 | Login = 5, 14 | Logout = 6, 15 | FailedLogin = 7 16 | } 17 | 18 | public enum AccessScope 19 | { 20 | BothCentralAndTenants = 1, 21 | [EnumDescription("Root-Only")] 22 | CentralOnly, 23 | [EnumDescription("Tenant-Only")] 24 | TenantsOnly, 25 | } 26 | 27 | public enum ImageType 28 | { 29 | Passport = 0, 30 | Picture, 31 | Signature, 32 | LeftThumbPrint, 33 | RightThumbPrint, 34 | Other = 99, 35 | } 36 | 37 | public enum Gender 38 | { 39 | NotSpecified, 40 | Male = 1, 41 | Female 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Exceptions/ForceChangeOfPasswordException.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework 2 | { 3 | public class ForceChangeOfPasswordException : GeneralException 4 | { 5 | public ForceChangeOfPasswordException() : base("You will need to change your password.") 6 | { 7 | 8 | } 9 | 10 | public ForceChangeOfPasswordException(string message) : base(message) 11 | { 12 | 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Exceptions/GeneralException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MultiTenancyFramework 4 | { 5 | /// 6 | /// TODO: Figure out what other special thing to do with this exception. 7 | /// Maybe throw an Error ID and a nicer message. Think through later. 8 | /// 9 | public class GeneralException : Exception 10 | { 11 | public ExceptionType ExceptionType { get; set; } 12 | public GeneralException(string message, ExceptionType exceptionType = ExceptionType.InvalidUserActionOrInput) : base(message) 13 | { 14 | ExceptionType = exceptionType; 15 | } 16 | 17 | public GeneralException(string message, Exception innerException, ExceptionType exceptionType = ExceptionType.InvalidUserActionOrInput) : base(message, innerException) 18 | { 19 | ExceptionType = exceptionType; 20 | } 21 | } 22 | 23 | public enum ExceptionType 24 | { 25 | InvalidUserActionOrInput, 26 | NoMoreDbForOrganizations, 27 | UnidentifiedInstitutionCode, 28 | DatabaseRelated, 29 | AccessDeniedInstitution, 30 | SessionTimeOut, 31 | /// 32 | /// When all data required fro the app to run is not yet setup in the DB, or when the DB itself is not available 33 | /// 34 | SetupFailure, 35 | Security, 36 | DoNothing = 99, 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Exceptions/LogOutUserException.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace MultiTenancyFramework 3 | { 4 | public class LogOutUserException : GeneralException 5 | { 6 | public LogOutUserException() : base("Log user out. Redirect to login page", ExceptionType.SessionTimeOut) 7 | { 8 | } 9 | 10 | public LogOutUserException(string message) : base(message, ExceptionType.SessionTimeOut) 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Extensions/EntityExtensions.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Core.TaskManager.Tasks; 2 | using MultiTenancyFramework.Data; 3 | using System.Linq; 4 | 5 | namespace MultiTenancyFramework 6 | { 7 | public static class EntityExtensions 8 | { 9 | public static RetrievedData Cast(this RetrievedData list) 10 | { 11 | return new RetrievedData 12 | { 13 | DataBatch = list.DataBatch.Cast().ToList(), 14 | TotalCount = list.TotalCount 15 | }; 16 | } 17 | 18 | /// 19 | /// Gets an email account instance. A new one is created; as opposed to reading from DB 20 | /// 21 | /// The settings. 22 | /// 23 | public static EmailAccount ToEmailAccount(this EmailAndSmtpSetting Settings) 24 | { 25 | return new EmailAccount 26 | { 27 | DisplayName = Settings.DefaultSenderDisplayName, 28 | Username = Settings.SmtpUsername, 29 | Password = Settings.SmtpPassword, 30 | Host = Settings.SmtpHost, 31 | Port = Settings.SmtpPort, 32 | EnableSsl = Settings.EnableSSL, 33 | UseDefaultCredentials = false, 34 | Email = Settings.DefaultEmailSender 35 | }; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Extensions/OtherExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework 2 | { 3 | /// 4 | /// More in 'OtherExtensions' in MultiTenancyFramework.Utils 5 | /// 6 | public static class OtherExtensions 7 | { 8 | public static void SetNLogLogger(this ILogger logger, string name) 9 | { 10 | if (!string.IsNullOrWhiteSpace(name)) 11 | logger.SetLogger(NLog.LogManager.GetLogger(name)); 12 | else 13 | logger.SetLogger(null); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Logic/IAuditTrailLogger.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyFramework.Logic 2 | { 3 | public interface IAuditTrailLogger 4 | { 5 | /// 6 | /// Audit Trail at every login or logout attempt. Do not set the second parameter 7 | /// if it was possible at all to retrieve the user. In that case, just bundle the user in session. 8 | /// We'll pick it up from there. 9 | /// 10 | /// The action. 11 | /// Name of the user. 12 | /// Remarks. 13 | /// Institution Code. 14 | void AuditLogin(EventType action, string userName = null, string remarks = null, string institutionCode = null); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Logic/SystemSettingLogic.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using MultiTenancyFramework.Entities; 3 | 4 | namespace MultiTenancyFramework.Logic 5 | { 6 | public class SystemSettingLogic : CoreBaseLogic 7 | { 8 | public SystemSettingLogic() : base(MyServiceLocator.GetInstance>()) 9 | { 10 | } 11 | 12 | public SystemSetting RetrieveSystemSetting() 13 | { 14 | return _dao.RetrieveOne(); 15 | } 16 | 17 | public override void OnAfterCommittingChanges(SystemSetting e) 18 | { 19 | base.OnAfterCommittingChanges(e); 20 | Utilities.SystemSettings = e; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Logic/UserClaimLogic.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using MultiTenancyFramework.Entities; 3 | 4 | namespace MultiTenancyFramework.Logic 5 | { 6 | public class UserClaimLogic : CoreLogic 7 | { 8 | public UserClaimLogic(string institutionCode) 9 | : base(MyServiceLocator.GetInstance>(), institutionCode) 10 | { 11 | } 12 | 13 | public override string InstitutionCode 14 | { 15 | get 16 | { 17 | return base.InstitutionCode; 18 | } 19 | set 20 | { 21 | _dao.InstitutionCode = base.InstitutionCode = value; 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Logic/UserLoginLogic.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using MultiTenancyFramework.Entities; 3 | 4 | namespace MultiTenancyFramework.Logic 5 | { 6 | public class UserLoginLogic : CoreLogic 7 | { 8 | public UserLoginLogic(string institutionCode) 9 | : base(MyServiceLocator.GetInstance>(), institutionCode) 10 | { 11 | } 12 | 13 | public override string InstitutionCode 14 | { 15 | get 16 | { 17 | return base.InstitutionCode; 18 | } 19 | set 20 | { 21 | _dao.InstitutionCode = base.InstitutionCode = value; 22 | } 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/Logic/UserRoleLogic.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using MultiTenancyFramework.Entities; 3 | 4 | namespace MultiTenancyFramework.Logic 5 | { 6 | public class UserRoleLogic : CoreLogic 7 | { 8 | public UserRoleLogic(string institutionCode) 9 | : base(MyServiceLocator.GetInstance>(), institutionCode) 10 | { 11 | } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/MultiTenancyFramework.Core.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | 1.1.0.0 6 | $title$ 7 | $author$ 8 | $author$ 9 | http://codedrum.blogspot.com/2016/08/MultiTenancyFramework.html 10 | false 11 | $description$ 12 | Read more at https://github.com/smbadiwe/MultiTenancyFramework/wiki. Drop a note if need be. 13 | $copyright$ 14 | SaaS MultiTenant MultiTenancy Framework Software-as-a-Service 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/NLog.config: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | 14 | 18 | 19 | 20 | 25 | 26 | 31 | 32 | 33 | 34 | 35 | 36 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/TaskManager/GetTaskByTypeQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | 3 | namespace MultiTenancyFramework.Core.TaskManager 4 | { 5 | public class GetTaskByTypeQuery : IDbQueryAsync 6 | { 7 | public string Type { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/TaskManager/ScheduledTask.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | using System; 3 | 4 | namespace MultiTenancyFramework.Core.TaskManager 5 | { 6 | /// 7 | /// This represents the task record as stored in DB 8 | /// 9 | /// 10 | public class ScheduledTask : Entity 11 | { 12 | /// 13 | /// Gets or sets the run period (in seconds) 14 | /// 15 | public virtual int Seconds { get; set; } 16 | 17 | /// 18 | /// Gets or sets the type of appropriate IScheduleTask class 19 | /// 20 | public virtual string Type { get; set; } 21 | 22 | /// 23 | /// Gets or sets the value indicating whether a task should be stopped on some error 24 | /// 25 | public virtual bool StopOnError { get; set; } 26 | 27 | /// 28 | /// Gets or sets the datetime when it was started last time 29 | /// 30 | public virtual DateTime? LastStartUtc { get; set; } 31 | /// 32 | /// Gets or sets the datetime when it was finished last time (no matter failed ir success) 33 | /// 34 | public virtual DateTime? LastEndUtc { get; set; } 35 | /// 36 | /// Gets or sets the datetime when it was sucessfully finished last time 37 | /// 38 | public virtual DateTime? LastSuccessUtc { get; set; } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/TaskManager/Tasks/ClearLogTask.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Core.TaskManager; 2 | using MultiTenancyFramework.Logic; 3 | using System; 4 | using System.Threading.Tasks; 5 | 6 | namespace MultiTenancyFramework.Tasks 7 | { 8 | public class ClearLogTask : IRunnableTask 9 | { 10 | public ScheduledTask DefaultTaskPlan 11 | { 12 | get 13 | { 14 | return new ScheduledTask 15 | { 16 | Name = "Clear logs", 17 | Seconds = 2 * 86400, // 2 day 18 | Type = typeof(ClearLogTask).AssemblyQualifiedName, 19 | IsDisabled = false, 20 | StopOnError = false, 21 | }; 22 | } 23 | } 24 | 25 | public OwnershipType OwnershipType 26 | { 27 | get 28 | { 29 | return OwnershipType.CentralOnly; 30 | } 31 | } 32 | 33 | public Task Execute(string institutionCode) 34 | { 35 | return new LogLogic().ClearLog(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/TaskManager/Tasks/IRunnableTask.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Core.TaskManager; 2 | using System.Threading.Tasks; 3 | 4 | namespace MultiTenancyFramework.Tasks 5 | { 6 | public interface IRunnableTask 7 | { 8 | OwnershipType OwnershipType { get; } 9 | ScheduledTask DefaultTaskPlan { get; } 10 | Task Execute(string institutionCode); 11 | } 12 | 13 | public enum OwnershipType 14 | { 15 | CentralOnly, 16 | PerInstitution 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/TaskManager/Tasks/KeepAliveTask.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Threading.Tasks; 4 | using MultiTenancyFramework.Core.TaskManager; 5 | 6 | namespace MultiTenancyFramework.Tasks 7 | { 8 | public class KeepAliveTask : IRunnableTask 9 | { 10 | public ScheduledTask DefaultTaskPlan 11 | { 12 | get 13 | { 14 | return new ScheduledTask 15 | { 16 | Name = "Keep alive", 17 | Seconds = 300, 18 | Type = typeof(KeepAliveTask).AssemblyQualifiedName, 19 | IsDisabled = false, 20 | StopOnError = false, 21 | }; 22 | } 23 | } 24 | 25 | public OwnershipType OwnershipType 26 | { 27 | get 28 | { 29 | return OwnershipType.CentralOnly; 30 | } 31 | } 32 | 33 | public Task Execute(string institutionCode) 34 | { 35 | using (var client = new WebClient()) 36 | { 37 | client.DownloadStringAsync(new Uri(ConfigurationHelper.GetSiteUrl() + "keepalive/index")); 38 | } 39 | return Task.CompletedTask; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/TaskManager/Tasks/SearchQueuedEmailsQuery.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using MultiTenancyFramework.Data.Queries; 3 | using System; 4 | 5 | namespace MultiTenancyFramework.Core.TaskManager.Tasks 6 | { 7 | public class SearchQueuedEmailsQuery : DbPagingQuery, IDbQuery> 8 | { 9 | public string FromEmail { get; set; } 10 | public string ToEmail { get; set; } 11 | public DateTime? CreatedFromUtc { get; set; } 12 | public DateTime? CreatedToUtc { get; set; } 13 | public bool LoadNotSentItemsOnly { get; set; } 14 | public bool LoadOnlyItemsToBeSent { get; set; } 15 | public bool LoadNewest { get; set; } 16 | public int MaxSendTries { get; set; } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/app.config.install.xdt: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/app.config.transform: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/app.config.uninstall.xdt: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/web.config.install.xdt: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/web.config.transform: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Core/web.config.uninstall.xdt: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /MultiTenancyFramework.CoreTests/Extensions/OtherExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | 3 | namespace MultiTenancyFramework.Tests 4 | { 5 | [TestClass()] 6 | public class OtherExtensionsTests 7 | { 8 | [TestMethod()] 9 | public void GetNameTest() 10 | { 11 | Assert.AreEqual(int.MaxValue.ToString(), OtherExtensions.GetName(x => int.MaxValue)); 12 | } 13 | 14 | [TestMethod()] 15 | public void GetNameTest2() 16 | { 17 | Assert.AreEqual("32", OtherExtensions.GetName(x => 32)); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /MultiTenancyFramework.CoreTests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/AppUserDAO.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using MultiTenancyFramework.Entities; 3 | 4 | namespace MultiTenancyFramework.NHibernate 5 | { 6 | public class AppUserDAO : AppUserDAO, IAppUserDAO 7 | { 8 | } 9 | 10 | public class AppUserDAO : CoreDAO, IAppUserDAO where T : AppUser 11 | { 12 | public AppUserDAO() 13 | { 14 | EntityName = NHManager.NHSessionManager.GetEntityNameToUseInNHSession(typeof(AppUser)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Audit/GlobalTrackingConfig.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | using System; 3 | using System.Linq.Expressions; 4 | 5 | namespace MultiTenancyFramework.NHibernate.Audit 6 | { 7 | public static class GlobalTrackingConfig 8 | { 9 | public static bool Enabled { get; set; } = true; 10 | 11 | public static bool TrackEmptyPropertiesOnAdditionAndDeletion { get; set; } = false; 12 | 13 | public static bool DisconnectedContext { get; set; } = false; 14 | 15 | public static Type SoftDeletableType { get; set; } = typeof(IBaseEntity); 16 | 17 | public static string SoftDeletablePropertyName { get; set; } = "IsDeleted"; 18 | 19 | /// 20 | /// Set the property to use for tracking deleted entities 21 | /// 22 | /// 23 | /// 24 | public static void SetSoftDeletableCriteria(Expression> softDeletableProperty) 25 | { 26 | SoftDeletableType = typeof(TSoftDeletable); 27 | SoftDeletablePropertyName = softDeletableProperty.GetPropertyInfo().Name; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Audit/PropertyConfigKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MultiTenancyFramework.NHibernate.Audit 4 | { 5 | public class PropertyConfigKey 6 | { 7 | public PropertyConfigKey(string propertyName, string typeFullName) 8 | { 9 | PropertyName = propertyName; 10 | TypeFullName = typeFullName; 11 | } 12 | 13 | public string PropertyName { get; } 14 | public string TypeFullName { get; } 15 | 16 | public override bool Equals(object obj) 17 | { 18 | if (obj == null) return false; 19 | var otherEntity = obj as PropertyConfigKey; 20 | if (otherEntity == null) return false; 21 | bool isNameSame = otherEntity.PropertyName.Equals(PropertyName, StringComparison.OrdinalIgnoreCase); 22 | bool isTypeSame = otherEntity.TypeFullName.Equals(TypeFullName, StringComparison.OrdinalIgnoreCase); 23 | 24 | return isNameSame && isTypeSame; 25 | } 26 | 27 | public override int GetHashCode() 28 | { 29 | return (PropertyName + TypeFullName).GetHashCode(); 30 | } 31 | 32 | public override string ToString() 33 | { 34 | return TypeFullName + "." + PropertyName; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Audit/PropertyTracking.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace MultiTenancyFramework.NHibernate.Audit 5 | { 6 | public static class PropertyTracking 7 | { 8 | public static bool IsTrackingEnabled(PropertyConfigKey property, Type entityType) 9 | { 10 | bool isEnabled; 11 | if (!TrackingDataStore.PropertyConfigStore.TryGetValue(property, out isEnabled)) 12 | { 13 | isEnabled = entityType.GetProperty(property.PropertyName).GetCustomAttribute() == null; 14 | TrackingDataStore.PropertyConfigStore.TryAdd(property, isEnabled); 15 | } 16 | return isEnabled; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Audit/TrackingDataStore.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | 3 | namespace MultiTenancyFramework.NHibernate.Audit 4 | { 5 | internal static class TrackingDataStore 6 | { 7 | /// 8 | /// This tells us whether or not a given property (the key) in an entity should be skipped in AuditLog. 9 | /// Value = false means it SHOULD NOT be skipped 10 | /// 11 | internal static ConcurrentDictionary PropertyConfigStore = new ConcurrentDictionary(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/CoreGeneralWithGridPagingDAO.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.NHibernate 4 | { 5 | public abstract class CoreGeneralWithGridPagingDAO : CoreGridPagingDAO where T : class, IBaseEntity 6 | { 7 | 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/DataInitializer.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using MultiTenancyFramework.NHibernate.NHManager; 3 | 4 | namespace MultiTenancyFramework.NHibernate 5 | { 6 | public class DataInitializer : IDataInitializer 7 | { 8 | public virtual void Init(bool isWeb = true) 9 | { 10 | //Sesson Factory 11 | NHSessionManager.Init(null, NHSessionManager.GetSessionKey(isWebSession: isWeb)); 12 | } 13 | 14 | public virtual void Terminate(bool isWeb = true) 15 | { 16 | NHSessionManager.CloseStorage(isWebSession: isWeb); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/InstitutionDAO.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using MultiTenancyFramework.Entities; 3 | 4 | namespace MultiTenancyFramework.NHibernate 5 | { 6 | public class InstitutionDAO : InstitutionDAO, IInstitutionDAO 7 | { 8 | } 9 | 10 | public class InstitutionDAO : CoreDAO, IInstitutionDAO where T : Institution 11 | { 12 | public InstitutionDAO() 13 | { 14 | EntityName = NHManager.NHSessionManager.GetEntityNameToUseInNHSession(typeof(T)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Maps/AuditLogMap.cs: -------------------------------------------------------------------------------- 1 | using FluentNHibernate.Automapping; 2 | using FluentNHibernate.Automapping.Alterations; 3 | using MultiTenancyFramework.Entities; 4 | 5 | namespace MultiTenancyFramework.NHibernate.Maps 6 | { 7 | public class AuditLogMap : IAutoMappingOverride 8 | { 9 | public void Override(AutoMapping mapping) 10 | { 11 | mapping.Map(x => x.AuditData).VarCharMax(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Maps/EntityMap.cs: -------------------------------------------------------------------------------- 1 | using FluentNHibernate.Mapping; 2 | using MultiTenancyFramework.Entities; 3 | using System; 4 | 5 | namespace MultiTenancyFramework.NHibernate.Maps 6 | { 7 | public class EntityMap : EntityMap where T : class, IEntity 8 | { 9 | 10 | } 11 | 12 | public class EntityMap : BaseEntityMap where T : class, IEntity where idT : IEquatable 13 | { 14 | public EntityMap() 15 | { 16 | Map(x => x.Name); 17 | } 18 | } 19 | 20 | public class BaseEntityMap : BaseEntityMap where T : class, IBaseEntity 21 | { 22 | 23 | } 24 | 25 | public class BaseEntityMap : ClassMap where T : class, IBaseEntity where idT : IEquatable 26 | { 27 | public BaseEntityMap() 28 | { 29 | Id(x => x.Id); 30 | Map(x => x.IsDeleted); 31 | Map(x => x.InstitutionCode); 32 | Map(x => x.IsDisabled); 33 | Map(x => x.DateCreated); 34 | Map(x => x.CreatedBy); 35 | Map(x => x.LastDateModified); 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Maps/IdentityUserMap.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.NHibernate.Maps 4 | { 5 | public sealed class AppUserMap : AppUserMap 6 | { 7 | } 8 | 9 | public class AppUserMap : PersonMap where T : AppUser 10 | { 11 | public AppUserMap() 12 | { 13 | Table(ConfigurationHelper.AppSettingsItem("UseLowercaseTableNames") ? "users" : "Users"); 14 | Map(x => x.UserName).Index("ind_username"); 15 | Map(x => x.PasswordHash); 16 | Map(x => x.UserRoles); 17 | 18 | Map(x => x.ForceChangeOfPassword); 19 | 20 | Map(x => x.LockoutEnabled); 21 | Map(x => x.LockoutEndDateUtc); 22 | Map(x => x.AccessFailedCount); 23 | Map(x => x.PhoneNumberConfirmed); 24 | Map(x => x.TwoFactorEnabled); 25 | Map(x => x.SecurityStamp); 26 | Map(x => x.EmailConfirmed); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Maps/InstitutionMap.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.NHibernate.Maps 4 | { 5 | public sealed class InstitutionMap : InstitutionMap 6 | { 7 | 8 | } 9 | 10 | public class InstitutionMap : EntityMap where T : Institution 11 | { 12 | public InstitutionMap() 13 | { 14 | Table(typeof(Institution).GetTableName()); 15 | 16 | Map(x => x.ShortName); 17 | Map(x => x.Code).Index("ind_code"); 18 | Map(x => x.Email); 19 | Map(x => x.Phone); 20 | Map(x => x.TempUserName); 21 | Map(x => x.TempPassword); 22 | Map(x => x.DatabaseConnectionId); 23 | Map(x => x.LastModificationDoneByUs); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Maps/NHMapsExtensions.cs: -------------------------------------------------------------------------------- 1 | using FluentNHibernate.Mapping; 2 | 3 | namespace MultiTenancyFramework.NHibernate.Maps 4 | { 5 | public static class NHMapsExtensions 6 | { 7 | public static PropertyPart VarCharMax(this PropertyPart part) 8 | { 9 | //Any length more than 4001 sets the string column to varchar(MAX) or Text. 10 | return part.Length(4444); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Maps/PersonMap.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.NHibernate.Maps 4 | { 5 | public class PersonMap : BaseEntityMap where T : Person 6 | { 7 | public PersonMap() 8 | { 9 | Map(x => x.LastName); 10 | Map(x => x.OtherNames); 11 | Map(x => x.Gender); 12 | Map(x => x.Email); 13 | Map(x => x.PhoneNumber); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Maps/PrivilegeMap.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | 3 | namespace MultiTenancyFramework.NHibernate.Maps 4 | { 5 | public sealed class PrivilegeMap : PrivilegeMap 6 | { 7 | } 8 | 9 | public class PrivilegeMap : EntityMap where T : Privilege 10 | { 11 | public PrivilegeMap() 12 | { 13 | Table(typeof(Privilege).GetTableName()); 14 | Map(x => x.Description); 15 | Map(x => x.Scope); 16 | Map(x => x.DisplayName); 17 | Map(x => x.IsDefault); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Maps/UserRoleMap.cs: -------------------------------------------------------------------------------- 1 | using FluentNHibernate.Automapping; 2 | using FluentNHibernate.Automapping.Alterations; 3 | using MultiTenancyFramework.Entities; 4 | 5 | namespace MultiTenancyFramework.NHibernate.Maps 6 | { 7 | public class UserRoleMap : IAutoMappingOverride 8 | { 9 | public void Override(AutoMapping mapping) 10 | { 11 | mapping.Map(x => x.Privileges).VarCharMax(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/NHManager/Conventions/ClassMappingConvention.cs: -------------------------------------------------------------------------------- 1 | using FluentNHibernate.Conventions; 2 | using FluentNHibernate.Conventions.Instances; 3 | using MultiTenancyFramework.NHibernate.NHManager.Listeners; 4 | 5 | namespace MultiTenancyFramework.NHibernate.NHManager.Conventions 6 | { 7 | public class ClassMappingConvention : IClassConvention 8 | { 9 | public void Apply(IClassInstance instance) 10 | { 11 | //Table name rule 12 | var tableName = instance.EntityType.Name.ToPlural(); 13 | if (ConfigurationHelper.AppSettingsItem("UseLowercaseTableNames")) 14 | { 15 | tableName = tableName.ToLowerInvariant(); 16 | } 17 | instance.Table(tableName); 18 | //To filter queries based on what I've defined in the Tenant filter definition 19 | 20 | instance.ApplyFilter(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/NHManager/Conventions/EnumMappingConvention.cs: -------------------------------------------------------------------------------- 1 | using FluentNHibernate.Conventions; 2 | using FluentNHibernate.Conventions.AcceptanceCriteria; 3 | using FluentNHibernate.Conventions.Inspections; 4 | using FluentNHibernate.Conventions.Instances; 5 | using System; 6 | 7 | namespace MultiTenancyFramework.NHibernate.NHManager.Conventions 8 | { 9 | public class EnumMappingConvention : IPropertyConvention, IPropertyConventionAcceptance 10 | { 11 | public void Accept(IAcceptanceCriteria criteria) 12 | { 13 | criteria.Expect(x => x.Property.PropertyType.IsEnum || 14 | (x.Property.PropertyType.IsNullable() && 15 | Nullable.GetUnderlyingType(x.Property.PropertyType).IsEnum) 16 | ); 17 | } 18 | 19 | public void Apply(IPropertyInstance instance) 20 | { 21 | instance.CustomType(instance.Property.PropertyType); 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/NHManager/Conventions/InstitutionCodePropertyConvention.cs: -------------------------------------------------------------------------------- 1 | using FluentNHibernate.Conventions; 2 | using FluentNHibernate.Conventions.Instances; 3 | 4 | namespace MultiTenancyFramework.NHibernate.NHManager.Conventions 5 | { 6 | public class InstitutionCodePropertyConvention : IPropertyConvention 7 | { 8 | public void Apply(IPropertyInstance instance) 9 | { 10 | if (!ConfigurationHelper.AppSettingsItem("SingleTenant")) 11 | { 12 | Entities.BaseEntity e; 13 | if (instance.Name == nameof(e.InstitutionCode) && instance.Property.PropertyType == typeof(string)) 14 | { 15 | instance.Index("ind_InstitutionCode"); 16 | } 17 | } 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/NHManager/Conventions/ReferencesConvention.cs: -------------------------------------------------------------------------------- 1 | using FluentNHibernate.Conventions; 2 | using FluentNHibernate.Conventions.Instances; 3 | 4 | namespace MultiTenancyFramework.NHibernate.NHManager.Conventions 5 | { 6 | public class ReferencesConvention : IReferenceConvention 7 | { 8 | public void Apply(IManyToOneInstance instance) 9 | { 10 | instance.Column((instance.Property.Name.StartsWith("The") 11 | ? instance.Property.Name.Remove(0, 3) 12 | : instance.Property.Name) + "Id"); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/NHManager/DbSessionCleanup.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using System.Collections.Generic; 3 | 4 | namespace MultiTenancyFramework.NHibernate.NHManager 5 | { 6 | public class DbSessionCleanup : IDbSessionCleanup 7 | { 8 | public void CloseDbConnections() 9 | { 10 | var storageSet = new Dictionary(NHSessionManager.SessionStorages); 11 | if (storageSet != null && storageSet.Count > 0) 12 | { 13 | foreach (var storage in storageSet.Values) 14 | { 15 | //Closes the session if there's any open session 16 | if (storage != null && storage.Session != null) 17 | { 18 | NHSessionManager.CloseStorage(((WebSessionStorage)storage)?.InstitutionCode); 19 | } 20 | } 21 | storageSet.Clear(); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/NHManager/ISessionStorage.cs: -------------------------------------------------------------------------------- 1 | using NHibernate; 2 | 3 | namespace MultiTenancyFramework.NHibernate.NHManager 4 | { 5 | /// 6 | /// Provides a standard interface for managing session storage 7 | /// 8 | public interface ISessionStorage 9 | { 10 | ISession Session { get; set; } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/NHManager/Listeners/AppFilterDefinition.cs: -------------------------------------------------------------------------------- 1 | using FluentNHibernate.Mapping; 2 | using NHibernate; 3 | 4 | namespace MultiTenancyFramework.NHibernate.NHManager.Listeners 5 | { 6 | internal class AppFilterDefinition : FilterDefinition 7 | { 8 | public AppFilterDefinition() 9 | { 10 | if (!ConfigurationHelper.AppSettingsItem("SingleTenant")) 11 | { 12 | //Where IsDeleted != true AND InstitutionCode = :instCode 13 | WithName(Utilities.InstitutionFilterName) 14 | .WithCondition($"{Utilities.SoftDeletePropertyName} != :{Utilities.SoftDeleteParamName} AND {Utilities.InstitutionCodePropertyName} = :{Utilities.InstitutionCodeQueryParamName}") 15 | .AddParameter(Utilities.InstitutionCodeQueryParamName, NHibernateUtil.String) 16 | .AddParameter(Utilities.SoftDeleteParamName, NHibernateUtil.Boolean); 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/NHManager/Listeners/MySqlExceptionConverter.cs: -------------------------------------------------------------------------------- 1 | //using MySql.Data.MySqlClient; 2 | //using NHibernate; 3 | using NHibernate.Exceptions; 4 | using System; 5 | 6 | namespace MultiTenancyFramework.NHibernate.NHManager.Listeners 7 | { 8 | public class MySqlExceptionConverter : ISQLExceptionConverter 9 | { 10 | public Exception Convert(AdoExceptionContextInfo exInfo) 11 | { 12 | Utilities.Logger.Log("Inside our SqlExceptionConverter: EntityId: {0}. EntityName: {1}\nMessage: {2}.", exInfo.EntityId, exInfo.EntityName, exInfo.Message); 13 | //var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as MySqlException; 14 | //if (sqle != null) 15 | //{ 16 | // switch (sqle.Number) 17 | // { 18 | // case 547: 19 | // return new ConstraintViolationException(exInfo.Message, 20 | // sqle.InnerException, exInfo.Sql, null); 21 | // case 208: 22 | // return new SQLGrammarException(exInfo.Message, 23 | // sqle.InnerException, exInfo.Sql); 24 | // case 3960: 25 | // return new StaleObjectStateException(exInfo.EntityName, exInfo.EntityId); 26 | // } 27 | //} 28 | return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException, 29 | exInfo.Message, exInfo.Sql); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/NHManager/NonWebSessionStorage.cs: -------------------------------------------------------------------------------- 1 | using NHibernate; 2 | 3 | namespace MultiTenancyFramework.NHibernate.NHManager 4 | { 5 | /// 6 | /// Basic implementation of for use when a non-web session is desired 7 | /// 8 | public class NonWebSessionStorage : ISessionStorage 9 | { 10 | //public string InstitutionCode { get; set; } 11 | 12 | public ISession Session { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/NHManager/WebSessionStorage.cs: -------------------------------------------------------------------------------- 1 | using NHibernate; 2 | 3 | namespace MultiTenancyFramework.NHibernate.NHManager 4 | { 5 | /// 6 | /// Implements via the session-per-request pattern 7 | /// Handles storage of Nhibernate Storage using the HttpContext and Closes the session at the end of the HttpRequest. 8 | /// 9 | public class WebSessionStorage : ISessionStorage 10 | { 11 | /// 12 | /// Constant key for storing the session in the HttpContext 13 | /// 14 | public const string CurrentSessionKey = "::nhibernate_current_session::"; 15 | 16 | public string InstitutionCode { get; set; } 17 | public ISession Session { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/NHUtils.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Entities; 2 | using System; 3 | using System.Web; 4 | 5 | namespace MultiTenancyFramework.NHibernate 6 | { 7 | public class NHUtils 8 | { 9 | public static AppUser CurrentUser 10 | { 11 | get 12 | { 13 | try 14 | { 15 | return HttpContext.Current.Session["::SS_CURRENT_USER::"] as AppUser; 16 | } 17 | catch (Exception) 18 | { 19 | return null; 20 | } 21 | 22 | } 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/PrivilegeDAO.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using MultiTenancyFramework.Entities; 3 | 4 | namespace MultiTenancyFramework.NHibernate 5 | { 6 | public class PrivilegeDAO : PrivilegeDAO, IPrivilegeDAO 7 | { 8 | } 9 | 10 | public class PrivilegeDAO : CoreDAO, IPrivilegeDAO where T : Privilege 11 | { 12 | public PrivilegeDAO() 13 | { 14 | EntityName = NHManager.NHSessionManager.GetEntityNameToUseInNHSession(typeof(T)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Queries/GetAppUserByUserRoleQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace MultiTenancyFramework.NHibernate.Queries 7 | { 8 | public sealed class GetAppUserByUserRoleQueryHandler 9 | : CoreGeneralDAO, IDbQueryHandler> 10 | { 11 | public GetAppUserByUserRoleQueryHandler() 12 | { 13 | EntityName = NHManager.NHSessionManager.GetEntityNameToUseInNHSession(typeof(AppUser)); 14 | } 15 | 16 | public IList Handle(GetAppUserByUserRoleQuery theQuery) 17 | { 18 | var session = BuildSession(); 19 | var query = session.Query(EntityName) 20 | .Where(x => x.UserRoles.Contains($"{theQuery.UserRoleId},")); 21 | return query.ToList(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Queries/GetAppUserByUsernameQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using System.Linq; 4 | 5 | namespace MultiTenancyFramework.NHibernate.Queries 6 | { 7 | public sealed class GetAppUserByUsernameQueryHandler 8 | : CoreGeneralDAO, IDbQueryHandler 9 | { 10 | public GetAppUserByUsernameQueryHandler() 11 | { 12 | EntityName = NHManager.NHSessionManager.GetEntityNameToUseInNHSession(typeof(AppUser)); 13 | } 14 | 15 | public AppUser Handle(GetAppUserByUsernameQuery theQuery) 16 | { 17 | var session = BuildSession(); 18 | var query = session.Query(EntityName) 19 | .Where(x => x.UserName == theQuery.Username); 20 | return query.SingleOrDefault(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Queries/GetDatabaseConnectionByNameAndConnectionStringQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using System.Linq; 4 | 5 | namespace MultiTenancyFramework.NHibernate.Queries 6 | { 7 | public sealed class GetDatabaseConnectionByNameAndConnectionStringQueryHandler 8 | : CoreGeneralDAO, IDbQueryHandler 9 | { 10 | public DatabaseConnection Handle(GetDatabaseConnectionByNameAndConnectionStringQuery theQuery) 11 | { 12 | var session = BuildSession(); 13 | var query = session.Query() 14 | .Where(x => x.Name == theQuery.Name && x.ConnectionString == theQuery.ConnectionString); 15 | return query.SingleOrDefault(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Queries/GetEntitiesAppearingInAuditLogsQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace MultiTenancyFramework.NHibernate.Queries 7 | { 8 | public class GetEntitiesAppearingInAuditLogsQueryHandler : CoreGeneralDAO, IDbQueryHandler> 9 | { 10 | public IList Handle(GetEntitiesAppearingInAuditLogsQuery theQuery) 11 | { 12 | var session = BuildSession(); 13 | 14 | var query = session.Query() 15 | .Where(x => x.Entity != null) 16 | .OrderBy(t => t.Entity).Select(s => s.Entity).Distinct(); 17 | return query.ToList(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Queries/GetIAppUserByEmailQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using System.Linq; 4 | 5 | namespace MultiTenancyFramework.NHibernate.Queries 6 | { 7 | public sealed class GetIAppUserByEmailQueryHandler 8 | : CoreGeneralDAO, IDbQueryHandler 9 | { 10 | public GetIAppUserByEmailQueryHandler() 11 | { 12 | EntityName = NHManager.NHSessionManager.GetEntityNameToUseInNHSession(typeof(AppUser)); 13 | } 14 | 15 | public AppUser Handle(GetAppUserByEmailQuery theQuery) 16 | { 17 | var session = BuildSession(); 18 | var query = session.Query(EntityName) 19 | .Where(x => x.Email == theQuery.Email); 20 | return query.SingleOrDefault(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Queries/GetInstitutionByCodeQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using System.Linq; 4 | 5 | namespace MultiTenancyFramework.NHibernate.Queries 6 | { 7 | public class GetInstitutionByCodeQueryHandler : CoreGeneralDAO, IDbQueryHandler 8 | { 9 | public GetInstitutionByCodeQueryHandler() 10 | { 11 | EntityName = NHManager.NHSessionManager.GetEntityNameToUseInNHSession(typeof(Institution)); 12 | } 13 | 14 | public Institution Handle(GetInstitutionByCodeQuery theQuery) 15 | { 16 | InstitutionCode = null; 17 | var session = BuildSession(); 18 | var query = session.Query(EntityName).Where(x => x.Code == theQuery.Code); 19 | return query.SingleOrDefault(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Queries/GetPhotosByOwnerIdAndImageTypeQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using System.Collections.Generic; 4 | 5 | namespace MultiTenancyFramework.NHibernate.Queries 6 | { 7 | public sealed class GetPhotosByOwnerIdAndImageTypeQueryHandler 8 | : CoreGeneralDAO, IDbQueryHandler> 9 | { 10 | public IList Handle(GetPhotosByOwnerIdAndImageTypeQuery theQuery) 11 | { 12 | if (string.IsNullOrWhiteSpace(theQuery.OwnerID)) return new List(); 13 | 14 | var session = BuildSession(); 15 | var query = session.QueryOver() 16 | .Where(x => x.OwnerID == theQuery.OwnerID) 17 | .And(x => x.ImageType == theQuery.ImageType); 18 | return query.List(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Queries/GetPrivilegesByGridSearchParamsQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data; 2 | using MultiTenancyFramework.Data.Queries; 3 | using MultiTenancyFramework.Entities; 4 | using System.Linq; 5 | 6 | namespace MultiTenancyFramework.NHibernate.Queries 7 | { 8 | public class GetPrivilegesByGridSearchParamsQueryHandler : CoreGeneralWithGridPagingDAO, IDbQueryHandler> 9 | { 10 | public GetPrivilegesByGridSearchParamsQueryHandler() 11 | { 12 | EntityName = NHManager.NHSessionManager.GetEntityNameToUseInNHSession(typeof(Privilege)); 13 | } 14 | 15 | public RetrievedData Handle(GetPrivilegesByGridSearchParamsQuery theQuery) 16 | { 17 | var session = BuildSession(); 18 | var query = session.Query(EntityName); 19 | if (!string.IsNullOrWhiteSpace(theQuery.Name)) 20 | { 21 | query = query.Where(x => x.Name.Contains(theQuery.Name) || x.DisplayName.Contains(theQuery.Name)); 22 | } 23 | if (theQuery.AccessScope.HasValue && theQuery.AccessScope.Value > 0) 24 | { 25 | query = query.Where(x => x.Scope == theQuery.AccessScope.Value); 26 | } 27 | return RetrieveUsingPaging(query, theQuery.PageIndex, theQuery.PageSize); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Queries/GetUserClaimsByUserIdQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace MultiTenancyFramework.NHibernate.Queries 7 | { 8 | public class GetUserClaimsByUserIdQueryHandler : CoreGeneralDAO, IDbQueryHandler> 9 | { 10 | public IList Handle(GetUserClaimsByUserIdQuery theQuery) 11 | { 12 | var session = BuildSession(); 13 | var query = session.Query().Where(x => x.UserId == theQuery.UserId); 14 | return query.ToList(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Queries/GetUserLoginByLoginProviderKeyAndUserIdQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using System.Linq; 4 | 5 | namespace MultiTenancyFramework.NHibernate.Queries 6 | { 7 | public class GetUserLoginByLoginProviderKeyAndUserIdQueryHandler : CoreGeneralDAO, IDbQueryHandler 8 | { 9 | public UserLogin Handle(GetUserLoginByLoginProviderKeyAndUserIdQuery theQuery) 10 | { 11 | var session = BuildSession(); 12 | var query = session.Query() 13 | .Where(x => x.LoginProvider == theQuery.LoginProvider && x.ProviderKey == theQuery.ProviderKey); 14 | if (theQuery.UserID > 0) 15 | { 16 | query = query.Where(x => x.UserId == theQuery.UserID); 17 | } 18 | return query.SingleOrDefault(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Queries/GetUserLoginssByUserIdQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace MultiTenancyFramework.NHibernate.Queries 7 | { 8 | public class GetUserLoginssByUserIdQueryHandler : CoreGeneralDAO, IDbQueryHandler> 9 | { 10 | public IList Handle(GetUserLoginsByUserIdQuery theQuery) 11 | { 12 | var session = BuildSession(); 13 | var query = session.Query().Where(x => x.UserId == theQuery.UserId); 14 | return query.ToList(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/Queries/GetUserRoleByNameQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Data.Queries; 2 | using MultiTenancyFramework.Entities; 3 | using System.Linq; 4 | 5 | namespace MultiTenancyFramework.NHibernate.Queries 6 | { 7 | public sealed class GetUserRoleByNameQueryHandler 8 | : CoreGeneralDAO, IDbQueryHandler 9 | { 10 | public UserRole Handle(GetUserRoleByNameQuery theQuery) 11 | { 12 | var session = BuildSession(); 13 | var query = session.Query() 14 | .Where(x => x.Name == theQuery.Name); 15 | return query.SingleOrDefault(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/TaskManager/GetTaskByTypeQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyFramework.Core.TaskManager; 2 | using MultiTenancyFramework.Data.Queries; 3 | using System.Linq; 4 | using NHibernate.Linq; 5 | using System.Threading.Tasks; 6 | using System.Threading; 7 | 8 | namespace MultiTenancyFramework.NHibernate.TaskManager 9 | { 10 | public class GetTaskByTypeQueryHandler : CoreGeneralDAO, IDbQueryHandlerAsync 11 | { 12 | public async Task Handle(GetTaskByTypeQuery theQuery, CancellationToken token = default(CancellationToken)) 13 | { 14 | if (string.IsNullOrWhiteSpace(theQuery.Type)) 15 | return null; 16 | 17 | var session = BuildSession(); 18 | var query = session.Query() 19 | .Where(x => x.Type == theQuery.Type) 20 | .OrderByDescending(x => x.Id); 21 | 22 | return await query.FirstOrDefaultAsync(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/TaskManager/ScheduleTaskMap.cs: -------------------------------------------------------------------------------- 1 | using FluentNHibernate.Automapping; 2 | using FluentNHibernate.Automapping.Alterations; 3 | using MultiTenancyFramework.Core.TaskManager; 4 | 5 | namespace MultiTenancyFramework.NHibernate.TaskManager 6 | { 7 | public class ScheduleTaskMap : IAutoMappingOverride 8 | { 9 | public void Override(AutoMapping mapping) 10 | { 11 | mapping.Map(x => x.Name).Not.Nullable(); 12 | mapping.Map(x => x.Type).Not.Nullable(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/TaskManager/Tasks/LogMap.cs: -------------------------------------------------------------------------------- 1 | using FluentNHibernate.Automapping; 2 | using FluentNHibernate.Automapping.Alterations; 3 | using MultiTenancyFramework.NHibernate.Maps; 4 | using MultiTenancyFramework.Entities; 5 | 6 | namespace MultiTenancyFramework.NHibernate.TaskManager.Tasks 7 | { 8 | public class LogMap : IAutoMappingOverride 9 | { 10 | public void Override(AutoMapping mapping) 11 | { 12 | mapping.Map(x => x.ShortMessage).VarCharMax(); 13 | mapping.Map(x => x.FullMessage).VarCharMax(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/TaskManager/Tasks/QueuedEmailMap.cs: -------------------------------------------------------------------------------- 1 | using FluentNHibernate.Automapping; 2 | using FluentNHibernate.Automapping.Alterations; 3 | using MultiTenancyFramework.Core.TaskManager.Tasks; 4 | using MultiTenancyFramework.NHibernate.Maps; 5 | 6 | namespace MultiTenancyFramework.NHibernate.TaskManager.Tasks 7 | { 8 | public class QueuedEmailMap : IAutoMappingOverride 9 | { 10 | public void Override(AutoMapping mapping) 11 | { 12 | mapping.Map(x => x.Receivers).Length(1000); 13 | mapping.Map(x => x.Subject).Length(1000); 14 | mapping.Map(x => x.Body).VarCharMax(); 15 | //mapping.References(x => x.EmailAccount).Fetch.Join(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/app.config.uninstall.xdt: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /MultiTenancyFramework.NHibernate/web.config.uninstall.xdt: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Utils/EnumDescriptionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MultiTenancyFramework 4 | { 5 | /// 6 | /// Use this to provide an alternative or more readable name for your enum 7 | /// 8 | [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] 9 | public class EnumDescriptionAttribute : Attribute 10 | { 11 | private string _name; 12 | public EnumDescriptionAttribute(string name) 13 | { 14 | _name = name; 15 | } 16 | 17 | /// 18 | /// The alternative name 19 | /// 20 | public string Name { get { return _name; } } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Utils/MultiTenancyFramework.Utils.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $id$ 5 | 1.1.0.0 6 | $title$ 7 | $author$ 8 | $author$ 9 | http://codedrum.blogspot.com/2016/08/MultiTenancyFramework.html 10 | false 11 | $description$ 12 | Read more at https://github.com/smbadiwe/MultiTenancyFramework/wiki. Drop a note if need be. 13 | $copyright$ 14 | SaaS MultiTenant MultiTenancy Framework Software-as-a-Service 15 | 16 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Utils/Utility/AsyncHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | namespace MultiTenancyFramework 6 | { 7 | public class AsyncHelper 8 | { 9 | private static readonly TaskFactory _myTaskFactory = new 10 | TaskFactory(CancellationToken.None, 11 | TaskCreationOptions.None, 12 | TaskContinuationOptions.None, 13 | TaskScheduler.Default); 14 | 15 | public static TResult RunSync(Task task) 16 | { 17 | return task 18 | .GetAwaiter() 19 | .GetResult(); 20 | } 21 | 22 | public static void RunSync(Task task) 23 | { 24 | task 25 | .GetAwaiter() 26 | .GetResult(); 27 | } 28 | 29 | public static TResult RunSync(Func> func) 30 | { 31 | return _myTaskFactory 32 | .StartNew(func) 33 | .Unwrap() 34 | .GetAwaiter() 35 | .GetResult(); 36 | } 37 | 38 | public static void RunSync(Func func) 39 | { 40 | _myTaskFactory 41 | .StartNew(func) 42 | .Unwrap() 43 | .GetAwaiter() 44 | .GetResult(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /MultiTenancyFramework.Utils/Utility/ILogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MultiTenancyFramework 4 | { 5 | public enum LoggingLevel 6 | { 7 | Trace, 8 | Debug, 9 | Info, 10 | Warn, 11 | Error, 12 | Fatal 13 | } 14 | 15 | public interface ILogger 16 | { 17 | void LogToDb(bool saveToDb); 18 | 19 | void SetLogger(object logger); 20 | 21 | void Log(Exception ex, bool isFatal = false); 22 | 23 | void Trace(string format, params object[] args); 24 | 25 | void Error(string format, params object[] args); 26 | 27 | void Info(string format, params object[] args); 28 | 29 | /// 30 | /// Logs the specified message using 31 | /// 32 | /// The message format. 33 | /// The arguments. 34 | void Log(string format, params object[] args); 35 | 36 | void Log(LoggingLevel level, string format, params object[] args); 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MultiTenancyFramework 2 | Everything you need to jump-start building multi-tenant applications in C# using any framework of your choice. 3 | 4 | The goal of this project is to provide the framework needed to build multi-tenant .NET applications (also known as Software-as-a-Service, SaaS) while using your preferred choice of ORM (NHibernate, EntityFramework, Dapper etc), 5 | IoC Container (SimpleInjector, AutoFac, StructureMap, Unity, etc) and web frameworks (MVC, NancyFx). 6 | 7 | Learn more on [the Wiki page](https://github.com/smbadiwe/MultiTenancyFramework/wiki) 8 | 9 | You can [get started quickly](https://github.com/smbadiwe/MultiTenancyFramework/wiki/Getting-Started) to build your SaaS, focusing on the actual business solution you're contracted to build. 10 | 11 | And, feel free to ask questions or [contribute to the project](https://github.com/smbadiwe/MultiTenancyFramework/wiki/How-To-Contribute). 12 | -------------------------------------------------------------------------------- /SolutionItems/ArchitectureDiagram.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbadiwe/MultiTenancyFramework/670277f442d1e5673437723f794b8e3a1dcdb080/SolutionItems/ArchitectureDiagram.odg -------------------------------------------------------------------------------- /SolutionItems/SolutionArchitecture.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbadiwe/MultiTenancyFramework/670277f442d1e5673437723f794b8e3a1dcdb080/SolutionItems/SolutionArchitecture.PNG -------------------------------------------------------------------------------- /Tests/MultiTenancyFramework.Core.Tests/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MultiTenancyFramework.Core.Tests 8 | { 9 | public class Class1 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Tests/MultiTenancyFramework.Core.Tests/Extensions/OtherExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | namespace MultiTenancyFramework.Tests 4 | { 5 | [TestFixture] 6 | public class OtherExtensionsTests 7 | { 8 | [Test] 9 | public void GetNameTest() 10 | { 11 | Assert.AreEqual(int.MaxValue.ToString(), OtherExtensions.GetName(x => int.MaxValue)); 12 | } 13 | 14 | [Test] 15 | public void GetNameTest2() 16 | { 17 | Assert.AreEqual("32", OtherExtensions.GetName(x => 32)); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Tests/MultiTenancyFramework.Core.Tests/Extensions/StringExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace MultiTenancyFramework.Core.Tests.Extensions 6 | { 7 | [TestFixture] 8 | public class StringExtensionsTests 9 | { 10 | [Test] 11 | public void AsSplitPascalCasedString_one_word() 12 | { 13 | Assert.AreEqual("Soma", StringExtensions.AsSplitPascalCasedString("Soma")); 14 | } 15 | 16 | [Test] 17 | public void AsSplitPascalCasedString_two_words() 18 | { 19 | Assert.AreEqual("Soma Dina", StringExtensions.AsSplitPascalCasedString("SomaDina")); 20 | } 21 | 22 | [Test] 23 | public void AsSplitPascalCasedString_words_with_abbrev() 24 | { 25 | Assert.AreEqual("Soma ID Next", StringExtensions.AsSplitPascalCasedString("SomaIDNext")); 26 | } 27 | 28 | [Test] 29 | public void AsSplitPascalCasedString_words_with_number() 30 | { 31 | Assert.AreEqual("GL 12 Version", StringExtensions.AsSplitPascalCasedString("GL12Version")); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Tests/MultiTenancyFramework.Core.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /WebAPI/MultiTenancyFramework.WebAPI/GlobalExceptionFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | using System.Web.Http.Filters; 4 | 5 | namespace MultiTenancyFramework.WebAPI 6 | { 7 | public class GlobalExceptionFilterAttribute : ExceptionFilterAttribute 8 | { 9 | //Exception Filters are used whenever a controller action throws an unhandled 10 | // exception that is not an HttpResponseException. 11 | public override void OnException(HttpActionExecutedContext context) 12 | { 13 | //TODO: GlobalExceptionFilterAttribute 14 | base.OnException(context); 15 | } 16 | 17 | public override Task OnExceptionAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken) 18 | { 19 | //TODO: GlobalExceptionFilterAttribute 20 | return base.OnExceptionAsync(actionExecutedContext, cancellationToken); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WebAPI/MultiTenancyFramework.WebAPI/GlobalExceptionHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | using System.Web.Http.ExceptionHandling; 4 | 5 | namespace MultiTenancyFramework.WebAPI 6 | { 7 | public class GlobalExceptionHandler : ExceptionHandler 8 | { 9 | //Exception Handlers are called after Exception Filters and Exception Loggers, 10 | // and only if the exception has not already been handled. 11 | public override void Handle(ExceptionHandlerContext context) 12 | { 13 | //TODO: Implement GlobalExceptionHandler 14 | base.Handle(context); 15 | } 16 | 17 | public override Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken) 18 | { 19 | //TODO: Implement GlobalExceptionHandler 20 | return base.HandleAsync(context, cancellationToken); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WebAPI/MultiTenancyFramework.WebAPI/GlobalExceptionLogger.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | using System.Web.Http.ExceptionHandling; 4 | 5 | namespace MultiTenancyFramework.WebAPI 6 | { 7 | public class GlobalExceptionLogger : ExceptionLogger 8 | { 9 | public override void Log(ExceptionLoggerContext context) 10 | { 11 | //TODO: Do whatever logging you need to do here. 12 | base.Log(context); 13 | } 14 | 15 | public override Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken) 16 | { 17 | //TODO: Do whatever logging you need to do here. 18 | return base.LogAsync(context, cancellationToken); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /WebAPI/MultiTenancyFramework.WebAPI/GlobalWebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Owin.Security.OAuth; 2 | using System.Web.Http; 3 | using System.Web.Http.ExceptionHandling; 4 | 5 | namespace MultiTenancyFramework.WebAPI 6 | { 7 | public static class GlobalWebApiConfig 8 | { 9 | public static void Register(HttpConfiguration config) 10 | { 11 | // Web API configuration and services 12 | // Configure Web API to use only bearer token authentication. 13 | config.SuppressDefaultHostAuthentication(); 14 | config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); 15 | 16 | config.Filters.Add(new GlobalAuthorizeAttribute()); 17 | config.Filters.Add(new GlobalExceptionFilterAttribute()); 18 | config.Services.Replace(typeof(IExceptionLogger), new GlobalExceptionLogger()); 19 | config.Services.Replace(typeof(IExceptionHandler), new GlobalExceptionHandler()); 20 | 21 | // Web API routes 22 | config.MapHttpAttributeRoutes(); 23 | 24 | GlobalWebApiRoutesConfig.RegisterRoutes(config.Routes); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WebAPI/MultiTenancyFramework.WebAPI/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /WebApiTest/App_Start/BundleConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Optimization; 3 | 4 | namespace WebApiTest 5 | { 6 | public class BundleConfig 7 | { 8 | // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862 9 | public static void RegisterBundles(BundleCollection bundles) 10 | { 11 | bundles.Add(new ScriptBundle("~/bundles/jquery").Include( 12 | "~/Scripts/jquery-{version}.js")); 13 | 14 | // Use the development version of Modernizr to develop with and learn from. Then, when you're 15 | // ready for production, use the build tool at http://modernizr.com to pick only the tests you need. 16 | bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( 17 | "~/Scripts/modernizr-*")); 18 | 19 | bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( 20 | "~/Scripts/bootstrap.js", 21 | "~/Scripts/respond.js")); 22 | 23 | bundles.Add(new StyleBundle("~/Content/css").Include( 24 | "~/Content/bootstrap.css", 25 | "~/Content/site.css")); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /WebApiTest/App_Start/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Mvc; 3 | 4 | namespace WebApiTest 5 | { 6 | public class FilterConfig 7 | { 8 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 9 | { 10 | filters.Add(new HandleErrorAttribute()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /WebApiTest/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace WebApiTest 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WebApiTest/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Http; 5 | using System.Web.Http; 6 | using Microsoft.Owin.Security.OAuth; 7 | using Newtonsoft.Json.Serialization; 8 | 9 | namespace WebApiTest 10 | { 11 | public static class WebApiConfig 12 | { 13 | public static void Register(HttpConfiguration config) 14 | { 15 | // Web API configuration and services 16 | // Configure Web API to use only bearer token authentication. 17 | config.SuppressDefaultHostAuthentication(); 18 | config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); 19 | 20 | // Web API routes 21 | config.MapHttpAttributeRoutes(); 22 | 23 | config.Routes.MapHttpRoute( 24 | name: "DefaultApi", 25 | routeTemplate: "api/{controller}/{id}", 26 | defaults: new { id = RouteParameter.Optional } 27 | ); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/HelpPageAreaRegistration.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | using System.Web.Mvc; 3 | 4 | namespace WebApiTest.Areas.HelpPage 5 | { 6 | public class HelpPageAreaRegistration : AreaRegistration 7 | { 8 | public override string AreaName 9 | { 10 | get 11 | { 12 | return "HelpPage"; 13 | } 14 | } 15 | 16 | public override void RegisterArea(AreaRegistrationContext context) 17 | { 18 | context.MapRoute( 19 | "HelpPage_Default", 20 | "Help/{action}/{apiId}", 21 | new { controller = "Help", action = "Index", apiId = UrlParameter.Optional }); 22 | 23 | HelpPageConfig.Register(GlobalConfiguration.Configuration); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/ModelDescriptions/CollectionModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace WebApiTest.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class CollectionModelDescription : ModelDescription 4 | { 5 | public ModelDescription ElementDescription { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/ModelDescriptions/ComplexTypeModelDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | 3 | namespace WebApiTest.Areas.HelpPage.ModelDescriptions 4 | { 5 | public class ComplexTypeModelDescription : ModelDescription 6 | { 7 | public ComplexTypeModelDescription() 8 | { 9 | Properties = new Collection(); 10 | } 11 | 12 | public Collection Properties { get; private set; } 13 | } 14 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/ModelDescriptions/DictionaryModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace WebApiTest.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class DictionaryModelDescription : KeyValuePairModelDescription 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/ModelDescriptions/EnumTypeModelDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | 4 | namespace WebApiTest.Areas.HelpPage.ModelDescriptions 5 | { 6 | public class EnumTypeModelDescription : ModelDescription 7 | { 8 | public EnumTypeModelDescription() 9 | { 10 | Values = new Collection(); 11 | } 12 | 13 | public Collection Values { get; private set; } 14 | } 15 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/ModelDescriptions/EnumValueDescription.cs: -------------------------------------------------------------------------------- 1 | namespace WebApiTest.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class EnumValueDescription 4 | { 5 | public string Documentation { get; set; } 6 | 7 | public string Name { get; set; } 8 | 9 | public string Value { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/ModelDescriptions/IModelDocumentationProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace WebApiTest.Areas.HelpPage.ModelDescriptions 5 | { 6 | public interface IModelDocumentationProvider 7 | { 8 | string GetDocumentation(MemberInfo member); 9 | 10 | string GetDocumentation(Type type); 11 | } 12 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/ModelDescriptions/KeyValuePairModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace WebApiTest.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class KeyValuePairModelDescription : ModelDescription 4 | { 5 | public ModelDescription KeyModelDescription { get; set; } 6 | 7 | public ModelDescription ValueModelDescription { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/ModelDescriptions/ModelDescription.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiTest.Areas.HelpPage.ModelDescriptions 4 | { 5 | /// 6 | /// Describes a type model. 7 | /// 8 | public abstract class ModelDescription 9 | { 10 | public string Documentation { get; set; } 11 | 12 | public Type ModelType { get; set; } 13 | 14 | public string Name { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/ModelDescriptions/ModelNameAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiTest.Areas.HelpPage.ModelDescriptions 4 | { 5 | /// 6 | /// Use this attribute to change the name of the generated for a type. 7 | /// 8 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum, AllowMultiple = false, Inherited = false)] 9 | public sealed class ModelNameAttribute : Attribute 10 | { 11 | public ModelNameAttribute(string name) 12 | { 13 | Name = name; 14 | } 15 | 16 | public string Name { get; private set; } 17 | } 18 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/ModelDescriptions/ParameterAnnotation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiTest.Areas.HelpPage.ModelDescriptions 4 | { 5 | public class ParameterAnnotation 6 | { 7 | public Attribute AnnotationAttribute { get; set; } 8 | 9 | public string Documentation { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/ModelDescriptions/ParameterDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | 4 | namespace WebApiTest.Areas.HelpPage.ModelDescriptions 5 | { 6 | public class ParameterDescription 7 | { 8 | public ParameterDescription() 9 | { 10 | Annotations = new Collection(); 11 | } 12 | 13 | public Collection Annotations { get; private set; } 14 | 15 | public string Documentation { get; set; } 16 | 17 | public string Name { get; set; } 18 | 19 | public ModelDescription TypeDescription { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/ModelDescriptions/SimpleTypeModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace WebApiTest.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class SimpleTypeModelDescription : ModelDescription 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/SampleGeneration/ImageSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiTest.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents an image sample on the help page. There's a display template named ImageSample associated with this class. 7 | /// 8 | public class ImageSample 9 | { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// The URL of an image. 14 | public ImageSample(string src) 15 | { 16 | if (src == null) 17 | { 18 | throw new ArgumentNullException("src"); 19 | } 20 | Src = src; 21 | } 22 | 23 | public string Src { get; private set; } 24 | 25 | public override bool Equals(object obj) 26 | { 27 | ImageSample other = obj as ImageSample; 28 | return other != null && Src == other.Src; 29 | } 30 | 31 | public override int GetHashCode() 32 | { 33 | return Src.GetHashCode(); 34 | } 35 | 36 | public override string ToString() 37 | { 38 | return Src; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/SampleGeneration/InvalidSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiTest.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents an invalid sample on the help page. There's a display template named InvalidSample associated with this class. 7 | /// 8 | public class InvalidSample 9 | { 10 | public InvalidSample(string errorMessage) 11 | { 12 | if (errorMessage == null) 13 | { 14 | throw new ArgumentNullException("errorMessage"); 15 | } 16 | ErrorMessage = errorMessage; 17 | } 18 | 19 | public string ErrorMessage { get; private set; } 20 | 21 | public override bool Equals(object obj) 22 | { 23 | InvalidSample other = obj as InvalidSample; 24 | return other != null && ErrorMessage == other.ErrorMessage; 25 | } 26 | 27 | public override int GetHashCode() 28 | { 29 | return ErrorMessage.GetHashCode(); 30 | } 31 | 32 | public override string ToString() 33 | { 34 | return ErrorMessage; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/SampleGeneration/SampleDirection.cs: -------------------------------------------------------------------------------- 1 | namespace WebApiTest.Areas.HelpPage 2 | { 3 | /// 4 | /// Indicates whether the sample is used for request or response 5 | /// 6 | public enum SampleDirection 7 | { 8 | Request = 0, 9 | Response 10 | } 11 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/SampleGeneration/TextSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApiTest.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents a preformatted text sample on the help page. There's a display template named TextSample associated with this class. 7 | /// 8 | public class TextSample 9 | { 10 | public TextSample(string text) 11 | { 12 | if (text == null) 13 | { 14 | throw new ArgumentNullException("text"); 15 | } 16 | Text = text; 17 | } 18 | 19 | public string Text { get; private set; } 20 | 21 | public override bool Equals(object obj) 22 | { 23 | TextSample other = obj as TextSample; 24 | return other != null && Text == other.Text; 25 | } 26 | 27 | public override int GetHashCode() 28 | { 29 | return Text.GetHashCode(); 30 | } 31 | 32 | public override string ToString() 33 | { 34 | return Text; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/Api.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using WebApiTest.Areas.HelpPage.Models 3 | @model HelpPageApiModel 4 | 5 | @{ 6 | var description = Model.ApiDescription; 7 | ViewBag.Title = description.HttpMethod.Method + " " + description.RelativePath; 8 | } 9 | 10 | 11 |
12 | 19 |
20 | @Html.DisplayForModel() 21 |
22 |
23 | -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/DisplayTemplates/ApiGroup.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using System.Web.Http.Controllers 3 | @using System.Web.Http.Description 4 | @using WebApiTest.Areas.HelpPage 5 | @using WebApiTest.Areas.HelpPage.Models 6 | @model IGrouping 7 | 8 | @{ 9 | var controllerDocumentation = ViewBag.DocumentationProvider != null ? 10 | ViewBag.DocumentationProvider.GetDocumentation(Model.Key) : 11 | null; 12 | } 13 | 14 |

@Model.Key.ControllerName

15 | @if (!String.IsNullOrEmpty(controllerDocumentation)) 16 | { 17 |

@controllerDocumentation

18 | } 19 | 20 | 21 | 22 | 23 | 24 | @foreach (var api in Model) 25 | { 26 | 27 | 28 | 38 | 39 | } 40 | 41 |
APIDescription
@api.HttpMethod.Method @api.RelativePath 29 | @if (api.Documentation != null) 30 | { 31 |

@api.Documentation

32 | } 33 | else 34 | { 35 |

No documentation available.

36 | } 37 |
-------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/DisplayTemplates/CollectionModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using WebApiTest.Areas.HelpPage.ModelDescriptions 2 | @model CollectionModelDescription 3 | @if (Model.ElementDescription is ComplexTypeModelDescription) 4 | { 5 | @Html.DisplayFor(m => m.ElementDescription) 6 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/DisplayTemplates/ComplexTypeModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using WebApiTest.Areas.HelpPage.ModelDescriptions 2 | @model ComplexTypeModelDescription 3 | @Html.DisplayFor(m => m.Properties, "Parameters") -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/DisplayTemplates/DictionaryModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using WebApiTest.Areas.HelpPage.ModelDescriptions 2 | @model DictionaryModelDescription 3 | Dictionary of @Html.DisplayFor(m => Model.KeyModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.KeyModelDescription }) [key] 4 | and @Html.DisplayFor(m => Model.ValueModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.ValueModelDescription }) [value] -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/DisplayTemplates/EnumTypeModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using WebApiTest.Areas.HelpPage.ModelDescriptions 2 | @model EnumTypeModelDescription 3 | 4 |

Possible enumeration values:

5 | 6 | 7 | 8 | 9 | 10 | 11 | @foreach (EnumValueDescription value in Model.Values) 12 | { 13 | 14 | 15 | 18 | 21 | 22 | } 23 | 24 |
NameValueDescription
@value.Name 16 |

@value.Value

17 |
19 |

@value.Documentation

20 |
-------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/DisplayTemplates/ImageSample.cshtml: -------------------------------------------------------------------------------- 1 | @using WebApiTest.Areas.HelpPage 2 | @model ImageSample 3 | 4 | -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/DisplayTemplates/InvalidSample.cshtml: -------------------------------------------------------------------------------- 1 | @using WebApiTest.Areas.HelpPage 2 | @model InvalidSample 3 | 4 | @if (HttpContext.Current.IsDebuggingEnabled) 5 | { 6 |
7 |

@Model.ErrorMessage

8 |
9 | } 10 | else 11 | { 12 |

Sample not available.

13 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/DisplayTemplates/KeyValuePairModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using WebApiTest.Areas.HelpPage.ModelDescriptions 2 | @model KeyValuePairModelDescription 3 | Pair of @Html.DisplayFor(m => Model.KeyModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.KeyModelDescription }) [key] 4 | and @Html.DisplayFor(m => Model.ValueModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.ValueModelDescription }) [value] -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/DisplayTemplates/ModelDescriptionLink.cshtml: -------------------------------------------------------------------------------- 1 | @using WebApiTest.Areas.HelpPage.ModelDescriptions 2 | @model Type 3 | @{ 4 | ModelDescription modelDescription = ViewBag.modelDescription; 5 | if (modelDescription is ComplexTypeModelDescription || modelDescription is EnumTypeModelDescription) 6 | { 7 | if (Model == typeof(Object)) 8 | { 9 | @:Object 10 | } 11 | else 12 | { 13 | @Html.ActionLink(modelDescription.Name, "ResourceModel", "Help", new { modelName = modelDescription.Name }, null) 14 | } 15 | } 16 | else if (modelDescription is CollectionModelDescription) 17 | { 18 | var collectionDescription = modelDescription as CollectionModelDescription; 19 | var elementDescription = collectionDescription.ElementDescription; 20 | @:Collection of @Html.DisplayFor(m => elementDescription.ModelType, "ModelDescriptionLink", new { modelDescription = elementDescription }) 21 | } 22 | else 23 | { 24 | @Html.DisplayFor(m => modelDescription) 25 | } 26 | } -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/DisplayTemplates/Samples.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Net.Http.Headers 2 | @model Dictionary 3 | 4 | @{ 5 | // Group the samples into a single tab if they are the same. 6 | Dictionary samples = Model.GroupBy(pair => pair.Value).ToDictionary( 7 | pair => String.Join(", ", pair.Select(m => m.Key.ToString()).ToArray()), 8 | pair => pair.Key); 9 | var mediaTypes = samples.Keys; 10 | } 11 |
12 | @foreach (var mediaType in mediaTypes) 13 | { 14 |

@mediaType

15 |
16 | Sample: 17 | @{ 18 | var sample = samples[mediaType]; 19 | if (sample == null) 20 | { 21 |

Sample not available.

22 | } 23 | else 24 | { 25 | @Html.DisplayFor(s => sample); 26 | } 27 | } 28 |
29 | } 30 |
-------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/DisplayTemplates/SimpleTypeModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using WebApiTest.Areas.HelpPage.ModelDescriptions 2 | @model SimpleTypeModelDescription 3 | @Model.Documentation -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/DisplayTemplates/TextSample.cshtml: -------------------------------------------------------------------------------- 1 | @using WebApiTest.Areas.HelpPage 2 | @model TextSample 3 | 4 |
5 | @Model.Text
6 | 
-------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/Index.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using System.Web.Http.Controllers 3 | @using System.Web.Http.Description 4 | @using System.Collections.ObjectModel 5 | @using WebApiTest.Areas.HelpPage.Models 6 | @model Collection 7 | 8 | @{ 9 | ViewBag.Title = "ASP.NET Web API Help Page"; 10 | 11 | // Group APIs by controller 12 | ILookup apiGroups = Model.ToLookup(api => api.ActionDescriptor.ControllerDescriptor); 13 | } 14 | 15 | 16 |
17 |
18 |
19 |

@ViewBag.Title

20 |
21 |
22 |
23 |
24 | 32 |
33 | @foreach (var group in apiGroups) 34 | { 35 | @Html.DisplayFor(m => group, "ApiGroup") 36 | } 37 |
38 |
39 | -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Help/ResourceModel.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using WebApiTest.Areas.HelpPage.ModelDescriptions 3 | @model ModelDescription 4 | 5 | 6 |
7 | 14 |

@Model.Name

15 |

@Model.Documentation

16 |
17 | @Html.DisplayFor(m => Model) 18 |
19 |
20 | -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @ViewBag.Title 7 | @RenderSection("scripts", required: false) 8 | 9 | 10 | @RenderBody() 11 | 12 | -------------------------------------------------------------------------------- /WebApiTest/Areas/HelpPage/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | // Change the Layout path below to blend the look and feel of the help page with your existing web pages 3 | Layout = "~/Views/Shared/_Layout.cshtml"; 4 | } -------------------------------------------------------------------------------- /WebApiTest/Content/Site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Set padding to keep content from hitting the edges */ 7 | .body-content { 8 | padding-left: 15px; 9 | padding-right: 15px; 10 | } 11 | 12 | /* Set width on the form input elements since they're 100% wide by default */ 13 | input, 14 | select, 15 | textarea { 16 | max-width: 280px; 17 | } 18 | -------------------------------------------------------------------------------- /WebApiTest/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | 7 | namespace WebApiTest.Controllers 8 | { 9 | public class HomeController : Controller 10 | { 11 | public ActionResult Index() 12 | { 13 | ViewBag.Title = "Home Page"; 14 | 15 | return View(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WebApiTest/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Http; 6 | using System.Web.Http; 7 | 8 | namespace WebApiTest.Controllers 9 | { 10 | //[Authorize] 11 | [RoutePrefix("api/{ver}/{ic}/Values")] 12 | public class ValuesController : ApiController 13 | { 14 | // GET api/values 15 | public IEnumerable Get() 16 | { 17 | return new string[] { "value1", "value2" }; 18 | } 19 | 20 | // GET api/values/5 21 | public string Get(int id) 22 | { 23 | return "value"; 24 | } 25 | 26 | // POST api/values 27 | public void Post([FromBody]string value) 28 | { 29 | } 30 | 31 | // PUT api/values/5 32 | public void Put(int id, [FromBody]string value) 33 | { 34 | } 35 | 36 | // DELETE api/values/5 37 | public void Delete(int id) 38 | { 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /WebApiTest/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="WebApiTest.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /WebApiTest/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Mvc; 7 | using System.Web.Optimization; 8 | using System.Web.Routing; 9 | 10 | namespace WebApiTest 11 | { 12 | public class WebApiApplication : System.Web.HttpApplication 13 | { 14 | protected void Application_Start() 15 | { 16 | AreaRegistration.RegisterAllAreas(); 17 | GlobalConfiguration.Configure(MultiTenancyFramework.WebAPI.GlobalWebApiConfig.Register); 18 | FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 19 | RouteConfig.RegisterRoutes(RouteTable.Routes); 20 | BundleConfig.RegisterBundles(BundleTable.Bundles); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WebApiTest/Models/AccountViewModels.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace WebApiTest.Models 5 | { 6 | // Models returned by AccountController actions. 7 | 8 | public class ExternalLoginViewModel 9 | { 10 | public string Name { get; set; } 11 | 12 | public string Url { get; set; } 13 | 14 | public string State { get; set; } 15 | } 16 | 17 | public class ManageInfoViewModel 18 | { 19 | public string LocalLoginProvider { get; set; } 20 | 21 | public string Email { get; set; } 22 | 23 | public IEnumerable Logins { get; set; } 24 | 25 | public IEnumerable ExternalLoginProviders { get; set; } 26 | } 27 | 28 | public class UserInfoViewModel 29 | { 30 | public string Email { get; set; } 31 | 32 | public bool HasRegistered { get; set; } 33 | 34 | public string LoginProvider { get; set; } 35 | } 36 | 37 | public class UserLoginInfoViewModel 38 | { 39 | public string LoginProvider { get; set; } 40 | 41 | public string ProviderKey { get; set; } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /WebApiTest/Models/IdentityModels.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Claims; 2 | using System.Threading.Tasks; 3 | using Microsoft.AspNet.Identity; 4 | using Microsoft.AspNet.Identity.EntityFramework; 5 | using Microsoft.AspNet.Identity.Owin; 6 | 7 | namespace WebApiTest.Models 8 | { 9 | // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more. 10 | public class ApplicationUser : IdentityUser 11 | { 12 | public async Task GenerateUserIdentityAsync(UserManager manager, string authenticationType) 13 | { 14 | // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType 15 | var userIdentity = await manager.CreateIdentityAsync(this, authenticationType); 16 | // Add custom user claims here 17 | return userIdentity; 18 | } 19 | } 20 | 21 | public class ApplicationDbContext : IdentityDbContext 22 | { 23 | public ApplicationDbContext() 24 | : base("DefaultConnection", throwIfV1Schema: false) 25 | { 26 | } 27 | 28 | public static ApplicationDbContext Create() 29 | { 30 | return new ApplicationDbContext(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /WebApiTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("WebApiTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("WebApiTest")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("4227c3a0-6cd8-499b-af25-210bed685156")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /WebApiTest/Results/ChallengeResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Http; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using System.Web.Http; 9 | 10 | namespace WebApiTest.Results 11 | { 12 | public class ChallengeResult : IHttpActionResult 13 | { 14 | public ChallengeResult(string loginProvider, ApiController controller) 15 | { 16 | LoginProvider = loginProvider; 17 | Request = controller.Request; 18 | } 19 | 20 | public string LoginProvider { get; set; } 21 | public HttpRequestMessage Request { get; set; } 22 | 23 | public Task ExecuteAsync(CancellationToken cancellationToken) 24 | { 25 | Request.GetOwinContext().Authentication.Challenge(LoginProvider); 26 | 27 | HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Unauthorized); 28 | response.RequestMessage = Request; 29 | return Task.FromResult(response); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /WebApiTest/Scripts/_references.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbadiwe/MultiTenancyFramework/670277f442d1e5673437723f794b8e3a1dcdb080/WebApiTest/Scripts/_references.js -------------------------------------------------------------------------------- /WebApiTest/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Owin; 5 | using Owin; 6 | 7 | [assembly: OwinStartup(typeof(WebApiTest.Startup))] 8 | 9 | namespace WebApiTest 10 | { 11 | public partial class Startup 12 | { 13 | public void Configuration(IAppBuilder app) 14 | { 15 | ConfigureAuth(app); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WebApiTest/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | 
2 |

ASP.NET

3 |

ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS, and JavaScript.

4 |

Learn more »

5 |
6 |
7 |
8 |

Getting started

9 |

ASP.NET Web API is a framework that makes it easy to build HTTP services that reach 10 | a broad range of clients, including browsers and mobile devices. ASP.NET Web API 11 | is an ideal platform for building RESTful applications on the .NET Framework.

12 |

Learn more »

13 |
14 |
15 |

Get more libraries

16 |

NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.

17 |

Learn more »

18 |
19 |
20 |

Web Hosting

21 |

You can easily find a web hosting company that offers the right mix of features and price for your applications.

22 |

Learn more »

23 |
24 |
25 | -------------------------------------------------------------------------------- /WebApiTest/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Error 6 | 7 | 8 |
9 |

Error.

10 |

An error occurred while processing your request.

11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /WebApiTest/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /WebApiTest/Web.Debug.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /WebApiTest/Web.Release.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /WebApiTest/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbadiwe/MultiTenancyFramework/670277f442d1e5673437723f794b8e3a1dcdb080/WebApiTest/favicon.ico -------------------------------------------------------------------------------- /WebApiTest/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbadiwe/MultiTenancyFramework/670277f442d1e5673437723f794b8e3a1dcdb080/WebApiTest/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /WebApiTest/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbadiwe/MultiTenancyFramework/670277f442d1e5673437723f794b8e3a1dcdb080/WebApiTest/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /WebApiTest/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbadiwe/MultiTenancyFramework/670277f442d1e5673437723f794b8e3a1dcdb080/WebApiTest/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /WebApiTest/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbadiwe/MultiTenancyFramework/670277f442d1e5673437723f794b8e3a1dcdb080/WebApiTest/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /WebTests/404.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 404 - Page Not Found 6 | 7 | 8 | 9 |
10 | Page Not Found (404). 11 |
12 |

Looking for the dead in the land of the living? Not Found!
[404]

13 | 14 | -------------------------------------------------------------------------------- /WebTests/500.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 500 - Server Error 6 | 7 | 8 | 9 |
10 | Page Not Found (404). 11 |
12 |
13 |

Looks like something went wrong!

14 |

We track these errors automatically, but if the problem persists feel free to contact us. In the meantime, try refreshing.

15 |
16 | 17 | -------------------------------------------------------------------------------- /WebTests/App_Start/NHibernateProfilerBootstrapper.cs: -------------------------------------------------------------------------------- 1 | //using HibernatingRhinos.Profiler.Appender.NHibernate; 2 | 3 | //[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(WebTests.App_Start.NHibernateProfilerBootstrapper), "PreStart")] 4 | //namespace WebTests.App_Start 5 | //{ 6 | // public static class NHibernateProfilerBootstrapper 7 | // { 8 | // public static void PreStart() 9 | // { 10 | // // Initialize the profiler 11 | // NHibernateProfiler.Initialize(); 12 | 13 | // // You can also use the profiler in an offline manner. 14 | // // This will generate a file with a snapshot of all the NHibernate activity in the application, 15 | // // which you can use for later analysis by loading the file into the profiler. 16 | // // var filename = @"c:\profiler-log"; 17 | // // NHibernateProfiler.InitializeOfflineProfiling(filename); 18 | 19 | // // You can use the following for production profiling. 20 | // // NHibernateProfiler.InitializeForProduction(11234, "A strong password like: ze38r/b2ulve2HLQB8NK5AYig"); 21 | // } 22 | // } 23 | //} 24 | 25 | -------------------------------------------------------------------------------- /WebTests/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | using System.Web.Routing; 3 | 4 | namespace WebTests 5 | { 6 | public class RouteConfig 7 | { 8 | public static void RegisterRoutes(RouteCollection routes) 9 | { 10 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 11 | 12 | routes.MapRoute( 13 | name: "Default", 14 | url: "{controller}/{action}/{id}", 15 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 16 | ); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WebTests/Areas/Samples/SamplesAreaRegistration.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace WebTests.Areas.Samples 4 | { 5 | public class SamplesAreaRegistration : AreaRegistration 6 | { 7 | public override string AreaName 8 | { 9 | get 10 | { 11 | return "Samples"; 12 | } 13 | } 14 | 15 | public override void RegisterArea(AreaRegistrationContext context) 16 | { 17 | //context.MapRoute( 18 | // "Samples_default", 19 | // "Samples/{controller}/{action}/{id}", 20 | // new { action = "Index", id = UrlParameter.Optional } 21 | //); 22 | MultiTenancyFramework.Mvc.MvcUtility.RegisterArea(AreaName, context); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /WebTests/Content/Site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Set padding to keep content from hitting the edges */ 7 | .body-content { 8 | padding-left: 15px; 9 | padding-right: 15px; 10 | } 11 | 12 | /* Set width on the form input elements since they're 100% wide by default */ 13 | input, 14 | select, 15 | textarea { 16 | max-width: 280px; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /WebTests/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="WebTests.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /WebTests/LoggingConfig.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | true 4 | 5 | /LM/W3SVC/2/ROOT-1-131179573442470325 6 | ERROR ON /LM/W3SVC/2/ROOT-1-131179573442470325 7 | somadinambadiwe@gmail.com 8 | DoNotReply.QCPTA@gmail.com 9 | october2014 10 | smtp.gmail.com 11 | 587 12 | true 13 | 14 | 15 | Logs 16 | 17 | true 18 | 19 | 100 20 | -------------------------------------------------------------------------------- /WebTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("WebTests")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("WebTests")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("d36d7968-4933-4f6d-ac3e-af0286256dfd")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Revision and Build Numbers 32 | // by using the '*' as shown below: 33 | [assembly: AssemblyVersion("1.0.0.0")] 34 | [assembly: AssemblyFileVersion("1.0.0.0")] 35 | -------------------------------------------------------------------------------- /WebTests/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Owin; 2 | using Owin; 3 | 4 | [assembly: OwinStartupAttribute(typeof(SchoolSoul.Web.Startup))] 5 | namespace SchoolSoul.Web 6 | { 7 | public partial class Startup 8 | { 9 | public void Configuration(IAppBuilder app) 10 | { 11 | ConfigureAuth(app); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /WebTests/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 |

Index

4 | 5 |

Done

6 |

7 | Sign up 8 |

-------------------------------------------------------------------------------- /WebTests/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } -------------------------------------------------------------------------------- /WebTests/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /WebTests/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /WebTests/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbadiwe/MultiTenancyFramework/670277f442d1e5673437723f794b8e3a1dcdb080/WebTests/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /WebTests/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbadiwe/MultiTenancyFramework/670277f442d1e5673437723f794b8e3a1dcdb080/WebTests/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /WebTests/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbadiwe/MultiTenancyFramework/670277f442d1e5673437723f794b8e3a1dcdb080/WebTests/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /WebTests/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbadiwe/MultiTenancyFramework/670277f442d1e5673437723f794b8e3a1dcdb080/WebTests/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /WebTestsNuget/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace WebTestsNuget 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WebTestsNuget/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="WebTestsNuget.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /WebTestsNuget/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace WebTestsNuget 9 | { 10 | public class MvcApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | AreaRegistration.RegisterAllAreas(); 15 | RouteConfig.RegisterRoutes(RouteTable.Routes); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WebTestsNuget/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("WebTestsNuget")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("WebTestsNuget")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("25e0c390-79d0-454b-8174-a608490d6363")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /WebTestsNuget/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /WebTestsNuget/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /WebTestsNuget/readme.txt: -------------------------------------------------------------------------------- 1 | Thank you for installing the MultiTenancy Framework using MVC5 and NHibernate! 2 | You can now easily build SaaS using MVC5 and NHibernate. 3 | Learn more on https://github.com/smbadiwe/MultiTenancyFramework/wiki 4 | 5 | A few things to note: 6 | - Your config file will be modified. Here are the ones that need your attention: 7 | - The NHibernate section. Modify accordingly 8 | - AppSettings: the key 'SiteUrl' added. Modify the URL accordingly 9 | - AppSettings: the key 'EntityAssemblies' where you may add the assembly names (comma separated) of the assemblies where your entities reside 10 | 11 | Feel free to contriute, raise an issue, suggest improvements or provide general feedback on the Github page for the framework --------------------------------------------------------------------------------