public ActionResult Settings() { var fbAccount = DbContext.FbAccounts .Include("Settings") .Include("Settings.TestRailConfig") .Single(a => a.Id == UserContext.FbAccountId); FbAccountSettings fbAccountSettings; if (fbAccount == null) fbAccountSettings = new FbAccountSettings(); else fbAccountSettings = fbAccount.Settings; var viewModel = new SettingViewModel(); viewModel.Setup(); MapSettingsViewModel(viewModel, fbAccountSettings); return View("Update", viewModel); }
public ActionResult Settings(SettingViewModel viewModel) { viewModel.Setup(); if (!ModelState.IsValid) { return View("Update", viewModel); } var fbAccount = DbContext.FbAccounts .Include("Settings") .Include("Settings.TestRailConfig") .SingleOrDefault(s => s.Id == viewModel.Id); FbAccountSettings fbAccountSettings; if (fbAccount == null) fbAccountSettings = new FbAccountSettings(); else fbAccountSettings = fbAccount.Settings; //refresh cache when qa estimate settings changed if (fbAccountSettings.AllowQaEstimates != viewModel.AllowQaEstimates || fbAccountSettings.QaEstimateCustomFieldName != viewModel.QaEstimateCustomFieldname || fbAccountSettings.QaPercentage != viewModel.QaPercentage) { CleareCachedCaseSets(); } MapSettingsEntity(fbAccountSettings, viewModel); var service = new FbAccountService(); if (fbAccount != null && fbAccount.Settings != null) { if (fbAccount.Settings.SendDailyDigestEmails) { string cacheKeyToken = MsCacheKey.Gen(MsCacheDataType.FogBugz_ClientByFogBugzUrl, UserContext.FogBugzUrl); object fbClientObject = null; MsCache.TryGet(cacheKeyToken, ref fbClientObject); var fbClient = (FogBugzClientEx) fbClientObject; fbAccount.Token = fbClient.GetToken(); } else { fbAccount.Token = String.Empty; } } // save settings in db service.Update(fbAccount); var cacheKey = MsCacheKey.Gen(MsCacheDataType.ProjectLists, UserContext.FogBugzUrl); MsCache.TryRemove(cacheKey); cacheKey = MsCacheKey.Gen(MsCacheDataType.FogBugz_ClientCacheByFogBugzUrl, UserContext.FogBugzUrl); MsCache.TryRemove(cacheKey); UserContext.SetNotification(PageNotificationType.Success, "Settings have been updated."); return RedirectToAction("Settings"); }