Exemple #1
0
 public void Patch(string id, [FromBody] MergePatchFacilityDto value)
 {
     try {
         FacilitiesControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
         _facilityApplicationService.When(value as IMergePatchFacility);
     } catch (Exception ex) { var response = FacilitiesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #2
0
 public IEnumerable <IFacilityStateDto> GetAll(string sort = null, string fields = null, int firstResult = 0, int maxResults = int.MaxValue, string filter = null)
 {
     try {
         IEnumerable <IFacilityState> states = null;
         if (!String.IsNullOrWhiteSpace(filter))
         {
             states = _facilityApplicationService.Get(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new ApiControllerTypeConverter(), new PropertyTypeResolver()
                                                                              , n => (FacilityMetadata.Instance.FilteringPropertyAliasDictionary.ContainsKey(n) ? FacilityMetadata.Instance.FilteringPropertyAliasDictionary[n] : n))
                                                      , FacilitiesControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults);
         }
         else
         {
             states = _facilityApplicationService.Get(FacilitiesControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs())
                                                      , FacilitiesControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults);
         }
         var stateDtos = new List <IFacilityStateDto>();
         foreach (var s in states)
         {
             var dto = s is FacilityStateDtoWrapper ? (FacilityStateDtoWrapper)s : new FacilityStateDtoWrapper(s);
             if (String.IsNullOrWhiteSpace(fields))
             {
                 dto.AllFieldsReturned = true;
             }
             else
             {
                 dto.ReturnedFieldsString = fields;
             }
             stateDtos.Add(dto);
         }
         return(stateDtos);
     } catch (Exception ex) { var response = FacilitiesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #3
0
 public FacilityStateCreatedOrMergePatchedOrDeletedDto GetStateEvent(string id, long version)
 {
     try {
         var idObj = id;
         var conv  = new FacilityStateEventDtoConverter();
         var se    = _facilityApplicationService.GetEvent(idObj, version);
         return(se == null ? null : conv.ToFacilityStateEventDto(se));
     } catch (Exception ex) { var response = FacilitiesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #4
0
 public void Delete(string id, string commandId, string version, string requesterId = default(string))
 {
     try {
         var value = new DeleteFacilityDto();
         value.CommandId   = commandId;
         value.RequesterId = requesterId;
         value.Version     = (long)Convert.ChangeType(version, typeof(long));
         FacilitiesControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
         _facilityApplicationService.When(value as IDeleteFacility);
     } catch (Exception ex) { var response = FacilitiesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #5
0
        public HttpResponseMessage Post([FromBody] CreateFacilityDto value)
        {
            try {
                if (value.FacilityId == default(string))
                {
                    throw DomainError.Named("nullId", "Aggregate Id in cmd is null, aggregate name: {0}.", "Facility");
                }
                _facilityApplicationService.When(value as ICreateFacility);
                var idObj = value.FacilityId;

                return(Request.CreateResponse <string>(HttpStatusCode.Created, idObj));
            } catch (Exception ex) { var response = FacilitiesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
        }
 public long GetCount(string filter = null)
 {
     try {
         long count = 0;
         if (!String.IsNullOrWhiteSpace(filter))
         {
             count = _facilityApplicationService.GetCount(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new WebApiControllerTypeConverter(), new PropertyTypeResolver()
                                                                                  , n => (FacilityMetadata.Instance.FilteringPropertyAliasDictionary.ContainsKey(n) ? FacilityMetadata.Instance.FilteringPropertyAliasDictionary[n] : n)));
         }
         else
         {
             count = _facilityApplicationService.GetCount(FacilitiesControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs()));
         }
         return(count);
     } catch (Exception ex) { var response = HttpServiceExceptionUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #7
0
 public IEnumerable <PropertyMetadataDto> GetMetadataFilteringFields()
 {
     try {
         var filtering = new List <PropertyMetadataDto>();
         foreach (var p in FacilityMetadata.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 = FacilitiesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #8
0
        public void Put(string id, [FromBody] CreateOrMergePatchOrDeleteFacilityDto value)
        {
            try {
                // ///////////////////////////////
                if (value.Version != default(long))
                {
                    value.CommandType = CommandType.MergePatch;
                    FacilitiesControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
                    _facilityApplicationService.When(value as IMergePatchFacility);
                    return;
                }
                // ///////////////////////////////

                FacilitiesControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
                _facilityApplicationService.When(value as ICreateFacility);
            } catch (Exception ex) { var response = FacilitiesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
        }
Exemple #9
0
 public IFacilityStateDto Get(string id, string fields = null)
 {
     try {
         var idObj = id;
         var state = _facilityApplicationService.Get(idObj);
         if (state == null)
         {
             return(null);
         }
         var stateDto = new FacilityStateDtoWrapper(state);
         if (String.IsNullOrWhiteSpace(fields))
         {
             stateDto.AllFieldsReturned = true;
         }
         else
         {
             stateDto.ReturnedFieldsString = fields;
         }
         return(stateDto);
     } catch (Exception ex) { var response = FacilitiesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #10
0
 public Type ResolveTypeByPropertyName(string propertyName)
 {
     return(FacilitiesControllerUtils.GetFilterPropertyType(propertyName));
 }