예제 #1
0
 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
     });
 }
예제 #2
0
        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);
        }
예제 #3
0
        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));
        }