public async Task <List <OperationModel> > GetOperationModels() { LoggingService.Trace("Querying OperationsDatabase.GetOperationModels"); var databaseConnection = await GetDatabaseConnection <OperationDatabaseModel>().ConfigureAwait(false); var dbLock = databaseConnection.GetConnection().Lock(); try { var operationDatabaseModelList = databaseConnection.GetConnection().GetAllWithChildren <OperationDatabaseModel>(); return(operationDatabaseModelList.Select(x => OperationDatabaseModel.ToOperationModel(x)).ToList()); } catch (Exception e) { LoggingService.Error(e, "Error OperationsDatabase.GetOperationModels"); return(new List <OperationModel>()); } finally { dbLock.Dispose(); } }
public async Task <OperationModel?> GetOperationModel(string operationId) { LoggingService.Trace("Querying OperationsDatabase.GetOperationModel"); if (string.IsNullOrEmpty(operationId)) { return(null); } var databaseConnection = await GetDatabaseConnection <OperationDatabaseModel>().ConfigureAwait(false); var dbLock = databaseConnection.GetConnection().Lock(); try { var operationDatabaseModel = databaseConnection.GetConnection().GetWithChildren <OperationDatabaseModel>(operationId); return(operationDatabaseModel != null? OperationDatabaseModel.ToOperationModel(operationDatabaseModel) : null); } catch (Exception e) { return(null); } finally { dbLock.Dispose(); } }
public async Task <bool> HideLocalOperation(string opId, bool isHidden) { LoggingService.Trace("Querying OperationsDatabase.HideLocalOperation"); var databaseConnection = await GetDatabaseConnection <OperationDatabaseModel>().ConfigureAwait(false); var dbLock = databaseConnection.GetConnection().Lock(); try { var operationModel = await GetOperationModel(opId); if (operationModel == null) { return(false); } operationModel.IsHiddenLocally = isHidden; var dbModel = OperationDatabaseModel.ToOperationDatabaseModel(operationModel); databaseConnection.GetConnection().UpdateWithChildren(dbModel); return(true); } catch (Exception e) { LoggingService.Error(e, "Error Querying OperationsDatabase.HideLocalOperation"); return(false); } finally { dbLock.Dispose(); } }
public static OperationModel ToOperationModel(OperationDatabaseModel operationDatabaseModel) { try { return(new OperationModel() { Id = operationDatabaseModel.OpId, Name = operationDatabaseModel.OpName, Creator = operationDatabaseModel.Creator, Color = operationDatabaseModel.Color, Portals = operationDatabaseModel.Portals ?? new List <PortalModel>(), Anchors = operationDatabaseModel.Anchors ?? new List <string>(), Blockers = operationDatabaseModel.Blockers ?? new List <BlockerModel>(), TeamList = operationDatabaseModel.TeamList ?? new List <TeamModel>(), Modified = operationDatabaseModel.Modified, Comment = operationDatabaseModel.Comment, KeysOnHand = operationDatabaseModel.KeysOnHand ?? new List <KeysOnHandModel>(), Zones = operationDatabaseModel.Zones ?? new List <ZoneModel>(), IsHiddenLocally = operationDatabaseModel.IsHiddenLocally, DownloadedAt = operationDatabaseModel.DownloadedAt, Markers = operationDatabaseModel.Markers?.Select(markerDbModel => MarkersDatabase.MarkerDatabaseModel.ToMarkerModel(markerDbModel)).ToList(), Links = operationDatabaseModel.Links?.Select(linkDbModel => LinksDatabase.LinkDatabaseModel.ToLinkModel(linkDbModel)).ToList() }); } catch (Exception) { return(null); } }
public async Task <int> SaveOperationModel(OperationModel operationModel) { LoggingService.Trace("Querying OperationsDatabase.SaveOperationModel"); var databaseConnection = await GetDatabaseConnection <OperationDatabaseModel>().ConfigureAwait(false); var dbLock = databaseConnection.GetConnection().Lock(); try { var operationDatabaseModel = OperationDatabaseModel.ToOperationDatabaseModel(operationModel); var existingData = await GetOperationModel(operationModel.Id); if (existingData != null) { operationDatabaseModel.IsHiddenLocally = existingData.IsHiddenLocally; } databaseConnection.GetConnection().InsertOrReplaceWithChildren(operationDatabaseModel); return(0); } catch (Exception e) { LoggingService.Error(e, "Error Querying OperationsDatabase.SaveOperationModel"); return(1); } finally { dbLock.Dispose(); } }