public UserProfessions AssignProfessionToUser(int userId, ProfessionsEnum profession) { Users user = GetUserById(userId); if (user == null) { throw new NoEntryFoundException(userId, typeof(Users).Name); } UserProfessions existingProfession = ProfessionRepository.GetByUserIdAndProfession(user.Id, profession); if (existingProfession != null) { return(existingProfession); } UserProfessions userProfession = new UserProfessions { UserId = user.Id, ProfessionId = (int)profession }; ProfessionRepository.Add(userProfession); return(ProfessionRepository.GetByIdAndUserId(userProfession.Id, user.Id)); }
public UserProfessions GetByUserIdAndProfession(int userId, ProfessionsEnum profession) { return(DatabaseContext .UserProfessions .AsNoTracking() .Where( x => x.UserId == userId && x.ProfessionId == (int)profession ).Include( x => x.TheProfession ).SingleOrDefault()); }
} //For EF private Professions(ProfessionsEnum @enum) { this.Id = (int)@enum; this.ProfessionName = @enum.ToString(); this.ProfessionDescription = @enum.GetEnumDescription(); }
public List <Users> GetUsersByProfessionCriteria(ProfessionsEnum profession, string searchTerm, float currentLatitude, float currentLongitude, int pageSize, int pageNumber) { return(SearchRepository.GetPagedUserListFilteredByProfessionAndCurrentLocationAndRating( profession, RepairSearchTerm(searchTerm), currentLatitude, currentLongitude, pageSize, pageNumber)); }
public List <Users> GetPagedUserListFilteredByProfessionAndCurrentLocationAndRating(ProfessionsEnum profession, string searchTerm, float currentLatitude, float currentLongitude, int pageSize, int pageNumber) { IQueryable <Users> firstQuery = DatabaseContext .Users .Where( x => x.TheProfessionsThatThisUserKnows .Any( y => y.ProfessionId == (int)profession ) ); IQueryable <Users> searchTermFilteredQuery = GeneralSearchTerm(firstQuery, searchTerm); IQueryable <Users> locationAdjustedQuery = DistanceQuery(searchTermFilteredQuery, currentLatitude, currentLongitude); return(PagingQuery(locationAdjustedQuery, pageNumber, pageSize).ToList()); }