public SearchResponseDTO GetLazy(SearchRequestDTO request) { var response = new SearchResponseDTO { TotalCount = _productStorage.Count() }; switch (request.SortBy) { case SortByColumn.NameASC: case SortByColumn.NameDESC: response.Products = SortedProducts(request, x => x.Name); break; case SortByColumn.PriceASC: case SortByColumn.PriceDESC: response.Products = SortedProducts(request, x => x.Price); break; case SortByColumn.QuantityASC: case SortByColumn.QuantityDESC: response.Products = SortedProducts(request, x => x.Quantity); break; } return(response); }
public SearchResponseDTO <TeamSearchItemDTO> SearchTeams(SearchTeamParameterDTO parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } SearchResponseDTO <Team> result = SearchTeamsWithQuery(parameters); var items = result.Items.Select(i => new TeamSearchItemDTO { Id = i.Id.ToString(), Name = i.Name, Description = i.Description, CompanyName = i.Company?.Name, CompanyId = i.CompanyId, CreatedOn = i.CreatedOn, NumberOfMembers = i.Members.Count(), HourHiringRate = GetTeamHiringRate(i.Members), Technologies = _mapper.Map <IEnumerable <TechnologyDTO> >(i.Members.Select(m => m.PrimaryTechnology).Distinct()), }); return(new SearchResponseDTO <TeamSearchItemDTO> { Items = items, TotalCount = result.TotalCount }); }
/// <summary> /// Uses the Command Pattern and executes the generate search result logic /// </summary> /// <returns> an outcome object containing the search results</returns> public Outcome Execute() { var result = new Outcome(); var response = new SearchResponseDTO(); var messages = new List <string>(); var gateway = new SearchGateway(); // Gets user info var gatewayResponse = gateway.RetrieveUsers(); if (!gatewayResponse.IsSuccessful) { response.IsSuccessful = false; response.Messages = gatewayResponse.Messages; result.Result = response; } // Filters the user search based on the distance of the coordinates var filteredResults = gatewayResponse.Results.Select(x => new { x.User, x.FirstName, x.LastName, x.SkillLevel, UserCoordinate = new GeoCoordinate(x.Latitude, x.Longitude), }).Where(x => ValidatedLocations.ContainsKey(x.UserCoordinate) && x.SkillLevel.Contains(Criteria.Skill) && x.User != Criteria.RequestedUser); // Map the filteredResults to a list of SearchResult objects var searchResults = filteredResults.Select(x => new SearchResult() { User = x.User, FirstName = x.FirstName, LastName = x.LastName, Skill = x.SkillLevel, Distance = Math.Round(ValidatedLocations[x.UserCoordinate], 2) }).AsEnumerable(); searchResults = searchResults.OrderBy(x => x.Distance); // Changes the response data based if filtered data has any users in it if (!searchResults.Any()) { response.IsSuccessful = false; messages.Add(SearchConstants.NO_NEARBY_USERS_ERROR); response.Messages = messages; } else { response.IsSuccessful = true; messages.Add(SearchConstants.USERS_FOUND_ERROR); response.Messages = messages; response.SearchResults = searchResults.ToList(); } result.Result = response; return(result); }
public SearchResponseDTO Error(string message) { var response = new SearchResponseDTO() { IsSuccessful = false, Messages = new List <string>() }; response.Messages.Add(message); return(response); }
public async Task <IActionResult> FilterSingleActiveEmployees([FromQuery] SearchEmployeeParameterDTO parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } parameters.CurrentUserCompanyId = (await GetCurrentUser()).CompanyId; SearchResponseDTO <EmployeeDTO> result = _service.SearchSingleActiveEmployees(parameters); return(Ok(result)); }
public async Task <IActionResult> Filter([FromQuery] SearchVacancyParameterDTO parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } parameters.UserId = await GetCurrentUserId(); SearchResponseDTO <VacancyDTO> result = _service.SearchVacancies(parameters); return(Ok(result)); }
public SearchResponseDTO <CompanyDTO> SearchCompanies(SearchCompanyParameterDTO parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } SearchResponseDTO <Company> result = SearchCompaniesWithQuery(parameters); return(new SearchResponseDTO <CompanyDTO> { Items = _mapper.Map <IEnumerable <CompanyDTO> >(result.Items), TotalCount = result.TotalCount }); }
public SearchResponseDTO <EmployeeDTO> SearchSingleActiveEmployees(SearchEmployeeParameterDTO parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } SearchResponseDTO <Employee> result = SearchEmployeesWithQuery(parameters, GetSingleActiveEmployeesSearchQuery); return(new SearchResponseDTO <EmployeeDTO> { Items = _mapper.Map <IEnumerable <EmployeeDTO> >(result.Items).Do(employee => SetHiringRate(employee, 1)), TotalCount = result.TotalCount }); }
public Outcome Execute() { var response = new Outcome(); var result = new SearchResponseDTO(); var messages = new List <string>(); // returns error if criteria is null if (SearchNearbyCriteria == null) { result.IsSuccessful = false; messages.Add(SearchConstants.NO_CRITERIA_ERROR); result.Messages = messages; response.Result = result; return(response); } var validator = new SearchNearbyCriteriaValidator(); var results = validator.Validate(SearchNearbyCriteria); IList <ValidationFailure> failures = results.Errors; // Returns any error messages if there was any when validating if (failures.Any()) { foreach (ValidationFailure failure in failures) { messages.Add(failure.ErrorMessage); } result.IsSuccessful = false; result.Messages = messages; response.Result = result; return(response); } // Sets the result as true to indicate it passed result.IsSuccessful = true; response.Result = result; return(response); }
/// <summary> /// Executes the strategy of searching nearby users based on an address /// </summary> /// <returns> The users with their username, skill, workout type, and distance that fits the search criteria</returns> public Outcome Execute() { var searchResponse = new SearchResponseDTO(); var response = new Outcome(); // Validates the Criteria that the user has entered var criteriaValidator = new ValidateSearchNearbyCriteria() { SearchNearbyCriteria = Search }; var validatedCriteria = (SearchResponseDTO)criteriaValidator.Execute().Result; // if validator fails, return the result if (!validatedCriteria.IsSuccessful) { response.Result = validatedCriteria; return(response); } // Validates the location that the user inputted var locationValidator = new WebAPILocationValidator() { RequestedLocation = Search.RequestedSearch }; var validatedLocation = (WebAPIGeocode)locationValidator.Execute().Result; if (!validatedLocation.IsValid) { response.Result = Error(LocationConstants.ADDRESS_NOT_VALID_ERROR); return(response); } var gateway = new SearchGateway(); // Retrieve all locations from database var locationResponseDTO = gateway.RetrieveLocations(); if (!locationResponseDTO.IsSuccessful) { response.Result = Error(locationResponseDTO.Messages.First()); } var locations = locationResponseDTO.LocationResults; if (!locations.Any()) { response.Result = Error(LocationGatewayConstants.NO_LOCATION_FOUND_ERROR); return(response); } // Filtering the locations based on the distance var filterLocation = new FilterGeoCoordinates() { UserLocation = new GeoCoordinate(validatedLocation.Latitude, validatedLocation.Longitude), GeoCoordinates = locations, Distance = Search.Distance.Value, }; var filteredGeocoordinates = (Dictionary <GeoCoordinate, double>)filterLocation.Execute().Result; if (!filteredGeocoordinates.Any()) { response.Result = Error(SearchConstants.NO_NEARBY_USERS_ERROR); return(response); } // Generates the search results var filterSearch = new GenerateSearchResults() { Criteria = Search, ValidatedLocations = filteredGeocoordinates }; response.Result = (SearchResponseDTO)filterSearch.Execute().Result; return(response); }
public Outcome Execute() { var result = new Outcome(); var response = new SearchResponseDTO(); var messages = new List <string>(); // Validates the Criteria that the user has entered var validator = new ValidateSearchUserCriteria() { SearchUserCriteria = SearchUserCriteria }; var validatedCriteria = (SearchResponseDTO)validator.Execute().Result; // if validator fails, return the result if (!validatedCriteria.IsSuccessful) { result.Result = validatedCriteria; return(result); } // retrieve users var gatewayResponse = new SearchGateway().RetrieveUsers(); if (!gatewayResponse.IsSuccessful) { response.IsSuccessful = false; response.Messages = gatewayResponse.Messages; result.Result = response; return(result); } // Gets the user info based on username var requestedBy = gatewayResponse.Results.Where(x => x.User == SearchUserCriteria.RequestedBy).FirstOrDefault(); if (requestedBy == null) { response.IsSuccessful = false; messages.Add(SearchConstants.NO_REQUESTEDBY_ERROR); response.Messages = messages; result.Result = response; return(result); } var requestedUser = gatewayResponse.Results.Where(x => x.User == SearchUserCriteria.RequestedUser).FirstOrDefault(); if (requestedUser == null) { response.IsSuccessful = false; messages.Add(SearchConstants.NO_USER_ERROR); response.Messages = messages; result.Result = response; return(result); } // Creates Geocoordinates based on the two users location and generates a search result var requestedByCoord = new GeoCoordinate(requestedBy.Latitude, requestedBy.Longitude); var requestedUserCoord = new GeoCoordinate(requestedUser.Latitude, requestedUser.Longitude); var userResult = new SearchResult() { User = requestedUser.User, FirstName = requestedUser.FirstName, LastName = requestedUser.LastName, Skill = requestedUser.SkillLevel, Distance = Math.Round(((requestedUserCoord.GetDistanceTo(requestedByCoord)) / 1609.344), 2) }; response.IsSuccessful = true; response.SearchResults = new List <SearchResult>(); response.SearchResults.Add(userResult); messages.Add(SearchConstants.USER_FOUND); response.Messages = messages; result.Result = response; return(result); }