public async Task <ActionResult> UpdateGeneralSeting([FromBody] GeneralSettingRequests generalSettingRequests) { if (!GeneralSetting.SettingNames.Contains(generalSettingRequests.SettingName)) { return(Ok(new BaseResponse())); } SettingRequests settingRequests = new SettingRequests(generalSettingRequests) { Type = GeneralSetting.SettingType }; if (generalSettingRequests.AutoLoad != null) { settingRequests.AutoLoad = generalSettingRequests.AutoLoad; } var result = await _settingLogic.UpdateSetingOptionAsync(settingRequests); return(Ok(new BaseResponse(result))); }
public Task <Setting> UpdateSetingOptionAsync(SettingRequests settingRequests) { try { // Update Setting Setting setting = new Setting(); _logger.LogInformation("Update setting"); if (settingRequests.Name != null) { Setting updateSetting = _uow.GetRepository <Setting>().GetByFilter(x => x.Name == settingRequests.Name).FirstOrDefault(); if (updateSetting != null) { updateSetting.Value = settingRequests.Value; updateSetting.CustomValue = settingRequests.CustomValue; _uow.GetRepository <Setting>().Update(updateSetting); _uow.SaveChanges(); return(Task.FromResult(updateSetting)); } else { setting.Name = settingRequests.Name; setting.Value = settingRequests.Value; setting.Type = settingRequests.Type; setting.CustomValue = settingRequests.CustomValue; _uow.GetRepository <Setting>().Add(setting); _uow.SaveChanges(); return(Task.FromResult(setting)); } } return(Task.FromResult(setting)); } catch (Exception ex) { _logger.LogError(ex.Message.ToString()); throw ex; } }