protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings = Speedy.Extensions.GetSerializerSettings(true, false); GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter); GlobalConfiguration.Configuration.EnsureInitialized(); Database.SetInitializer(new MigrateDatabaseToLatestVersion <ScribeSqlDatabase, Configuration>(true)); var appDataPath = HttpContext.Current.Server.MapPath("~/App_Data"); var client = new ScribeDataChannel(new ScribeDatabaseProvider(() => new ScribeSqlDatabase())); var provider = new KeyValueRepositoryProvider <Event>(appDataPath); Tracker = Tracker.Start(client, provider); using (var datacontext = new ScribeSqlDatabase()) { var siteSettings = SiteSettings.Load(datacontext); IsConfigured = datacontext.Users.Any(); PrintCss = siteSettings.PrintCss ?? string.Empty; ViewCss = siteSettings.ViewCss ?? string.Empty; } }
public override bool IsUserInRole(string username, string roleName) { using (var database = new ScribeSqlDatabase()) { var userId = username.Split(';').First().ConvertToInt(); var user = database.Users.FirstOrDefault(x => x.Id == userId); return(user != null && user.InRole(roleName)); } }
public override string[] GetRolesForUser(string username) { using (var database = new ScribeSqlDatabase()) { var userId = username.Split(';').First().ConvertToInt(); var user = database.Users.FirstOrDefault(x => x.Id == userId); return(user?.Tags?.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToArray() ?? new string[0]); } }
public static IScribeDatabase GetDatabase(bool clearDatabase = true) { var database = new ScribeSqlDatabase(); if (clearDatabase) { database.Database.ExecuteSqlCommand(Resources.ClearDatabase); } return(database); }
public void Reload() { using (var datacontext = new ScribeSqlDatabase()) { SettingsService.ClearCache(); var settingsService = SiteSettings.Load(datacontext, true); MvcApplication.IsConfigured = datacontext.Users.Any(); MvcApplication.PrintCss = settingsService.PrintCss; MvcApplication.ViewCss = settingsService.ViewCss; } }