Exemple #1
0
        // Price Groups and Roles
        private void ImportPriceGroups()
        {
            Header("Importing Price Groups");

            Api oldProxy = GetOldStoreBV6Proxy();
            ApiResponse <List <PriceGroupDTO> > items = oldProxy.PriceGroupsFindAll();

            foreach (PriceGroupDTO oldGroup in items.Content)
            {
                wl("Price Group: " + oldGroup.Name);

                PriceGroupDTO pg       = oldGroup;
                Api           bv6proxy = GetBV6Proxy();
                var           res      = bv6proxy.PriceGroupsCreate(pg);
                if (res != null)
                {
                    if (res.Errors.Count() > 0)
                    {
                        DumpErrors(res.Errors);
                        wl("FAILED");
                    }
                    else
                    {
                        if (res.Content == null)
                        {
                            wl("FAILED!");
                        }
                        else
                        {
                            wl(res.Content.Bvin == string.Empty ? "FAILED" : "SUCCESS");
                        }
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 ///     Allows you to populate the current price group object using a PriceGroupDTO instance
 /// </summary>
 /// <param name="dto">An instance of the price group from the REST API</param>
 public void FromDto(PriceGroupDTO dto)
 {
     AdjustmentAmount = dto.AdjustmentAmount;
     Bvin             = dto.Bvin;
     LastUpdated      = dto.LastUpdated;
     Name             = dto.Name;
     PricingType      = (PricingTypes)(int)dto.PricingType;
     StoreId          = dto.StoreId;
 }
Exemple #3
0
 public void FromDto(PriceGroupDTO dto)
 {
     this.AdjustmentAmount = dto.AdjustmentAmount;
     this.Bvin             = dto.Bvin;
     this.LastUpdated      = dto.LastUpdated;
     this.Name             = dto.Name;
     this.PricingType      = (PricingTypes)((int)dto.PricingType);
     this.StoreId          = dto.StoreId;
 }
Exemple #4
0
        public PriceGroupDTO ToDto()
        {
            PriceGroupDTO dto = new PriceGroupDTO();

            dto.AdjustmentAmount = this.AdjustmentAmount;
            dto.Bvin             = this.Bvin;
            dto.LastUpdated      = this.LastUpdated;
            dto.Name             = this.Name;
            dto.PricingType      = (PricingTypesDTO)((int)this.PricingType);
            dto.StoreId          = this.StoreId;

            return(dto);
        }
Exemple #5
0
        /// <summary>
        ///     Allows you to convert the current price group object to the DTO equivalent for use with the REST API
        /// </summary>
        /// <returns>A new instance of PriceGroupDTO</returns>
        public PriceGroupDTO ToDto()
        {
            var dto = new PriceGroupDTO
            {
                AdjustmentAmount = AdjustmentAmount,
                Bvin             = Bvin,
                LastUpdated      = LastUpdated,
                Name             = Name,
                PricingType      = (PricingTypesDTO)(int)PricingType,
                StoreId          = StoreId
            };

            return(dto);
        }
Exemple #6
0
        // 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 <PriceGroupDTO> response = new ApiResponse <PriceGroupDTO>();

            PriceGroupDTO postedItem = null;

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

            PriceGroup item = new PriceGroup();

            item.FromDto(postedItem);

            if (bvin == string.Empty)
            {
                if (MTApp.ContactServices.PriceGroups.Create(item))
                {
                    bvin = item.Bvin;
                }
            }
            else
            {
                MTApp.ContactServices.PriceGroups.Update(item);
            }
            PriceGroup resultItem = MTApp.ContactServices.PriceGroups.Find(bvin);

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

            data = MerchantTribe.Web.Json.ObjectToJson(response);
            return(data);
        }
Exemple #7
0
        /// <summary>
        ///     Allows the REST API to create or update a price group
        /// </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 price group ID (bvin) and that this is an update, otherwise it assumes to
        ///     create a price group.
        /// </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 PriceGroupDTO object</param>
        /// <returns>PriceGroupDTO - Serialized (JSON) version of the price group</returns>
        public override string PostAction(string parameters, NameValueCollection querystring, string postdata)
        {
            var data     = string.Empty;
            var bvin     = FirstParameter(parameters);
            var response = new ApiResponse <PriceGroupDTO>();

            PriceGroupDTO postedItem = null;

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

            var item = new PriceGroup();

            item.FromDto(postedItem);

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

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

            data = Json.ObjectToJson(response);
            return(data);
        }
Exemple #8
0
        public void PriceGroups_TestCreateAndFindAndDelete()
        {
            //Create API Proxy.
            var proxy = CreateApiProxy();

            //Create Price group.
            var priceGroup = new PriceGroupDTO
            {
                StoreId          = 1,
                Name             = "Test PriceGroup",
                AdjustmentAmount = 5,
                PricingType      = PricingTypesDTO.AmountAboveCost
            };
            var createResponse = proxy.PriceGroupsCreate(priceGroup);

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

            //Find Price group by its unique identifer.
            var findResponse = proxy.PriceGroupsFind(createResponse.Content.Bvin);

            CheckErrors(findResponse);
            Assert.AreEqual(createResponse.Content.Name, findResponse.Content.Name);
            Assert.AreEqual(createResponse.Content.AdjustmentAmount, findResponse.Content.AdjustmentAmount);

            //Update Price group.
            priceGroup.AdjustmentAmount = 50;
            var updateResponse = proxy.PriceGroupsUpdate(priceGroup);

            CheckErrors(updateResponse);
            Assert.AreEqual(priceGroup.AdjustmentAmount, updateResponse.Content.AdjustmentAmount);

            //Delete Price group.
            var deleteResponse = proxy.PriceGroupsDelete(createResponse.Content.Bvin);

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