public List <ChallengeInfoViewModel> Search(ChallengesSearchOptions searchOptions) { var queryParameters = new ChallengeQueryParameters { PageRule = searchOptions.PageRule, IncludeTags = true }; var filterSettingsBuilder = FilterSettingsBuilder <Challenge> .Create(); if (!searchOptions.Keyword.IsNullOrEmpty()) { try { PopulateFilterSettings(filterSettingsBuilder, searchOptions.Keyword); } catch (NoResultsException) { return(new List <ChallengeInfoViewModel>()); } } queryParameters.FilterSettings = filterSettingsBuilder.GetSettings(); var challenges = unitOfWork.GetAll <Challenge>(queryParameters); return(mapper.Map <List <ChallengeInfoViewModel> >(challenges)); }
private Solver GetSolver(Guid challengeId, Guid userId) { var queryParameters = FilterSettingsBuilder <Solver> .Create() .AddFilterRule(x => x.ChallengeId, FilterOperator.IsEqualTo, challengeId) .AddFilterRule(x => x.UserId, FilterOperator.IsEqualTo, userId) .ToListQueryParameters(); return(unitOfWork.GetFirstOrDefault <Solver>(queryParameters)); }
public IdentityUser GetIdentityUserByEmail(string normalizedEmail) { var parameters = new QueryParameters { FilterSettings = FilterSettingsBuilder <User> .Create() .AddFilterRule(x => x.NormalizedEmail, FilterOperator.IsEqualTo, normalizedEmail) .GetSettings() }; var user = unitOfWork.GetSingleOrDefault <User>(parameters); return(mapper.Map <IdentityUser>(user)); }
public IdentityRole GetRoleByName(string roleName) { var parameters = new QueryParameters { FilterSettings = FilterSettingsBuilder <Role> .Create() .AddFilterRule(x => x.Name, FilterOperator.IsEqualTo, roleName) .GetSettings() }; var role = unitOfWork.GetSingleOrDefault <Role>(parameters); return(mapper.Map <IdentityRole>(role)); }
private void AddSolveAttempt(Guid challengeId, Guid userId) { Contract.NotDefault <InvalidOperationException, Guid>(userId, "user id must be not default"); var parameters = FilterSettingsBuilder <Solver> .Create() .AddFilterRule(x => x.ChallengeId, FilterOperator.IsEqualTo, challengeId) .AddFilterRule(x => x.UserId, FilterOperator.IsEqualTo, userId) .ToListQueryParameters(); var solver = unitOfWork.GetFirstOrDefault <Solver>(parameters); solver.NumberOfTries++; unitOfWork.InsertOrUpdate(solver); unitOfWork.Commit(); }
public TEntity Tag <TEntity>(TEntity entity, string str) where TEntity : ITaggable { var tag = str.Trim(); var queryParameters = FilterSettingsBuilder <Tag> .Create() .AddFilterRule(t => t.Value, FilterOperator.IsEqualTo, tag) .ToListQueryParameters(); if (entity.Tags.Any(t => t.Value == tag)) { return(entity); } var tagEntity = unitOfWork.TagsRepository.GetFirstOrDefault(queryParameters) ?? unitOfWork.TagsRepository.InsertOrUpdate(new Tag { Value = tag }); entity.Tags.Add(tagEntity); return(entity); }
private void PrepareQueryParameters(QueryParameters queryParameters, SortingType sortingType) { switch (sortingType) { case SortingType.Latest: queryParameters.SortSettings = SortSettingsBuilder <Challenge> .Create() .DescendingBy("TimeCreated") .GetSettings(); break; case SortingType.Popular: queryParameters.SortSettings = SortSettingsBuilder <Challenge> .Create() .DescendingBy("TimesSolved") .GetSettings(); break; case SortingType.Unsolved: queryParameters.SortSettings = SortSettingsBuilder <Challenge> .Create() .AscendingBy("TimeCreated") .GetSettings(); break; } if (sortingType == SortingType.Unsolved) { queryParameters.FilterSettings = FilterSettingsBuilder <Challenge> .Create() .AddFilterRule(x => x.TimesSolved, FilterOperator.IsEqualTo, 0) .GetSettings(); } }