Пример #1
0
        /// <summary>
        ///     Allows you to convert the current category product association object to the DTO equivalent for use with the REST
        ///     API
        /// </summary>
        /// <returns>A new instance of CategoryProductAssociationDTO</returns>
        public CategoryProductAssociationDTO ToDto()
        {
            var dto = new CategoryProductAssociationDTO();

            dto.Id         = Id;
            dto.CategoryId = CategoryId;
            dto.ProductId  = ProductId;
            dto.SortOrder  = SortOrder;
            dto.StoreId    = StoreId;

            return(dto);
        }
        //DTO
        public CategoryProductAssociationDTO ToDto()
        {
            CategoryProductAssociationDTO dto = new CategoryProductAssociationDTO();

            dto.Id         = this.Id;
            dto.CategoryId = this.CategoryId;
            dto.ProductId  = this.ProductId;
            dto.SortOrder  = this.SortOrder;
            dto.StoreId    = this.StoreId;

            return(dto);
        }
Пример #3
0
        /// <summary>
        ///     Allows you to populate the current category product association object using a CategoryProductAssociationDTO
        ///     instance
        /// </summary>
        /// <param name="dto">An instance of the category product association from the REST API</param>
        public void FromDto(CategoryProductAssociationDTO dto)
        {
            if (dto == null)
            {
                return;
            }

            Id         = dto.Id;
            CategoryId = dto.CategoryId;
            ProductId  = dto.ProductId;
            SortOrder  = dto.SortOrder;
            StoreId    = dto.StoreId;
        }
Пример #4
0
        // Create or Update
        public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
        {
            string data = string.Empty;
            string ids  = FirstParameter(parameters);
            long   id   = 0;

            long.TryParse(ids, out id);

            ApiResponse <CategoryProductAssociationDTO> response = new ApiResponse <CategoryProductAssociationDTO>();

            CategoryProductAssociationDTO postedItem = null;

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

            CategoryProductAssociation item = new CategoryProductAssociation();

            item.FromDto(postedItem);

            if (id < 1)
            {
                MTApp.CatalogServices.CategoriesXProducts.AddProductToCategory(item.ProductId, item.CategoryId);
                //if (MTApp.CatalogServices.CategoriesXProducts.Create(item))
                //{
                //    id = item.Id;
                //}
            }
            else
            {
                MTApp.CatalogServices.CategoriesXProducts.Update(item);
            }
            CategoryProductAssociation resultItem = MTApp.CatalogServices.CategoriesXProducts.Find(id);

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

            data = MerchantTribe.Web.Json.ObjectToJson(response);
            return(data);
        }
Пример #5
0
        /// <summary>
        ///     Allows the REST API to create or update a category/product association.
        /// </summary>
        /// <param name="parameters">
        ///     Parameters passed in the URL of the REST API call. Only one parameter is expected, which is
        ///     the ID of the category/product association, but only when updating.
        /// </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 CategoryProductAssociationDTO object</param>
        /// <returns>CategoryProductAssociationDTO - Serialized (JSON) version of the category/product association</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 <CategoryProductAssociationDTO>();

            CategoryProductAssociationDTO postedItem = null;

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

            var item = new CategoryProductAssociation();

            item.FromDto(postedItem);

            if (id < 1)
            {
                item = HccApp.CatalogServices.AddProductToCategory(item.ProductId, item.CategoryId);
            }
            else
            {
                HccApp.CatalogServices.CategoriesXProducts.Update(item);
            }

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

            data = Json.ObjectToJson(response);
            return(data);
        }
        public void Category_TestAssociationsUpdate()
        {
            //Create API Proxy.
            var proxy = CreateApiProxy();

            //Find Category by Slug.
            var resParent = proxy.CategoriesFindBySlug(TestConstants.TestCategorySlug);

            CheckErrors(resParent);

            //Create test product and category.
            var category = new CategoryDTO
            {
                StoreId  = 1,
                Name     = "Test Category",
                ParentId = resParent.Content.Bvin
            };
            var product = new ProductDTO
            {
                ProductName     = "HCC Unit tests product",
                AllowReviews    = true,
                ListPrice       = 687,
                LongDescription = "This is test product",
                Sku             = "TST100",
                StoreId         = 1,
                TaxExempt       = true
            };
            var createCategoryResponse = proxy.CategoriesCreate(category);

            CheckErrors(createCategoryResponse);

            var createProductResponse = proxy.ProductsCreate(product, null);

            //CheckErrors(createProductResponse);

            //Create category and product association.
            category.Bvin = createCategoryResponse.Content.Bvin;
            product.Bvin  = createProductResponse.Content.Bvin;

            var assoc = new CategoryProductAssociationDTO
            {
                ProductId  = product.Bvin,
                CategoryId = category.Bvin
            };
            var assocResponse = proxy.CategoryProductAssociationsCreate(assoc);

            CheckErrors(assocResponse);

            //Update category and product association.
            assocResponse.Content.SortOrder = 100;
            var assocUpdateResponse = proxy.CategoryProductAssociationsUpdate(assocResponse.Content);

            CheckErrors(assocUpdateResponse);

            var findAssociationResponse = proxy.CategoryProductAssociationsFind(assocResponse.Content.Id);

            CheckErrors(findAssociationResponse);
            Assert.AreEqual(assocUpdateResponse.Content.SortOrder, findAssociationResponse.Content.SortOrder);

            //Unrelate the category and product association.
            var unrelateResponse = proxy.CategoryProductAssociationsUnrelate(createProductResponse.Content.Bvin,
                                                                             createCategoryResponse.Content.Bvin);

            CheckErrors(unrelateResponse);
            Assert.IsTrue(unrelateResponse.Content);

            //Delete temporary product.
            var productDeleteResponse = proxy.ProductsDelete(product.Bvin);

            CheckErrors(productDeleteResponse);

            //Delete temporary category.
            var categoryDeleteResponse = proxy.CategoriesDelete(category.Bvin);

            CheckErrors(categoryDeleteResponse);
        }