private static void EnsureDefaultDevicesAreInit() { var devices = new MongoRepository <IosDevice>(); if (!devices.Any(d => d.Id == "092bb6b72e9b0067c86260d47b6eda05f7d43429")) { devices.Add(new IosDevice { Id = "092bb6b72e9b0067c86260d47b6eda05f7d43429", Name = "MK Support" }); } if (!devices.Any(d => d.Id == "0993f067aa9743a27cf42bce41b00e8ee7c64f97")) { devices.Add(new IosDevice { Id = "0993f067aa9743a27cf42bce41b00e8ee7c64f97", Name = "MK Support 2 - Denis" }); } if (!devices.Any(d => d.Id == "b6dc4dc7c54b9930f634b22cc1bdd8f846651738")) { devices.Add(new IosDevice { Id = "b6dc4dc7c54b9930f634b22cc1bdd8f846651738", Name = "MK Chris P" }); } if (!devices.Any(d => d.Id == "2e00e12d970a3be9423369484fdd18f01235c400")) { devices.Add(new IosDevice { Id = "2e00e12d970a3be9423369484fdd18f01235c400", Name = "apcurium Alex P" }); } }
public ActionResult DeleteMarket(MarketModel marketModel) { var companiesUsingThisMarketInTheirNetworkSettings = new MongoRepository <TaxiHailNetworkSettings>() .Where(x => x.Market == marketModel.Market) .OrderBy(x => x.Id) .Select(x => x.Id) .ToList(); if (companiesUsingThisMarketInTheirNetworkSettings.Any()) { TempData["warning"] = "Couldn't delete the market because some companies are configured to use it:" + companiesUsingThisMarketInTheirNetworkSettings.Aggregate("", (current, company) => current + string.Format( company == companiesUsingThisMarketInTheirNetworkSettings.Last() ? "{0}" : "{0}, ", company)); } else { try { Repository.Delete(v => v.Name == marketModel.Market); } catch (Exception) { ViewBag.Error = "An error occured. Unable to delete the market"; } } return(RedirectToAction("Index")); }
public ActionResult Index() { var repository = new MongoRepository<Revision>(); if (!repository.Any()) { return RedirectToAction("Update","Revision"); } return View(repository); }
void InsureTranslationsCanBeInserted(Translation translation) { var existing = _mongoRepository.Any(_predicate); if (existing) { throw new Exception("A similar translation already exist. Delete that first."); } translation.SetNewId(); }
public ActionResult ApplyDefaultsToCompanies() { var defaultSettings = new MongoRepository <DefaultCompanySetting>(); var companies = new MongoRepository <Company>(); foreach (var company in companies) { foreach (var setting in company.CompanySettings) { setting.IsClientSetting = false; } foreach (var defaultSetting in defaultSettings) { if (defaultSetting.Id.Contains("Facebook")) { defaultSetting.Key.ToString(); } var setting = company.CompanySettings.SingleOrDefault(c => c.Key == defaultSetting.Id); if (setting != null) { company.CompanySettings.Remove(setting); } } var clientKeys = new string[] { "ApplicationName", "ServiceUrl", "CanChangeServiceUrl", "ErrorLog", "ErrorLogEnabled", "FacebookAppId", "FacebookEnabled", "ServiceUrlTest", "TwitterAccessTokenUrl", "TwitterAuthorizeUrl", "TwitterCallback", "TwitterConsumerKey", "TwitterConsumerSecret", "TwitterEnabled", "TwitterRequestTokenUrl" }; foreach (var clientKey in clientKeys) { var setting = company.CompanySettings.SingleOrDefault(c => c.Key == clientKey); if (setting == null) { if (!defaultSettings.Any(s => s.Id == clientKey)) { company.CompanySettings.Add(new CompanySetting { Key = clientKey, IsClientSetting = true }); } } else { setting.IsClientSetting = true; } } companies.Update(company); } return(RedirectToAction("DefaultSettings")); }
public ActionResult Index() { ViewBag.MaxTag = TempData["UpdateTagLimitError"]; var repository = new MongoRepository <Revision>(); if (!repository.Any()) { return(RedirectToAction("Update", "Revision")); } return(View(repository.Where(r => !r.Inactive))); }
private static void MigrateNetworkVehiclesToMarketRepresentation() { var networkVehicles = new MongoRepository <NetworkVehicle>(); if (!networkVehicles.Any()) { // Migration already done return; } var allMarketsDefinedInNetworkSettings = new MongoRepository <TaxiHailNetworkSettings>().Select(x => x.Market).Distinct(); var allMarketsDefinedInNetworkVehicles = networkVehicles.Select(x => x.Market).Distinct(); var allMarketsDefined = new List <string>(); allMarketsDefined.AddRange(allMarketsDefinedInNetworkSettings); allMarketsDefined.AddRange(allMarketsDefinedInNetworkVehicles); allMarketsDefined = allMarketsDefined.Distinct().ToList(); var marketRepo = new MongoRepository <Market>(); foreach (var market in allMarketsDefined) { var vehiclesForThisMarket = networkVehicles .Where(x => x.Market == market) .Select(x => new Vehicle { Id = x.Id, Name = x.Name, LogoName = x.LogoName, MaxNumberPassengers = x.MaxNumberPassengers, NetworkVehicleId = x.NetworkVehicleId }) .ToList(); var newMarket = new Market { Id = Guid.NewGuid().ToString(), Name = market, Vehicles = vehiclesForThisMarket }; marketRepo.Add(newMarket); } networkVehicles.DeleteAll(); networkVehicles.Collection.Drop(); }
/// <summary> /// Configure /// </summary> /// <param name="builder">Authentication builder</param> public void AddAuthentication(AuthenticationBuilder builder, IConfiguration configuration) { builder.AddFacebook(FacebookDefaults.AuthenticationScheme, options => { var connection = DataSettingsManager.LoadSettings(); var settings = new FacebookExternalAuthSettings(); try { var fbSettings = new MongoRepository <Setting>(connection.ConnectionString).Table.Where(x => x.Name.StartsWith("facebookexternalauthsettings")); if (fbSettings.Any()) { var metadata = fbSettings.FirstOrDefault().Metadata; settings = JsonSerializer.Deserialize <FacebookExternalAuthSettings>(metadata); } } catch (Exception ex) { Log.Error(ex, "AddFacebook"); }; //no empty values allowed. otherwise, an exception could be thrown on application startup options.AppId = !string.IsNullOrWhiteSpace(settings.ClientKeyIdentifier) ? settings.ClientKeyIdentifier : "000"; options.AppSecret = !string.IsNullOrWhiteSpace(settings.ClientSecret) ? settings.ClientSecret : "000"; options.SaveTokens = true; //handles exception thrown by external auth provider options.Events = new OAuthEvents() { OnRemoteFailure = ctx => { ctx.HandleResponse(); var errorCode = ctx.Request.Query["error_code"].FirstOrDefault(); var errorMessage = ctx.Request.Query["error_message"].FirstOrDefault(); var state = ctx.Request.Query["state"].FirstOrDefault(); errorCode = WebUtility.UrlEncode(errorCode); errorMessage = WebUtility.UrlEncode(errorMessage); ctx.Response.Redirect($"/fb-signin-failed?error_code={errorCode}&error_message={errorMessage}"); return(Task.FromResult(0)); } }; }); }
/// <summary> /// Configure /// </summary> /// <param name="builder">Authentication builder</param> public void AddAuthentication(AuthenticationBuilder builder, IConfiguration configuration) { builder.AddGoogle(GoogleDefaults.AuthenticationScheme, options => { var connection = DataSettingsManager.LoadSettings(); var settings = new GoogleExternalAuthSettings(); try { var gSettings = new MongoRepository <Setting>(connection.ConnectionString).Table.Where(x => x.Name.StartsWith("googleexternalauthsettings")); if (gSettings.Any()) { var metadata = gSettings.FirstOrDefault().Metadata; settings = JsonSerializer.Deserialize <GoogleExternalAuthSettings>(metadata); } } catch (Exception ex) { Log.Error(ex, "AddGoogle"); }; options.ClientId = !string.IsNullOrWhiteSpace(settings.ClientKeyIdentifier) ? settings.ClientKeyIdentifier : "000"; options.ClientSecret = !string.IsNullOrWhiteSpace(settings.ClientSecret) ? settings.ClientSecret : "000"; options.SaveTokens = true; //handles exception thrown by external auth provider options.Events = new OAuthEvents() { OnRemoteFailure = ctx => { ctx.HandleResponse(); var errorMessage = ctx.Failure.Message; var state = ctx.Request.Query["state"].FirstOrDefault(); errorMessage = WebUtility.UrlEncode(errorMessage); ctx.Response.Redirect($"/google-signin-failed?error_message={errorMessage}"); return(Task.FromResult(0)); } }; }); }