Exemple #1
0
        public async Task <IActionResult> UpdateProductSpecificationAttribute(
            [ModelBinder(typeof(JsonModelBinder <ProductSpecificationAttributeDto>))]
            Delta <ProductSpecificationAttributeDto> productSpecificationAttributeDelta)
        {
            // Here we display the errors if the validation has failed at some point.
            if (!ModelState.IsValid)
            {
                return(Error());
            }

            // We do not need to validate the product attribute id, because this will happen in the model binder using the dto validator.
            var productSpecificationAttributeId = productSpecificationAttributeDelta.Dto.Id;

            var productSpecificationAttribute = await _specificationAttributeService.GetProductSpecificationAttributeByIdAsync(productSpecificationAttributeId);

            if (productSpecificationAttribute == null)
            {
                return(Error(HttpStatusCode.NotFound, "product specification attribute", "not found"));
            }

            productSpecificationAttributeDelta.Merge(productSpecificationAttribute);

            await _specificationAttributeService.UpdateProductSpecificationAttributeAsync(productSpecificationAttribute);

            await CustomerActivityService.InsertActivityAsync("EditProductSpecificationAttribute", productSpecificationAttribute.Id.ToString());

            // Preparing the result dto of the new product attribute
            var productSpecificationAttributeDto = _dtoHelper.PrepareProductSpecificationAttributeDto(productSpecificationAttribute);

            var productSpecificatoinAttributesRootObjectDto = new ProductSpecificationAttributesRootObjectDto();

            productSpecificatoinAttributesRootObjectDto.ProductSpecificationAttributes.Add(productSpecificationAttributeDto);

            var json = JsonFieldsSerializer.Serialize(productSpecificatoinAttributesRootObjectDto, string.Empty);

            return(new RawJsonActionResult(json));
        }