Beispiel #1
0
 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); }
 }
Beispiel #2
0
 public ILocatorStateEvent GetStateEvent(string id, long version)
 {
     try {
         var idObj = id;
         return(_locatorApplicationService.GetStateEvent(idObj, version));
     } catch (Exception ex) { var response = LocatorsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #3
0
 public void Patch(string id, [FromBody] MergePatchLocatorDto value)
 {
     try {
         LocatorsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
         _locatorApplicationService.When(value as IMergePatchLocator);
     } catch (Exception ex) { var response = HttpServiceExceptionUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #4
0
 public LocatorStateCreatedOrMergePatchedOrDeletedDto GetStateEvent(string id, long version)
 {
     try {
         var idObj = id;
         var conv  = new LocatorStateEventDtoConverter();
         var se    = _locatorApplicationService.GetStateEvent(idObj, version);
         return(se == null ? null : conv.ToLocatorStateEventDto(se));
     } catch (Exception ex) { var response = LocatorsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #5
0
 public void Delete(string id, string commandId, string version, string requesterId = default(string))
 {
     try {
         var value = new DeleteLocatorDto();
         value.CommandId   = commandId;
         value.RequesterId = requesterId;
         value.Version     = (long)Convert.ChangeType(version, typeof(long));
         LocatorsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
         _locatorApplicationService.When(value as IDeleteLocator);
     } catch (Exception ex) { var response = HttpServiceExceptionUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #6
0
        public HttpResponseMessage Post([FromBody] CreateLocatorDto value)
        {
            try {
                if (value.LocatorId == default(string))
                {
                    throw DomainError.Named("nullId", "Aggregate Id in cmd is null, aggregate name: {0}.", "Locator");
                }
                _locatorApplicationService.When(value as ICreateLocator);
                var idObj = value.LocatorId;

                return(Request.CreateResponse <string>(HttpStatusCode.Created, idObj));
            } catch (Exception ex) { var response = LocatorsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
        }
Beispiel #7
0
 public IEnumerable <PropertyMetadata> GetMetadataFilteringFields()
 {
     try {
         var filtering = new List <PropertyMetadata>();
         foreach (var p in LocatorMetadata.Instance.Properties)
         {
             if (p.IsFilteringProperty)
             {
                 filtering.Add(p);
             }
         }
         return(filtering);
     } catch (Exception ex) { var response = LocatorsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #8
0
 public long GetCount(string filter = null)
 {
     try {
         long count = 0;
         if (!String.IsNullOrWhiteSpace(filter))
         {
             count = _locatorApplicationService.GetCount(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new WebApiControllerTypeConverter(), new PropertyTypeResolver()
                                                                                 , n => (LocatorMetadata.Instance.FilteringPropertyAliasDictionary.ContainsKey(n) ? LocatorMetadata.Instance.FilteringPropertyAliasDictionary[n] : n)));
         }
         else
         {
             count = _locatorApplicationService.GetCount(LocatorsControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs()));
         }
         return(count);
     } catch (Exception ex) { var response = HttpServiceExceptionUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #9
0
        public void Put(string id, [FromBody] CreateOrMergePatchOrDeleteLocatorDto value)
        {
            try {
                // ///////////////////////////////
                if (value.Version != default(long))
                {
                    value.CommandType = CommandType.MergePatch;
                    LocatorsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
                    _locatorApplicationService.When(value as IMergePatchLocator);
                    return;
                }
                // ///////////////////////////////

                LocatorsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
                _locatorApplicationService.When(value as ICreateLocator);
            } catch (Exception ex) { var response = HttpServiceExceptionUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
        }
Beispiel #10
0
 public IEnumerable <PropertyMetadataDto> GetMetadataFilteringFields()
 {
     try {
         var filtering = new List <PropertyMetadataDto>();
         foreach (var p in LocatorMetadata.Instance.Properties)
         {
             if (p.IsFilteringProperty)
             {
                 var pdto = new PropertyMetadataDto(p.Name, p.TypeName, p.IsFilteringProperty,
                                                    !String.IsNullOrWhiteSpace(p.SourceChainingName) ? p.SourceChainingName :
                                                    (!String.IsNullOrWhiteSpace(p.DerivedFrom) ? p.DerivedFrom : p.Name));
                 filtering.Add(pdto);
             }
         }
         return(filtering);
     } catch (Exception ex) { var response = LocatorsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #11
0
 public LocatorStateDto Get(string id, string fields = null)
 {
     try {
         var idObj = id;
         var state = (LocatorState)_locatorApplicationService.Get(idObj);
         if (state == null)
         {
             return(null);
         }
         var stateDto = new LocatorStateDto(state);
         if (String.IsNullOrWhiteSpace(fields))
         {
             stateDto.AllFieldsReturned = true;
         }
         else
         {
             stateDto.ReturnedFieldsString = fields;
         }
         return(stateDto);
     } catch (Exception ex) { var response = LocatorsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #12
0
 public Type ResolveTypeByPropertyName(string propertyName)
 {
     return(LocatorsControllerUtils.GetFilterPropertyType(propertyName));
 }
Beispiel #13
0
 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); }
 }