public IEnumerable <ILocatorStateDto> GetAll(string sort = null, string fields = null, int firstResult = 0, int maxResults = int.MaxValue, string filter = null) { try { IEnumerable <ILocatorState> states = null; if (!String.IsNullOrWhiteSpace(filter)) { states = _locatorApplicationService.Get(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new WebApiControllerTypeConverter(), new PropertyTypeResolver() , n => (LocatorMetadata.Instance.FilteringPropertyAliasDictionary.ContainsKey(n) ? LocatorMetadata.Instance.FilteringPropertyAliasDictionary[n] : n)) , LocatorsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults); } else { states = _locatorApplicationService.Get(LocatorsControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs()) , LocatorsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults); } var stateDtos = new List <ILocatorStateDto>(); foreach (var s in states) { var dto = s is LocatorStateDtoWrapper ? (LocatorStateDtoWrapper)s : new LocatorStateDtoWrapper(s); if (String.IsNullOrWhiteSpace(fields)) { dto.AllFieldsReturned = true; } else { dto.ReturnedFieldsString = fields; } stateDtos.Add(dto); } return(stateDtos); } catch (Exception ex) { var response = HttpServiceExceptionUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); } }
public IEnumerable <LocatorStateDto> Get(string parentId = null, string sort = null, string fields = null, int firstResult = 0, int maxResults = int.MaxValue, string filter = null) { try { var parentIdObj = parentId == null ? null : parentId; IEnumerable <ILocatorState> states = null; if (!String.IsNullOrWhiteSpace(filter)) { if (parentIdObj == null) { if (IsOnlyIdReturned(fields)) { var ids = _locatorTreeApplicationService.GetRootIds(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new ApiControllerTypeConverter(), new PropertyTypeResolver()) , LocatorsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults); states = LocatorsControllerUtils.ToLocatorStateDtoCollection(ids); } else { states = _locatorTreeApplicationService.GetRoots(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new ApiControllerTypeConverter(), new PropertyTypeResolver()) , LocatorsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults); } } else { if (IsOnlyIdReturned(fields)) { var ids = _locatorTreeApplicationService.GetChildIds(parentIdObj, CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new ApiControllerTypeConverter(), new PropertyTypeResolver()) , LocatorsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults); states = LocatorsControllerUtils.ToLocatorStateDtoCollection(ids); } else { states = _locatorTreeApplicationService.GetChildren(parentIdObj, CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new ApiControllerTypeConverter(), new PropertyTypeResolver()) , LocatorsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults); } } } else { if (parentIdObj == null) { if (IsOnlyIdReturned(fields)) { var ids = _locatorTreeApplicationService.GetRootIds(LocatorsControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs()) , LocatorsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults); states = LocatorsControllerUtils.ToLocatorStateDtoCollection(ids); } else { states = _locatorTreeApplicationService.GetRoots(LocatorsControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs()) , LocatorsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults); } } else { if (IsOnlyIdReturned(fields)) { var ids = _locatorTreeApplicationService.GetChildIds(parentIdObj, LocatorsControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs()) , LocatorsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults); states = LocatorsControllerUtils.ToLocatorStateDtoCollection(ids); } else { states = _locatorTreeApplicationService.GetChildren(parentIdObj, LocatorsControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs()) , LocatorsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults); } } } var stateDtos = new List <LocatorStateDto>(); foreach (var s in states) { var dto = s is LocatorStateDto ? (LocatorStateDto)s : new LocatorStateDto((LocatorState)s); if (String.IsNullOrWhiteSpace(fields)) { dto.AllFieldsReturned = true; } else { dto.ReturnedFieldsString = fields; } stateDtos.Add(dto); } return(stateDtos); } catch (Exception ex) { var response = LocatorsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); } }