public IActionResult GetProductAttributes(ProductAttributesParametersModel parameters) { if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit) { return(Error(HttpStatusCode.BadRequest, "limit", "invalid limit parameter")); } if (parameters.Page < Configurations.DefaultPageValue) { return(Error(HttpStatusCode.BadRequest, "page", "invalid page parameter")); } var allProductAttributes = _productAttributesApiService.GetProductAttributes(parameters.Limit, parameters.Page, parameters.SinceId); IList <ProductAttributeDto> productAttributesAsDtos = allProductAttributes.Select(productAttribute => { return(_dtoHelper.PrepareProductAttributeDTO(productAttribute)); }).ToList(); var productAttributesRootObject = new ProductAttributesRootObjectDto() { ProductAttributes = productAttributesAsDtos }; var json = _jsonFieldsSerializer.Serialize(productAttributesRootObject, parameters.Fields); return(new RawJsonActionResult(json)); }
public IActionResult CreateProductAttribute([ModelBinder(typeof(JsonModelBinder <ProductAttributeDto>))] Delta <ProductAttributeDto> productAttributeDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } // Inserting the new product ProductAttribute productAttribute = new ProductAttribute(); productAttributeDelta.Merge(productAttribute); _productAttributeService.InsertProductAttribute(productAttribute); _customerActivityService.InsertActivity("AddNewProductAttribute", _localizationService.GetResource("ActivityLog.AddNewProductAttribute"), productAttribute.Name); // Preparing the result dto of the new product ProductAttributeDto productAttributeDto = _dtoHelper.PrepareProductAttributeDTO(productAttribute); var productAttributesRootObjectDto = new ProductAttributesRootObjectDto(); productAttributesRootObjectDto.ProductAttributes.Add(productAttributeDto); var json = _jsonFieldsSerializer.Serialize(productAttributesRootObjectDto, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult UpdateProductAttribute([ModelBinder(typeof(JsonModelBinder <ProductAttributeDto>))] Delta <ProductAttributeDto> productAttributeDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } var productAttribute = _productAttributesApiService.GetById(productAttributeDelta.Dto.Id); if (productAttribute == null) { return(Error(HttpStatusCode.NotFound, "product attribute", "not found")); } productAttributeDelta.Merge(productAttribute); _productAttributeService.UpdateProductAttribute(productAttribute); CustomerActivityService.InsertActivity("EditProductAttribute", LocalizationService.GetResource("ActivityLog.EditProductAttribute"), productAttribute); // Preparing the result dto of the new product attribute var productAttributeDto = _dtoHelper.PrepareProductAttributeDTO(productAttribute); var productAttributesRootObjectDto = new ProductAttributesRootObjectDto(); productAttributesRootObjectDto.ProductAttributes.Add(productAttributeDto); var json = JsonFieldsSerializer.Serialize(productAttributesRootObjectDto, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult GetProductAttributeById(int id, string fields = "") { if (id <= 0) { return(Error(HttpStatusCode.BadRequest, "id", "invalid id")); } ProductAttribute productAttribute = _productAttributesApiService.GetById(id); if (productAttribute == null) { return(Error(HttpStatusCode.NotFound, "product attribute", "not found")); } ProductAttributeDto productAttributeDto = _dtoHelper.PrepareProductAttributeDTO(productAttribute); var productAttributesRootObject = new ProductAttributesRootObjectDto(); productAttributesRootObject.ProductAttributes.Add(productAttributeDto); var json = _jsonFieldsSerializer.Serialize(productAttributesRootObject, fields); return(new RawJsonActionResult(json)); }