diff options
Diffstat (limited to 'src/DevHive.Data')
| -rw-r--r-- | src/DevHive.Data/Models/User.cs | 4 | ||||
| -rw-r--r-- | src/DevHive.Data/Repositories/DevHiveContext.cs | 8 | ||||
| -rw-r--r-- | src/DevHive.Data/Repositories/UserRepository.cs | 9 |
3 files changed, 18 insertions, 3 deletions
diff --git a/src/DevHive.Data/Models/User.cs b/src/DevHive.Data/Models/User.cs index fd0ee7b..eef0af2 100644 --- a/src/DevHive.Data/Models/User.cs +++ b/src/DevHive.Data/Models/User.cs @@ -14,8 +14,8 @@ namespace DevHive.Data.Models public string ProfilePicture { get; set; } - public virtual IList<Role> Roles { get; set; } + public virtual IList<Role> Roles { get; set; } = new List<Role>(); - //public List<User> Friends { get; set; } + public IList<User> Friends { get; set; } = new List<User>(); } } diff --git a/src/DevHive.Data/Repositories/DevHiveContext.cs b/src/DevHive.Data/Repositories/DevHiveContext.cs index 373eb5e..7fa8130 100644 --- a/src/DevHive.Data/Repositories/DevHiveContext.cs +++ b/src/DevHive.Data/Repositories/DevHiveContext.cs @@ -18,7 +18,13 @@ namespace DevHive.Data.Repositories builder.Entity<User>() .HasIndex(x => x.UserName) .IsUnique(); - + + builder.Entity<User>() + .HasMany(x => x.Roles); + + builder.Entity<User>() + .HasMany(x => x.Friends); + builder.Entity<Role>() .HasIndex(x => x.Id) .IsUnique(); diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index 130f96e..577f02f 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -43,6 +43,7 @@ namespace DevHive.Data.Repositories return await this._context .Set<User>() .Include(x => x.Roles) + .Include(x => x.Friends) .FirstOrDefaultAsync(x => x.Id == id); } @@ -115,5 +116,13 @@ namespace DevHive.Data.Repositories .AsNoTracking() .AnyAsync(u => u.Email == email); } + + public async Task<bool> AddFriend(User user, User friend) + { + this._context.Update(user); + user.Friends.Add(friend); + + return await RepositoryMethods.SaveChangesAsync(this._context); + } } } |
