Exemple #1
0
 public IEnumerable <IProductStateDto> GetAll(string sort = null, string fields = null, int firstResult = 0, int maxResults = int.MaxValue, string filter = null)
 {
     try {
         IEnumerable <IProductState> states = null;
         if (!String.IsNullOrWhiteSpace(filter))
         {
             states = _productApplicationService.Get(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new ApiControllerTypeConverter(), new PropertyTypeResolver()
                                                                             , n => (ProductMetadata.Instance.FilteringPropertyAliasDictionary.ContainsKey(n) ? ProductMetadata.Instance.FilteringPropertyAliasDictionary[n] : n))
                                                     , ProductsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults);
         }
         else
         {
             states = _productApplicationService.Get(ProductsControllerUtils.GetQueryFilterDictionary(this.Request.GetQueryNameValuePairs())
                                                     , ProductsControllerUtils.GetQueryOrders(sort, QueryOrderSeparator), firstResult, maxResults);
         }
         var stateDtos = new List <IProductStateDto>();
         foreach (var s in states)
         {
             var dto = s is ProductStateDtoWrapper ? (ProductStateDtoWrapper)s : new ProductStateDtoWrapper(s);
             if (String.IsNullOrWhiteSpace(fields))
             {
                 dto.AllFieldsReturned = true;
             }
             else
             {
                 dto.ReturnedFieldsString = fields;
             }
             stateDtos.Add(dto);
         }
         return(stateDtos);
     } catch (Exception ex) { var response = ProductsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #2
0
 public void Patch(string id, [FromBody] MergePatchProductDto value)
 {
     try {
         ProductsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
         _productApplicationService.When(value as IMergePatchProduct);
     } catch (Exception ex) { var response = ProductsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #3
0
 public ProductStateCreatedOrMergePatchedOrDeletedDto GetStateEvent(string id, long version)
 {
     try {
         var idObj = id;
         var conv  = new ProductStateEventDtoConverter();
         var se    = _productApplicationService.GetEvent(idObj, version);
         return(se == null ? null : conv.ToProductStateEventDto(se));
     } catch (Exception ex) { var response = ProductsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #4
0
 public IGoodIdentificationStateDto GetGoodIdentification(string productId, string goodIdentificationTypeId)
 {
     try {
         var state = (GoodIdentificationState)_productApplicationService.GetGoodIdentification(productId, goodIdentificationTypeId);
         if (state == null)
         {
             return(null);
         }
         var stateDto = new GoodIdentificationStateDtoWrapper(state);
         stateDto.AllFieldsReturned = true;
         return(stateDto);
     } catch (Exception ex) { var response = ProductsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #5
0
        public HttpResponseMessage Post([FromBody] CreateProductDto value)
        {
            try {
                if (value.ProductId == default(string))
                {
                    throw DomainError.Named("nullId", "Aggregate Id in cmd is null, aggregate name: {0}.", "Product");
                }
                _productApplicationService.When(value as ICreateProduct);
                var idObj = value.ProductId;

                return(Request.CreateResponse <string>(HttpStatusCode.Created, idObj));
            } catch (Exception ex) { var response = ProductsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
        }
Exemple #6
0
 public long GetCount(string filter = null)
 {
     try {
         long count = 0;
         if (!String.IsNullOrWhiteSpace(filter))
         {
             count = _productApplicationService.GetCount(CriterionDto.ToSubclass(JObject.Parse(filter).ToObject <CriterionDto>(), new WebApiControllerTypeConverter(), new PropertyTypeResolver()
                                                                                 , n => (ProductMetadata.Instance.FilteringPropertyAliasDictionary.ContainsKey(n) ? ProductMetadata.Instance.FilteringPropertyAliasDictionary[n] : n)));
         }
         else
         {
             count = _productApplicationService.GetCount(ProductsControllerUtils.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 ProductMetadata.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 = ProductsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #8
0
        public void Put(string id, [FromBody] CreateOrMergePatchOrDeleteProductDto value)
        {
            try {
                // ///////////////////////////////
                if (value.Version != default(long))
                {
                    value.CommandType = CommandType.MergePatch;
                    ProductsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
                    _productApplicationService.When(value as IMergePatchProduct);
                    return;
                }
                // ///////////////////////////////

                ProductsControllerUtils.SetNullIdOrThrowOnInconsistentIds(id, value);
                _productApplicationService.When(value as ICreateProduct);
            } catch (Exception ex) { var response = ProductsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
        }
Exemple #9
0
 public IEnumerable <IGoodIdentificationStateDto> GetGoodIdentifications(string productId)
 {
     try {
         var states = _productApplicationService.GetGoodIdentifications(productId);
         if (states == null)
         {
             return(null);
         }
         var stateDtos = new List <IGoodIdentificationStateDto>();
         foreach (var s in states)
         {
             var dto = s is GoodIdentificationStateDtoWrapper ? (GoodIdentificationStateDtoWrapper)s : new GoodIdentificationStateDtoWrapper((GoodIdentificationState)s);
             dto.AllFieldsReturned = true;
             stateDtos.Add(dto);
         }
         return(stateDtos);
     } catch (Exception ex) { var response = ProductsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #10
0
 public IProductStateDto Get(string id, string fields = null)
 {
     try {
         var idObj = id;
         var state = _productApplicationService.Get(idObj);
         if (state == null)
         {
             return(null);
         }
         var stateDto = new ProductStateDtoWrapper(state);
         if (String.IsNullOrWhiteSpace(fields))
         {
             stateDto.AllFieldsReturned = true;
         }
         else
         {
             stateDto.ReturnedFieldsString = fields;
         }
         return(stateDto);
     } catch (Exception ex) { var response = ProductsControllerUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
 }
Exemple #11
0
 public Type ResolveTypeByPropertyName(string propertyName)
 {
     return(ProductsControllerUtils.GetFilterPropertyType(propertyName));
 }