/// <summary> /// Allows the REST API to create or update a product type /// </summary> /// <param name="parameters"> /// Parameters passed in the URL of the REST API call. If there is a first parameter found in the /// URL, the method will assume it is the product type ID (bvin) and that this is an update, otherwise it assumes to /// create a product type. /// </param> /// <param name="querystring">Name/value pairs from the REST API call querystring. This is not used in this method.</param> /// <param name="postdata">Serialized (JSON) version of the ProductTypeDTO object</param> /// <returns>ProductTypeDTO - Serialized (JSON) version of the ProductType</returns> public override string PostAction(string parameters, NameValueCollection querystring, string postdata) { var data = string.Empty; var bvin = FirstParameter(parameters); // // <site Url>/producttypes/<guid>/properties/<propertyid>/<sortOrder> // var isProperty = GetParameterByIndex(1, parameters); if (isProperty.Trim().ToLowerInvariant() == "properties") { var response2 = new ApiResponse <bool>(); var propertyIds = GetParameterByIndex(2, parameters); long propertyId = 0; long.TryParse(propertyIds, out propertyId); response2.Content = HccApp.CatalogServices.ProductTypeAddProperty(bvin, propertyId); data = Json.ObjectToJson(response2); } else { var response = new ApiResponse <ProductTypeDTO>(); ProductTypeDTO postedItem = null; try { postedItem = Json.ObjectFromJson <ProductTypeDTO>(postdata); } catch (Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return(Json.ObjectToJson(response)); } var item = new ProductType(); item.FromDto(postedItem); if (bvin == string.Empty) { if (HccApp.CatalogServices.ProductTypes.Create(item)) { bvin = item.Bvin; } } else { HccApp.CatalogServices.ProductTypes.Update(item); } var resultItem = HccApp.CatalogServices.ProductTypes.Find(bvin); if (resultItem != null) { response.Content = resultItem.ToDto(); } data = Json.ObjectToJson(response); } return(data); }