public JsonResult PostSave(Dictionary <string, string> p_settings) { foreach (var item in p_settings) { var settingIndb = _context.Settings.SingleOrDefault(c => c.CompanyId == _CurrentUserCompanyID() && c.Key == item.Key); if (settingIndb == null) { Setting newSetting = new Setting(); newSetting.UserId = _CurrentUserID(); newSetting.CreatedUserID = _CurrentUserID(); newSetting.CompanyId = _CurrentUserCompanyID(); newSetting.Key = item.Key; newSetting.Value = item.Value; _context.Settings.Add(newSetting); } else { settingIndb.UserId = _CurrentUserID(); settingIndb.UpdatedUserID = _CurrentUserID(); settingIndb.CompanyId = _CurrentUserCompanyID(); settingIndb.UpdatedDate = DateTime.Now; settingIndb.Value = item.Value; _context.Entry(settingIndb).State = EntityState.Modified; } } try { _context.SaveChanges(); } catch (Exception ex) { _logger.LogError(ex, "Error in /api/Settings/Save"); throw; } if (p_settings.ContainsKey("SMS_GOO_Cals") == true) { //ensure google service user has appropriate permissions to read calendars set var gt = _CurrentUserGooToken(); if (gt != null) { using (GoogleService service = new GoogleService(gt)) { if (service.EnsureReadPermissionsForService(p_settings["SMS_GOO_Cals"], _config.GetSection("GoogleSettings")["GooServiceAccount"]) == false) { return(Json("Not all calendar access permissions were set!")); } } } } return(Json("OK")); }