public async Task <int?> UpsertAsync(ServiceModel.RepositoryCurrentState repositoryCurrentState)
        {
            var dbRepositoryCurrentState = await repositoryAnalysisContext
                                           .RepositoryCurrentState
                                           .Include(rcs => rcs.Teams)
                                           .Include(rcs => rcs.Topics)
                                           .Where(rcs => rcs.RepositoryId == repositoryCurrentState.Id)
                                           .SingleOrDefaultAsync();

            if (dbRepositoryCurrentState == null)
            {
                dbRepositoryCurrentState = mapper.Map <RepositoryCurrentState>(repositoryCurrentState);

                repositoryAnalysisContext.Add(dbRepositoryCurrentState);
            }
            else
            {
                // If the object already exists in the DB, then map the model object into this
                // already existing db objec to take advantage of EF update tracking
                mapper.Map(repositoryCurrentState, dbRepositoryCurrentState);
            }

            await repositoryAnalysisContext.SaveChangesAsync();

            return(dbRepositoryCurrentState.RepositoryCurrentStateId);
        }
        public async Task <ServiceModel.RepositoryCurrentState> ReadAsync(string repositoryId)
        {
            ServiceModel.RepositoryCurrentState repositoryCurrentState = null;

            var dbRepositoryCurrentState = await repositoryAnalysisContext
                                           .RepositoryCurrentState
                                           .AsNoTracking()
                                           .Include(rcs => rcs.Teams)
                                           .Include(rcs => rcs.Topics)
                                           .Where(rcs => rcs.RepositoryId == repositoryId)
                                           .SingleOrDefaultAsync();

            if (dbRepositoryCurrentState != null)
            {
                repositoryCurrentState = mapper.Map <ServiceModel.RepositoryCurrentState>(dbRepositoryCurrentState);
            }

            return(repositoryCurrentState);
        }