Пример #1
0
        public ProductCategoryDto Post(CreateProductCategoryDto dto)
        {
            //if(dto.SequenceId.lengh <= 4 )

            var productCategory = new ProductCategory();

            Mapper.Map(dto, productCategory);

            if (productCategory.ParentId == null)
            {
                var category = _context.ProductCategory.GetAllProductCategories();
                productCategory.SequenceId = SequenceId(category, null);
            }

            if (productCategory.ParentId != null)
            {
                var category         = _context.ProductCategory.GetAllProductCategories().Where(w => w.ParentId == dto.ParentId);
                var parentSequenceId =
                    _context.ProductCategory.GetSingleOrDefault(w => w.Id == productCategory.ParentId).SequenceId;
                productCategory.SequenceId = parentSequenceId + SequenceId(category, parentSequenceId);
            }

            _context.ProductCategory.Add(productCategory);
            _context.SaveChanges();

            return(Mapper.Map <ProductCategoryDto>(productCategory));
        }
        public IActionResult Post([FromBody] CreateProductCategoryDto productCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(Ok(_context.Post(productCategory)));
        }
Пример #3
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 = HttpServiceExceptionUtils.GetErrorHttpResponseMessage(ex); throw new HttpResponseException(response); }
        }
        public async Task WhenAsync(CreateProductCategoryDto c)
        {
            var idObj         = (c as ICreateProductCategory).ProductCategoryId;
            var uriParameters = new ProductCategoryUriParameters();

            uriParameters.Id = idObj;

            var req = new ProductCategoryPutRequest(uriParameters, (CreateProductCategoryDto)c);

            var resp = await _ramlClient.ProductCategory.Put(req);

            ProductCategoryProxyUtils.ThrowOnHttpResponseError(resp);
        }
 public void When(CreateProductCategoryDto c)
 {
     WhenAsync(c).GetAwaiter().GetResult();
 }