Beispiel #1
0
 public void Patch(string id, [FromBody] MergePatchUomDto value)
 {
     try {
         UomsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
         _uomApplicationService.When(value as IMergePatchUom);
     } catch (Exception ex) { var response = HttpServiceExceptionUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #2
0
 public IEnumerable <IUomStateDto> GetAll(string sort = null, string fields = null, int firstResult = 0, int maxResults = int.MaxValue, string filter = null)
 {
     try {
         IEnumerable <IUomState> states = null;
         if (!String.IsNullOrWhiteSpace(filter))
         {
             states = _uomApplicationService.Get(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new WebApiControllerTypeConverter(), new PropertyTypeResolver()
                                                                         , n => (UomMetadata.Instance.FilteringPropertyAliasDictionary.ContainsKey(n) ? UomMetadata.Instance.FilteringPropertyAliasDictionary[n] : n))
                                                 , UomsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults);
         }
         else
         {
             states = _uomApplicationService.Get(UomsControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs())
                                                 , UomsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults);
         }
         var stateDtos = new List <IUomStateDto>();
         foreach (var s in states)
         {
             var dto = s is UomStateDtoWrapper ? (UomStateDtoWrapper)s : new UomStateDtoWrapper(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 #3
0
 public UomStateCreatedOrMergePatchedOrDeletedDto GetStateEvent(string id, long version)
 {
     try {
         var idObj = id;
         var conv  = new UomStateEventDtoConverter();
         var se    = _uomApplicationService.GetEvent(idObj, version);
         return(se == null ? null : conv.ToUomStateEventDto(se));
     } catch (Exception ex) { var response = UomsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #4
0
 public void Delete(string id, string commandId, string version, string requesterId = default(string))
 {
     try {
         var value = new DeleteUomDto();
         value.CommandId   = commandId;
         value.RequesterId = requesterId;
         value.Version     = (long)Convert.ChangeType(version, typeof(long));
         UomsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
         _uomApplicationService.When(value as IDeleteUom);
     } catch (Exception ex) { var response = HttpServiceExceptionUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #5
0
        public HttpResponseMessage Post([FromBody] CreateUomDto value)
        {
            try {
                if (value.UomId == default(string))
                {
                    throw DomainError.Named("nullId", "Aggregate Id in cmd is null, aggregate name: {0}.", "Uom");
                }
                _uomApplicationService.When(value as ICreateUom);
                var idObj = value.UomId;

                return(Request.CreateResponse <string>(HttpStatusCode.Created, idObj));
            } catch (Exception ex) { var response = UomsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
        }
Beispiel #6
0
 public long GetCount(string filter = null)
 {
     try {
         long count = 0;
         if (!String.IsNullOrWhiteSpace(filter))
         {
             count = _uomApplicationService.GetCount(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new WebApiControllerTypeConverter(), new PropertyTypeResolver()
                                                                             , n => (UomMetadata.Instance.FilteringPropertyAliasDictionary.ContainsKey(n) ? UomMetadata.Instance.FilteringPropertyAliasDictionary[n] : n)));
         }
         else
         {
             count = _uomApplicationService.GetCount(UomsControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs()));
         }
         return(count);
     } catch (Exception ex) { var response = HttpServiceExceptionUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #7
0
        public void Put(string id, [FromBody] CreateOrMergePatchOrDeleteUomDto value)
        {
            try {
                // ///////////////////////////////
                if (value.Version != default(long))
                {
                    value.CommandType = CommandType.MergePatch;
                    UomsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
                    _uomApplicationService.When(value as IMergePatchUom);
                    return;
                }
                // ///////////////////////////////

                UomsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
                _uomApplicationService.When(value as ICreateUom);
            } catch (Exception ex) { var response = HttpServiceExceptionUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
        }
Beispiel #8
0
 public IEnumerable <PropertyMetadataDto> GetMetadataFilteringFields()
 {
     try {
         var filtering = new List <PropertyMetadataDto>();
         foreach (var p in UomMetadata.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 = UomsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #9
0
 public IUomStateDto Get(string id, string fields = null)
 {
     try {
         var idObj = id;
         var state = _uomApplicationService.Get(idObj);
         if (state == null)
         {
             return(null);
         }
         var stateDto = new UomStateDtoWrapper(state);
         if (String.IsNullOrWhiteSpace(fields))
         {
             stateDto.AllFieldsReturned = true;
         }
         else
         {
             stateDto.ReturnedFieldsString = fields;
         }
         return(stateDto);
     } catch (Exception ex) { var response = UomsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Beispiel #10
0
 public Type ResolveTypeByPropertyName(string propertyName)
 {
     return(UomsControllerUtils.GetFilterPropertyType(propertyName));
 }