aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-26 19:49:13 +0200
committertranstrike <transtrike@gmail.com>2021-01-26 19:49:13 +0200
commitd59ac14fa58a3c1171442e09a5a96b95e5bf40b8 (patch)
tree8c9b53e241844e2094ff826dd6b877996d523d9f
parentb97a24a4d84f795e615926a162fab3531c1b9ab3 (diff)
downloadDevHive-d59ac14fa58a3c1171442e09a5a96b95e5bf40b8.tar
DevHive-d59ac14fa58a3c1171442e09a5a96b95e5bf40b8.tar.gz
DevHive-d59ac14fa58a3c1171442e09a5a96b95e5bf40b8.zip
Fixed ChangeTracker; Optimized default role insertion
-rw-r--r--src/DevHive.Data/DevHiveContext.cs6
-rw-r--r--src/DevHive.Data/Repositories/FeedRepository.cs1
-rw-r--r--src/DevHive.Data/Repositories/LanguageRepository.cs3
-rw-r--r--src/DevHive.Data/Repositories/TechnologyRepository.cs2
-rw-r--r--src/DevHive.Data/Repositories/UserRepository.cs3
-rw-r--r--src/DevHive.Services/Services/TechnologyService.cs1
-rw-r--r--src/DevHive.Services/Services/UserService.cs2
7 files changed, 14 insertions, 4 deletions
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<User>()
.HasMany(x => x.Languages);
+ builder.Entity<Language>()
+ .HasMany(x => x.Users);
+
builder.Entity<User>()
.HasMany(x => x.Technologies);
+ builder.Entity<Technology>()
+ .HasMany(x => x.Users);
+
builder.Entity<User>()
.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<List<Post>> GetFriendsPosts(List<User> friendsList, DateTime firstRequestIssued, int pageNumber, int pageSize)
{
List<Guid> 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<Language> 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<bool> DoesLanguageNameExistAsync(string languageName)
{
return await this._context.Languages
+ .AsNoTracking()
.AnyAsync(r => r.Name == languageName);
}
public async Task<bool> 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<Technology> 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<bool> 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<User> 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<bool> 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<CreateTechnologyServiceModel>(technology);
}
+
public HashSet<ReadTechnologyServiceModel> GetTechnologies()
{
HashSet<Technology> 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<Role>() { defaultRole };
+ user.Roles.Add(defaultRole);
await this._userRepository.AddAsync(user);