public IEnumerable <User> GetAll() { using (var _context = new EduhubContext(_connectionString)) { var allUsers = new List <User>(); var dtoList = _context.Users .Include(u => u.Contacts) .Include(u => u.Invitations) .Include(u => u.Tags) .Include(u => u.Reviews) .Include(u => u.Notifies) .ToList(); dtoList.ForEach(d => allUsers.Add(UserExtensions.ParseFromUserDto(d))); return(allUsers); } }
public User GetUserById(int userId) { using (var _context = new EduhubContext(_connectionString)) { var userDto = _context.Users .Include(u => u.Contacts) .Include(u => u.Invitations) .Include(u => u.Tags) .Include(u => u.Reviews) .Include(u => u.Notifies) .FirstOrDefault(u => u.Id == userId); Ensure.Any.IsNotNull(userDto, nameof(userId), opt => opt.WithException(new UserNotFoundException(userId))); var user = UserExtensions.ParseFromUserDto(userDto); return(user); } }
public User GetUserByCredentials(Credentials credentials) { using (var _context = new EduhubContext(_connectionString)) { var userDto = _context.Users .Include(u => u.Contacts) .Include(u => u.Invitations) .Include(u => u.Tags) .Include(u => u.Reviews) .Include(u => u.Notifies) .FirstOrDefault(u => u.Email == credentials.Email && u.PasswordHash == credentials.PasswordHash); Ensure.Any.IsNotNull(userDto, nameof(credentials), opt => opt.WithException(new UserNotFoundException())); var user = UserExtensions.ParseFromUserDto(userDto); _context.SaveChanges(); return(user); } }