示例#1
0
 public IEnumerable <IProductCategoryStateDto> GetAll(string sort = null, string fields = null, int firstResult = 0, int maxResults = int.MaxValue, string filter = null)
 {
     try {
         IEnumerable <IProductCategoryState> states = null;
         if (!String.IsNullOrWhiteSpace(filter))
         {
             states = _productCategoryApplicationService.Get(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new ApiControllerTypeConverter(), new PropertyTypeResolver()
                                                                                     , n => (ProductCategoryMetadata.Instance.FilteringPropertyAliasDictionary.ContainsKey(n) ? ProductCategoryMetadata.Instance.FilteringPropertyAliasDictionary[n] : n))
                                                             , ProductCategoriesControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults);
         }
         else
         {
             states = _productCategoryApplicationService.Get(ProductCategoriesControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs())
                                                             , ProductCategoriesControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults);
         }
         var stateDtos = new List <IProductCategoryStateDto>();
         foreach (var s in states)
         {
             var dto = s is ProductCategoryStateDtoWrapper ? (ProductCategoryStateDtoWrapper)s : new ProductCategoryStateDtoWrapper(s);
             if (String.IsNullOrWhiteSpace(fields))
             {
                 dto.AllFieldsReturned = true;
             }
             else
             {
                 dto.ReturnedFieldsString = fields;
             }
             stateDtos.Add(dto);
         }
         return(stateDtos);
     } catch (Exception ex) { var response = ProductCategoriesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
示例#2
0
 public void Patch(string id, [FromBody] MergePatchProductCategoryDto value)
 {
     try {
         ProductCategoriesControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
         _productCategoryApplicationService.When(value as IMergePatchProductCategory);
     } catch (Exception ex) { var response = ProductCategoriesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
示例#3
0
 public ProductCategoryStateCreatedOrMergePatchedOrDeletedDto GetStateEvent(string id, long version)
 {
     try {
         var idObj = id;
         var conv  = new ProductCategoryStateEventDtoConverter();
         var se    = _productCategoryApplicationService.GetEvent(idObj, version);
         return(se == null ? null : conv.ToProductCategoryStateEventDto(se));
     } catch (Exception ex) { var response = ProductCategoriesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
示例#4
0
 public void Delete(string id, string commandId, string version, string requesterId = default(string))
 {
     try {
         var value = new DeleteProductCategoryDto();
         value.CommandId   = commandId;
         value.RequesterId = requesterId;
         value.Version     = (long)Convert.ChangeType(version, typeof(long));
         ProductCategoriesControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
         _productCategoryApplicationService.When(value as IDeleteProductCategory);
     } catch (Exception ex) { var response = ProductCategoriesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
示例#5
0
        public HttpResponseMessage Post([FromBody] CreateProductCategoryDto value)
        {
            try {
                if (value.ProductCategoryId == default(string))
                {
                    throw DomainError.Named("nullId", "Aggregate Id in cmd is null, aggregate name: {0}.", "ProductCategory");
                }
                _productCategoryApplicationService.When(value as ICreateProductCategory);
                var idObj = value.ProductCategoryId;

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

                ProductCategoriesControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
                _productCategoryApplicationService.When(value as ICreateProductCategory);
            } catch (Exception ex) { var response = ProductCategoriesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
        }
示例#9
0
 public IEnumerable <IProductCategoryStateDto> GetChildProductCategories(string id)
 {
     try {
         var idObj  = id;
         var states = _productCategoryApplicationService.GetChildProductCategories(idObj);
         if (states == null)
         {
             return(null);
         }
         var stateDtos = new List <IProductCategoryStateDto>();
         foreach (var s in states)
         {
             var dto = s is ProductCategoryStateDtoWrapper ? (ProductCategoryStateDtoWrapper)s : new ProductCategoryStateDtoWrapper((ProductCategoryState)s);
             dto.AllFieldsReturned = true;
             stateDtos.Add(dto);
         }
         return(stateDtos);
     } catch (Exception ex) { var response = ProductCategoriesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
示例#10
0
 public IProductCategoryStateDto Get(string id, string fields = null)
 {
     try {
         var idObj = id;
         var state = _productCategoryApplicationService.Get(idObj);
         if (state == null)
         {
             return(null);
         }
         var stateDto = new ProductCategoryStateDtoWrapper(state);
         if (String.IsNullOrWhiteSpace(fields))
         {
             stateDto.AllFieldsReturned = true;
         }
         else
         {
             stateDto.ReturnedFieldsString = fields;
         }
         return(stateDto);
     } catch (Exception ex) { var response = ProductCategoriesControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }