public async Task <IActionResult> Edit(InputModels.EditSettingsInput input) { if (ModelState.IsValid) { var serviceResponse = SettingsRepository.UpdateSiteSettings(input); return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback)); } return(await FailureCallback()); async Task <IActionResult> FailureCallback() { return(await Task.Run(() => { return ForumViewResult.RedirectToReferrer(this); })); } }
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); }