public void UpdateUserSettings(InputModels.UpdateAccountInput input) { var existingRecords = Records.Where(s => s.UserId == input.Id).ToList(); if (existingRecords.Any()) { DbContext.RemoveRange(existingRecords); } foreach (var settingInput in input.Settings) { if (string.IsNullOrEmpty(settingInput.Value)) { continue; } var siteSetting = Records.FirstOrDefault(s => !s.AdminOnly && s.Name == settingInput.Key && string.IsNullOrEmpty(s.UserId)); if (siteSetting != null) { var baseSetting = BaseSettings.Get(siteSetting.Name); if (baseSetting.Options != null && !baseSetting.Options.Contains(settingInput.Value)) { throw new HttpBadRequestError(); } var record = new DataModels.SiteSetting { UserId = input.Id, Name = siteSetting.Name, Value = settingInput.Value, AdminOnly = siteSetting.AdminOnly }; DbContext.SiteSettings.Add(record); } } DbContext.SaveChanges(); }
public ServiceModels.ServiceResponse UpdateSiteSettings(InputModels.EditSettingsInput input) { var serviceResponse = new ServiceModels.ServiceResponse(); foreach (var settingInput in input.Settings) { var existingRecords = Records.Where(s => s.Name == settingInput.Key && string.IsNullOrEmpty(s.UserId)).ToList(); if (existingRecords.Any()) { DbContext.RemoveRange(existingRecords); } if (string.IsNullOrEmpty(settingInput.Value)) { continue; } var baseSetting = BaseSettings.Get(settingInput.Key); if (baseSetting.Options != null && !baseSetting.Options.Contains(settingInput.Value)) { throw new HttpBadRequestError(); } var record = new DataModels.SiteSetting { Name = settingInput.Key, Value = settingInput.Value, AdminOnly = settingInput.AdminOnly }; DbContext.SiteSettings.Add(record); } DbContext.SaveChanges(); serviceResponse.Message = $"Site settings were updated."; return(serviceResponse); }