private async Task <Page <UserSearchResponse> > SearchByProfileProperty(UserSearch search) { List <UserSearchResponse> records; var response = new Page <UserSearchResponse>(); var property = await ValidateProfilePropertyForSearch(search); using (var uow = new UnitOfWork(Context)) { var repo = new UserProfilePropertyRepository(uow); var query = repo.SearchByPropertyValue(search.SearchText, property.ProfilePropertyId, search.Operator, search.IncludeAvatar); response.TotalRecordCount = await query.CountAsync(); var sortField = !string.IsNullOrWhiteSpace(search.SortField) ? search.SortField.Trim().ToLower() : "searchfieldvalue"; response.SortExpression = GetSortExpression(sortField, search.SortAscending); //query = query.OrderBy(response.SortExpression); records = await query.Skip(search.PageSize *search.PageOffset).Take(search.PageSize).ToListAsync(); } response.PageSize = search.PageSize; response.PageOffset = search.PageOffset; response.Records = records; return(response); }
private async Task CreateProfilePropertyInDb(UserProfileProperty userProfileProperty, ProfilePropertyVisibility visibility) { using (var uow = new UnitOfWork(Context)) { var repo = new UserProfilePropertyRepository(uow); await repo.CreateWithData(userProfileProperty, visibility); } }
public async Task <UserProfileProperty> GetUserProfileProperty(int userProfilePropertyId, bool isAdmin) { using (var uow = new UnitOfWork(Context)) { var repo = new UserProfilePropertyRepository(uow); var query = repo.GetAllWithRelated(isAdmin).Where(c => c.UserProfilePropertyId == userProfilePropertyId); return(await query.FirstOrDefaultAsync()); } }
private async Task <UserProfileProperty> UpdateExistingProfilePropertyInDb(UserProfileProperty updateUserProfileProperty) { UserProfileProperty updatedProfile; using (var uow = new UnitOfWork(Context)) { var repo = new UserProfilePropertyRepository(uow); updatedProfile = await repo.Update(updateUserProfileProperty); } await new UserProfilePropertyCache(Cache).InvalidateUserProfilePropertiesCache(updatedProfile.UserId); return(updatedProfile); }
private async Task <UserProfileProperty> GetUserProfileProperty(int userId, int profilePropertyId, string name, bool isAdmin) { using (var uow = new UnitOfWork(Context)) { var repo = new UserProfilePropertyRepository(uow); IQueryable <UserProfileProperty> query; if (profilePropertyId == 0) { query = repo.GetAllWithEmpty(userId, isAdmin).Where(c => c.ProfilePropertyName.ToUpper() == name.ToUpper()); } else { query = repo.GetAllWithEmpty(userId, isAdmin).Where(c => c.ProfilePropertyId == profilePropertyId); } return(await query.FirstOrDefaultAsync()); } }
private async Task <List <int> > FindUsersFromValue(int profilePropertyId, string profilePropertyName, string value) { using (var uow = new UnitOfWork(Context)) { var repo = new UserProfilePropertyRepository(uow); IQueryable <UserProfileProperty> query; if (profilePropertyId == 0) { query = repo.GetAllWithRelated(true).Where(c => c.ProfilePropertyName.ToUpper() == profilePropertyName.ToUpper()); } else { query = repo.GetAllWithRelated(true).Where(c => c.ProfilePropertyId == profilePropertyId); } query = query.Where(c => c.Value.ToUpper() == value.ToUpper()); return(await query.Select(c => c.UserId).ToListAsync()); } }
// Gets a users profile. This will return empty values for Properties the user does not fill out. public async Task <List <UserProfileProperty> > GetUserProfileProperties(int userId, bool isAdmin) { var cache = new UserProfilePropertyCache(Cache); List <UserProfileProperty> userProfileProperties = await cache.GetUserProfilePropertiesFromCache(userId, isAdmin); if (userProfileProperties != null) { return(userProfileProperties); } using (var uow = new UnitOfWork(Context)) { var repo = new UserProfilePropertyRepository(uow); var query = repo.GetAllWithEmpty(userId, isAdmin); userProfileProperties = await query.ToListAsync(); } await cache.AddUserProfilePropertiesToCache(userId, isAdmin, userProfileProperties); return(userProfileProperties); }