From d59ac14fa58a3c1171442e09a5a96b95e5bf40b8 Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 26 Jan 2021 19:49:13 +0200 Subject: Fixed ChangeTracker; Optimized default role insertion --- src/DevHive.Data/DevHiveContext.cs | 6 ++++++ src/DevHive.Data/Repositories/FeedRepository.cs | 1 + src/DevHive.Data/Repositories/LanguageRepository.cs | 3 ++- src/DevHive.Data/Repositories/TechnologyRepository.cs | 2 +- src/DevHive.Data/Repositories/UserRepository.cs | 3 ++- src/DevHive.Services/Services/TechnologyService.cs | 1 + src/DevHive.Services/Services/UserService.cs | 2 +- 7 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/DevHive.Data/DevHiveContext.cs b/src/DevHive.Data/DevHiveContext.cs index 17e16e7..48a6789 100644 --- a/src/DevHive.Data/DevHiveContext.cs +++ b/src/DevHive.Data/DevHiveContext.cs @@ -30,9 +30,15 @@ namespace DevHive.Data builder.Entity() .HasMany(x => x.Languages); + builder.Entity() + .HasMany(x => x.Users); + builder.Entity() .HasMany(x => x.Technologies); + builder.Entity() + .HasMany(x => x.Users); + builder.Entity() .HasChangeTrackingStrategy(ChangeTrackingStrategy.Snapshot); diff --git a/src/DevHive.Data/Repositories/FeedRepository.cs b/src/DevHive.Data/Repositories/FeedRepository.cs index 8bf1f9a..1b7518d 100644 --- a/src/DevHive.Data/Repositories/FeedRepository.cs +++ b/src/DevHive.Data/Repositories/FeedRepository.cs @@ -17,6 +17,7 @@ namespace DevHive.Data.Repositories { this._context = context; } + public async Task> GetFriendsPosts(List friendsList, DateTime firstRequestIssued, int pageNumber, int pageSize) { List friendsIds = friendsList.Select(f => f.Id).ToList(); diff --git a/src/DevHive.Data/Repositories/LanguageRepository.cs b/src/DevHive.Data/Repositories/LanguageRepository.cs index f2cc67f..7f4b946 100644 --- a/src/DevHive.Data/Repositories/LanguageRepository.cs +++ b/src/DevHive.Data/Repositories/LanguageRepository.cs @@ -22,7 +22,6 @@ namespace DevHive.Data.Repositories public async Task GetByNameAsync(string languageName) { return await this._context.Languages - .AsNoTracking() .FirstOrDefaultAsync(x => x.Name == languageName); } @@ -36,12 +35,14 @@ namespace DevHive.Data.Repositories public async Task DoesLanguageNameExistAsync(string languageName) { return await this._context.Languages + .AsNoTracking() .AnyAsync(r => r.Name == languageName); } public async Task DoesLanguageExistAsync(Guid id) { return await this._context.Languages + .AsNoTracking() .AnyAsync(r => r.Id == id); } #endregion diff --git a/src/DevHive.Data/Repositories/TechnologyRepository.cs b/src/DevHive.Data/Repositories/TechnologyRepository.cs index e03291d..7bb43cc 100644 --- a/src/DevHive.Data/Repositories/TechnologyRepository.cs +++ b/src/DevHive.Data/Repositories/TechnologyRepository.cs @@ -22,7 +22,6 @@ namespace DevHive.Data.Repositories public async Task GetByNameAsync(string technologyName) { return await this._context.Technologies - .AsNoTracking() .FirstOrDefaultAsync(x => x.Name == technologyName); } @@ -43,6 +42,7 @@ namespace DevHive.Data.Repositories public async Task DoesTechnologyExistAsync(Guid id) { return await this._context.Technologies + .AsNoTracking() .AnyAsync(x => x.Id == id); } #endregion diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index 06bafca..57ae146 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -40,7 +40,6 @@ namespace DevHive.Data.Repositories public async Task GetByUsernameAsync(string username) { return await this._context.Users - .AsNoTracking() .Include(x => x.Friends) .Include(x => x.Roles) .Include(x => x.Languages) @@ -74,9 +73,11 @@ namespace DevHive.Data.Repositories public async Task DoesUserHaveThisFriendAsync(Guid userId, Guid friendId) { User user = await this._context.Users + .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == userId); User friend = await this._context.Users + .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == friendId); return user.Friends.Contains(friend); diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs index 039cd8a..8f37273 100644 --- a/src/DevHive.Services/Services/TechnologyService.cs +++ b/src/DevHive.Services/Services/TechnologyService.cs @@ -49,6 +49,7 @@ namespace DevHive.Services.Services return this._technologyMapper.Map(technology); } + public HashSet GetTechnologies() { HashSet technologies = this._technologyRepository.GetTechnologies(); diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index abbecb1..9f4c777 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -77,7 +77,7 @@ namespace DevHive.Services.Services // Set the default role to the user Role defaultRole = await this._roleRepository.GetByNameAsync(Role.DefaultRole); - user.Roles = new HashSet() { defaultRole }; + user.Roles.Add(defaultRole); await this._userRepository.AddAsync(user); -- cgit v1.2.3