mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
Made the search page all async goodness #278
This commit is contained in:
parent
05b219a351
commit
03ce361183
13 changed files with 432 additions and 183 deletions
|
@ -24,6 +24,8 @@
|
|||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using PlexRequests.Core.SettingModels;
|
||||
|
@ -62,6 +64,21 @@ namespace PlexRequests.Core
|
|||
return model;
|
||||
}
|
||||
|
||||
public async Task<T> GetSettingsAsync()
|
||||
{
|
||||
var result = await Repo.GetAsync(EntityName);
|
||||
if (result == null)
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
result.Content = DecryptSettings(result);
|
||||
var obj = string.IsNullOrEmpty(result.Content) ? null : JsonConvert.DeserializeObject<T>(result.Content, SerializerSettings.Settings);
|
||||
|
||||
var model = obj;
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public bool SaveSettings(T model)
|
||||
{
|
||||
var entity = Repo.Get(EntityName);
|
||||
|
@ -88,6 +105,31 @@ namespace PlexRequests.Core
|
|||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> SaveSettingsAsync(T model)
|
||||
{
|
||||
var entity = await Repo.GetAsync(EntityName);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
var newEntity = model;
|
||||
|
||||
var settings = new GlobalSettings { SettingsName = EntityName, Content = JsonConvert.SerializeObject(newEntity, SerializerSettings.Settings) };
|
||||
settings.Content = EncryptSettings(settings);
|
||||
var insertResult = await Repo.InsertAsync(settings);
|
||||
|
||||
return insertResult != int.MinValue;
|
||||
}
|
||||
|
||||
var modified = model;
|
||||
modified.Id = entity.Id;
|
||||
|
||||
var globalSettings = new GlobalSettings { SettingsName = EntityName, Content = JsonConvert.SerializeObject(modified, SerializerSettings.Settings), Id = entity.Id };
|
||||
globalSettings.Content = EncryptSettings(globalSettings);
|
||||
var result = await Repo.UpdateAsync(globalSettings);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool Delete(T model)
|
||||
{
|
||||
var entity = Repo.Get(EntityName);
|
||||
|
@ -100,6 +142,17 @@ namespace PlexRequests.Core
|
|||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(T model)
|
||||
{
|
||||
var entity = Repo.Get(EntityName);
|
||||
if (entity != null)
|
||||
{
|
||||
return await Repo.DeleteAsync(entity);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private string EncryptSettings(GlobalSettings settings)
|
||||
{
|
||||
return StringCipher.Encrypt(settings.Content, settings.SettingsName);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue