コード例 #1
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);
        }
コード例 #2
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);
        }