private PropertyFindCriteria GetFindCriteria(PropertiesRequestModel model, int resultLimit) { return(new PropertyFindCriteria() { Postcode = model.Postcode, PropertyType = model.PropertyType, LastSaleDate = model.SearchRangeInMonths <= 0 ? default(DateTime) : DateTime.Now.AddMonths(-model.SearchRangeInMonths), ResultLimit = resultLimit }); }
private async Task <ModelStateDictionary> ValidateModel(PropertiesRequestModel model) { var modelStateDictionary = new ModelStateDictionary(); var existingPostcode = await _postcodeRepository.GetPostcode(model.Postcode); if (existingPostcode == null) { modelStateDictionary.AddModelError("Postcode", "Postcode does not exist."); } return(modelStateDictionary); }
public async Task <IHttpActionResult> Get([ModelBinder(typeof(PropertiesRequestModelBinder))] PropertiesRequestModel model) { ModelStateDictionary modelState = await ValidateModel(model); if (modelState.Count > 0) { return(BadRequest(modelState)); } var findCriteria = GetFindCriteria(model, 500); var orderBy = model.OrderBy; var paging = new Paging(model.Page, 25); var result = await _propertyRepository.FindAsync(findCriteria, orderBy, paging); return(Ok(result)); }