コード例 #1
0
        //DTO
        public ProductRelationshipDTO ToDto()
        {
            ProductRelationshipDTO dto = new ProductRelationshipDTO();

            dto.Id                   = this.Id;
            dto.StoreId              = this.StoreId;
            dto.ProductId            = this.ProductId;
            dto.RelatedProductId     = this.RelatedProductId;
            dto.IsSubstitute         = this.IsSubstitute;
            dto.SortOrder            = this.SortOrder;
            dto.MarketingDescription = this.MarketingDescription;

            return(dto);
        }
コード例 #2
0
        /// <summary>
        ///     Allows you to convert the current product relationship object to the DTO equivalent for use with the REST API
        /// </summary>
        /// <returns>A new instance of ProductRelationshipDTO</returns>
        public ProductRelationshipDTO ToDto()
        {
            var dto = new ProductRelationshipDTO();

            dto.Id                   = Id;
            dto.StoreId              = StoreId;
            dto.ProductId            = ProductId;
            dto.RelatedProductId     = RelatedProductId;
            dto.IsSubstitute         = IsSubstitute;
            dto.SortOrder            = SortOrder;
            dto.MarketingDescription = MarketingDescription;

            return(dto);
        }
コード例 #3
0
        public void FromDto(ProductRelationshipDTO dto)
        {
            if (dto == null)
            {
                return;
            }

            this.Id                   = dto.Id;
            this.StoreId              = dto.StoreId;
            this.ProductId            = dto.ProductId;
            this.RelatedProductId     = dto.RelatedProductId;
            this.IsSubstitute         = dto.IsSubstitute;
            this.SortOrder            = dto.SortOrder;
            this.MarketingDescription = dto.MarketingDescription;
        }
コード例 #4
0
        /// <summary>
        ///     Allows the REST API to create or update a product relationship
        /// </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 relationship ID (bvin) and that this is an update, otherwise it
        ///     assumes to create a product relationship.
        /// </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 ProductRelationshipDTO object</param>
        /// <returns>ProductRelationshipDTO - Serialized (JSON) version of the product relationship</returns>
        public override string PostAction(string parameters, NameValueCollection querystring, string postdata)
        {
            var  data = string.Empty;
            var  ids  = FirstParameter(parameters);
            long id   = 0;

            long.TryParse(ids, out id);

            var response = new ApiResponse <ProductRelationshipDTO>();

            ProductRelationshipDTO postedItem = null;

            try
            {
                postedItem = Json.ObjectFromJson <ProductRelationshipDTO>(postdata);
            }
            catch (Exception ex)
            {
                response.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                return(Json.ObjectToJson(response));
            }

            var item = new ProductRelationship();

            item.FromDto(postedItem);

            if (id < 1)
            {
                if (HccApp.CatalogServices.ProductRelationships.Create(item))
                {
                    id = item.Id;
                }
            }
            else
            {
                HccApp.CatalogServices.ProductRelationships.Update(item);
            }

            var resultItem = HccApp.CatalogServices.ProductRelationships.Find(id);

            if (resultItem != null)
            {
                response.Content = resultItem.ToDto();
            }

            data = Json.ObjectToJson(response);
            return(data);
        }
コード例 #5
0
        public void ProductRelationShip_CreateUpdateUnrelate()
        {
            //Create API Proxy.
            var proxy = CreateApiProxy();

            //Create Product relationship
            var productRelationShip = new ProductRelationshipDTO
            {
                MarketingDescription = "Test Marketing Desc",
                ProductId            = TestConstants.TestProductBvin,
                RelatedProductId     = "a7b43865-6a89-4ebe-a43b-a00b5105ae3a",
                StoreId = 1
            };
            var createResponse = proxy.ProductRelationshipsCreate(productRelationShip);

            CheckErrors(createResponse);

            //Update Product relationship
            createResponse.Content.MarketingDescription = createResponse.Content.MarketingDescription + "updated";
            var updateResponse = proxy.ProductRelationshipsUpdate(createResponse.Content);

            CheckErrors(updateResponse);
            Assert.AreEqual(createResponse.Content.MarketingDescription, updateResponse.Content.MarketingDescription);

            //Unrelate the product relationship.
            var unrelateResponse = proxy.ProductRelationshipsUnrelate(TestConstants.TestProductBvin,
                                                                      "a7b43865-6a89-4ebe-a43b-a00b5105ae3a");

            Assert.IsTrue(unrelateResponse.Content);

            //Quick create product relationship.
            var quickCreateResposne = proxy.ProductRelationshipsQuickCreate(TestConstants.TestProductBvin,
                                                                            "a7b43865-6a89-4ebe-a43b-a00b5105ae3a", false);

            Assert.IsTrue(quickCreateResposne.Content);

            //Unrelate the product relationship
            unrelateResponse = proxy.ProductRelationshipsUnrelate(TestConstants.TestProductBvin,
                                                                  "a7b43865-6a89-4ebe-a43b-a00b5105ae3a");
            Assert.IsTrue(unrelateResponse.Content);
        }