From 8b62011960ce88d722c64b72af6837c2e2dbcda5 Mon Sep 17 00:00:00 2001 From: transtrike Date: Fri, 5 Feb 2021 19:02:35 +0200 Subject: Friends relation FUCKING FINALLY FIXED, NIGGA --- src/DevHive.Data/Repositories/UserRepository.cs | 73 +++++-------------------- 1 file changed, 14 insertions(+), 59 deletions(-) (limited to 'src/DevHive.Data/Repositories/UserRepository.cs') diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index ed8db49..6e97e60 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -23,14 +23,6 @@ namespace DevHive.Data.Repositories } #region Read - public IEnumerable QueryAll() - { - return this._context.Users - .Include(x => x.Roles) - .AsNoTracking() - .AsEnumerable(); - } - public override async Task GetByIdAsync(Guid id) { return await this._context.Users @@ -38,8 +30,7 @@ namespace DevHive.Data.Repositories .Include(x => x.Languages) .Include(x => x.Technologies) .Include(x => x.Posts) - .Include(x => x.MyFriends) - .Include(x => x.FriendsOf) + .Include(x => x.Friends) .Include(x => x.ProfilePicture) .FirstOrDefaultAsync(x => x.Id == id); } @@ -51,56 +42,15 @@ namespace DevHive.Data.Repositories .Include(x => x.Languages) .Include(x => x.Technologies) .Include(x => x.Posts) - .Include(x => x.MyFriends) - .Include(x => x.FriendsOf) + .Include(x => x.Friends) .Include(x => x.ProfilePicture) .FirstOrDefaultAsync(x => x.UserName == username); } #endregion #region Update - public override async Task EditAsync(Guid id, User newEntity) + public async Task UpdateProfilePicture(Guid userId, string pictureUrl) { - User user = await this.GetByIdAsync(id); - - this._context - .Entry(user) - .CurrentValues - .SetValues(newEntity); - - HashSet languages = new(); - foreach (var lang in newEntity.Languages) - languages.Add(lang); - user.Languages = languages; - - HashSet roles = new(); - foreach (var role in newEntity.Roles) - roles.Add(role); - user.Roles = roles; - - foreach (var friend in newEntity.MyFriends) - { - user.MyFriends.Add(friend); - this._context.Entry(friend).State = EntityState.Modified; - } - - foreach (var friend in newEntity.FriendsOf) - { - user.FriendsOf.Add(friend); - this._context.Entry(friend).State = EntityState.Modified; - } - - HashSet technologies = new(); - foreach (var tech in newEntity.Technologies) - technologies.Add(tech); - user.Technologies = technologies; - - this._context.Entry(user).State = EntityState.Modified; - - return await this.SaveChangesAsync(); - } - - public async Task UpdateProfilePicture(Guid userId, string pictureUrl) { User user = await this.GetByIdAsync(userId); user.ProfilePicture.PictureURL = pictureUrl; @@ -131,14 +81,19 @@ namespace DevHive.Data.Repositories .AnyAsync(u => u.Email == email); } - public async Task DoesUserHaveThisFriendAsync(Guid userId, Guid friendId) + public async Task ValidateFriendsCollectionAsync(List usernames) { - return true; - // User user = await this.GetByIdAsync(userId); + bool valid = true; - // User friend = await this.GetByIdAsync(friendId); - - // return user.Friends.Any(x => x.Friend.Id == friendId); + foreach (var username in usernames) + { + if (!await this._context.Users.AnyAsync(x => x.UserName == username)) + { + valid = false; + break; + } + } + return valid; } public bool DoesUserHaveThisUsername(Guid id, string username) -- cgit v1.2.3