Exemplo n.º 1
0
        public async Task <TeamModel?> GetTeam(string teamId)
        {
            LoggingService.Trace("Querying TeamsDatabase.GetTeam");

            if (string.IsNullOrEmpty(teamId))
            {
                return(null);
            }

            var databaseConnection = await GetDatabaseConnection <TeamDatabaseModel>().ConfigureAwait(false);

            var dbLock = databaseConnection.GetConnection().Lock();

            try
            {
                var teamDatabaseModel = databaseConnection.GetConnection().GetWithChildren <TeamDatabaseModel>(teamId);

                return(teamDatabaseModel != null?
                       TeamDatabaseModel.ToTeamModel(teamDatabaseModel) :
                           null);
            }
            catch (Exception e)
            {
                LoggingService.Error(e, "Error Querying TeamsDatabase.GetTeam");

                return(null);
            }
            finally
            {
                dbLock.Dispose();
            }
        }
Exemplo n.º 2
0
        public async Task <int> SaveTeamsModels(IList <TeamModel> teams)
        {
            LoggingService.Trace("Querying TeamsDatabase.SaveTeamsModels");

            var databaseConnection = await GetDatabaseConnection <TeamDatabaseModel>().ConfigureAwait(false);

            var dbLock = databaseConnection.GetConnection().Lock();

            try
            {
                var teamsDatabaseModels = new List <TeamDatabaseModel>(
                    teams.Select(model => TeamDatabaseModel.ToTeamDatabaseModel(model)));

                databaseConnection.GetConnection().InsertOrReplaceAllWithChildren(teamsDatabaseModels, true);

                return(0);
            }
            catch (Exception e)
            {
                LoggingService.Error(e, "Error Querying TeamsDatabase.SaveTeamsModels");

                return(1);
            }
            finally
            {
                dbLock.Dispose();
            }
        }
Exemplo n.º 3
0
        public async Task <List <TeamModel> > GetTeamsForAgent(string agentId)
        {
            LoggingService.Trace("Querying TeamsDatabase.GetTeamsForAgent");

            if (string.IsNullOrEmpty(agentId))
            {
                return(new List <TeamModel>());
            }

            var databaseConnection = await GetDatabaseConnection <TeamDatabaseModel>().ConfigureAwait(false);

            var dbLock = databaseConnection.GetConnection().Lock();

            try
            {
                var teamDatabaseModels = databaseConnection.GetConnection().GetAllWithChildren <TeamDatabaseModel>();

                return(teamDatabaseModels != null && teamDatabaseModels.Any() ?
                       teamDatabaseModels
                       .Where(model => model.Agents.Any(a => a.AgentId != null && a.AgentId.Equals(agentId)))
                       .Select(x => TeamDatabaseModel.ToTeamModel(x))
                       .ToList() :
                       new List <TeamModel>());
            }
            catch (Exception e)
            {
                LoggingService.Error(e, "Error Querying TeamsDatabase.GetTeamsForAgent");

                return(new List <TeamModel>());
            }
            finally
            {
                dbLock.Dispose();
            }
        }
Exemplo n.º 4
0
 public static TeamModel ToTeamModel(TeamDatabaseModel teamDatabaseModel)
 {
     return(new TeamModel()
     {
         Id = teamDatabaseModel.TeamId,
         Name = teamDatabaseModel.Name,
         Agents = teamDatabaseModel.Agents?.Select(agentDbModel => TeamAgentsDatabase.TeamAgentDatabaseModel.ToTeamAgentModel(agentDbModel)).ToList(),
         DownloadedAt = teamDatabaseModel.DownloadedAt
     });
 }