diff options
| author | Kamen Mladenov <kamen.d.mladenov@protonmail.com> | 2021-04-09 19:51:35 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-09 19:51:35 +0300 |
| commit | 233f38915ba0079079233eff55434ef349c05c45 (patch) | |
| tree | 6c5f69017865bcab87355e910c87339453da1406 /src/DevHive.Data/Repositories/UserRepository.cs | |
| parent | f4a70c6430db923af9fa9958a11c2d6612cb52cc (diff) | |
| parent | a992357efcf1bc1ece81b95ecee5e05a0b73bfdc (diff) | |
| download | DevHive-0.2.tar DevHive-0.2.tar.gz DevHive-0.2.zip | |
Merge pull request #28 from Team-Kaleidoscope/devHEADv0.2mainheroku/main
Second stage: Complete
Diffstat (limited to 'src/DevHive.Data/Repositories/UserRepository.cs')
| -rw-r--r-- | src/DevHive.Data/Repositories/UserRepository.cs | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs deleted file mode 100644 index 6e97e60..0000000 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Threading.Tasks; -using AutoMapper.Mappers; -using DevHive.Data.Interfaces.Repositories; -using DevHive.Data.Models; -using DevHive.Data.RelationModels; -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; - -namespace DevHive.Data.Repositories -{ - public class UserRepository : BaseRepository<User>, IUserRepository - { - private readonly DevHiveContext _context; - - public UserRepository(DevHiveContext context) - : base(context) - { - this._context = context; - } - - #region Read - public override async Task<User> GetByIdAsync(Guid id) - { - return await this._context.Users - .Include(x => x.Roles) - .Include(x => x.Languages) - .Include(x => x.Technologies) - .Include(x => x.Posts) - .Include(x => x.Friends) - .Include(x => x.ProfilePicture) - .FirstOrDefaultAsync(x => x.Id == id); - } - - public async Task<User> GetByUsernameAsync(string username) - { - return await this._context.Users - .Include(x => x.Roles) - .Include(x => x.Languages) - .Include(x => x.Technologies) - .Include(x => x.Posts) - .Include(x => x.Friends) - .Include(x => x.ProfilePicture) - .FirstOrDefaultAsync(x => x.UserName == username); - } - #endregion - - #region Update - public async Task<bool> UpdateProfilePicture(Guid userId, string pictureUrl) - { - User user = await this.GetByIdAsync(userId); - - user.ProfilePicture.PictureURL = pictureUrl; - - return await this.SaveChangesAsync(); - } - #endregion - - #region Validations - public async Task<bool> DoesUserExistAsync(Guid id) - { - return await this._context.Users - .AsNoTracking() - .AnyAsync(x => x.Id == id); - } - - public async Task<bool> DoesUsernameExistAsync(string username) - { - return await this._context.Users - .AsNoTracking() - .AnyAsync(u => u.UserName == username); - } - - public async Task<bool> DoesEmailExistAsync(string email) - { - return await this._context.Users - .AsNoTracking() - .AnyAsync(u => u.Email == email); - } - - public async Task<bool> ValidateFriendsCollectionAsync(List<string> usernames) - { - bool valid = true; - - 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) - { - return this._context.Users - .AsNoTracking() - .Any(x => x.Id == id && - x.UserName == username); - } - #endregion - } -} |
