//DTO
        public ProductVolumeDiscountDTO ToDto()
        {
            ProductVolumeDiscountDTO dto = new ProductVolumeDiscountDTO();

            dto.Amount       = this.Amount;
            dto.StoreId      = this.StoreId;
            dto.Bvin         = this.Bvin;
            dto.DiscountType = (ProductVolumeDiscountTypeDTO)((int)this.DiscountType);
            dto.LastUpdated  = this.LastUpdated;
            dto.ProductId    = this.ProductId;
            dto.Qty          = this.Qty;

            return(dto);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Allows you to convert the current product volume discount object to the DTO equivalent for use with the REST API
        /// </summary>
        /// <returns>A new instance of ProductVolumeDiscountDTO</returns>
        public ProductVolumeDiscountDTO ToDto()
        {
            var dto = new ProductVolumeDiscountDTO();

            dto.Amount       = Amount;
            dto.StoreId      = StoreId;
            dto.Bvin         = Bvin;
            dto.DiscountType = (ProductVolumeDiscountTypeDTO)(int)DiscountType;
            dto.LastUpdated  = LastUpdated;
            dto.ProductId    = ProductId;
            dto.Qty          = Qty;

            return(dto);
        }
        /// <summary>
        ///     Allows the REST API to create or update a product volume discount
        /// </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 volume discount ID (bvin) and that this is an update, otherwise it
        ///     assumes to create a product volume discount.
        /// </param>
        /// <param name="querystring">
        ///     Name/value pairs from the REST API call querystring. This method does not expect any
        ///     querystrings.
        /// </param>
        /// <param name="postdata">Serialized (JSON) version of the ProductVolumeDiscountDTO object</param>
        /// <returns>ProductVolumeDiscountDTO - Serialized (JSON) version of the product volume discount</returns>
        public override string PostAction(string parameters, NameValueCollection querystring, string postdata)
        {
            var data     = string.Empty;
            var bvin     = FirstParameter(parameters);
            var response = new ApiResponse <ProductVolumeDiscountDTO>();

            ProductVolumeDiscountDTO postedItem = null;

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

            // return an error if the posted item isn't there
            if (postedItem == null)
            {
                response.Errors.Add(new ApiError("EXCEPTION", "Post data is missing or null"));
                return(Json.ObjectToJson(response));
            }

            var item = new ProductVolumeDiscount();

            item.FromDto(postedItem);

            if (bvin == string.Empty)
            {
                if (HccApp.CatalogServices.VolumeDiscounts.Create(item))
                {
                    bvin = item.Bvin;
                }
            }
            else
            {
                HccApp.CatalogServices.VolumeDiscounts.Update(item);
            }
            var resultItem = HccApp.CatalogServices.VolumeDiscounts.Find(bvin);

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

            data = Json.ObjectToJson(response);
            return(data);
        }
        public void FromDto(ProductVolumeDiscountDTO dto)
        {
            if (dto == null)
            {
                return;
            }

            this.Amount       = dto.Amount;
            this.StoreId      = dto.StoreId;
            this.Bvin         = dto.Bvin ?? string.Empty;
            this.DiscountType = (ProductVolumeDiscountType)((int)dto.DiscountType);
            this.LastUpdated  = dto.LastUpdated;
            this.ProductId    = dto.ProductId ?? string.Empty;
            this.Qty          = dto.Qty;
        }
        // Create or Update
        public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
        {
            string data = string.Empty;
            string bvin = FirstParameter(parameters);
            ApiResponse <ProductVolumeDiscountDTO> response = new ApiResponse <ProductVolumeDiscountDTO>();

            ProductVolumeDiscountDTO postedItem = null;

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

            ProductVolumeDiscount item = new ProductVolumeDiscount();

            item.FromDto(postedItem);

            if (bvin == string.Empty)
            {
                if (MTApp.CatalogServices.VolumeDiscounts.Create(item))
                {
                    bvin = item.Bvin;
                }
            }
            else
            {
                MTApp.CatalogServices.VolumeDiscounts.Update(item);
            }
            ProductVolumeDiscount resultItem = MTApp.CatalogServices.VolumeDiscounts.Find(bvin);

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

            data = MerchantTribe.Web.Json.ObjectToJson(response);
            return(data);
        }
Ejemplo n.º 6
0
        public void ProductVolumeDiscount_CreateUpdateFindDelete()
        {
            //Create API Proxy.
            var proxy = CreateApiProxy();

            //Create Product Volume Discount.
            var productVolumeDiscount = new ProductVolumeDiscountDTO
            {
                Amount       = 50,
                DiscountType = ProductVolumeDiscountTypeDTO.Amount,
                ProductId    = TestConstants.TestProductBvin,
                Qty          = 5
            };
            var createResponse = proxy.ProductVolumeDiscountsCreate(productVolumeDiscount);

            CheckErrors(createResponse);
            Assert.IsFalse(string.IsNullOrEmpty(createResponse.Content.Bvin));

            //Find Product Volume Discount
            var findResponse = proxy.ProductVolumeDiscountsFind(createResponse.Content.Bvin);

            CheckErrors(findResponse);
            Assert.AreEqual(createResponse.Content.DiscountType, findResponse.Content.DiscountType);
            Assert.AreEqual(createResponse.Content.ProductId, findResponse.Content.ProductId);

            //Update Product Volume Discount
            createResponse.Content.Amount = 75;
            var updateResponse = proxy.ProductVolumeDiscountsUpdate(createResponse.Content);

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

            //Delete Product Volume Discount.
            var deleteResponse = proxy.ProductVolumeDiscountsDelete(createResponse.Content.Bvin);

            CheckErrors(deleteResponse);
            Assert.IsTrue(deleteResponse.Content);
        }