Пример #1
0
        /// <summary>
        ///     Allows the REST API to create or update a tax schedule
        /// </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 tax schedule ID and that this is an update, otherwise it assumes to create a
        ///     tax schedule.
        /// </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 TaxScheduleDTO object</param>
        /// <returns>TaxDTO - Serialized (JSON) version of the tax schedule</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 <TaxScheduleDTO>();

            TaxScheduleDTO postedCategory = null;

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

            var item = new TaxSchedule();

            item.FromDto(postedCategory);

            if (id < 1)
            {
                var existing = HccApp.OrderServices.TaxSchedules.FindByNameForThisStore(item.Name);
                if (existing == null)
                {
                    // Create
                    HccApp.OrderServices.TaxSchedules.Create(item);
                }
                else
                {
                    item.Id = existing.Id;
                }
            }
            else
            {
                HccApp.OrderServices.TaxSchedules.Update(item);
            }
            response.Content = item.ToDto();

            data = Json.ObjectToJson(response);
            return(data);
        }
Пример #2
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 <TaxScheduleDTO> response = new ApiResponse <TaxScheduleDTO>();

            TaxScheduleDTO postedCategory = null;

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

            TaxSchedule item = new TaxSchedule();

            item.FromDto(postedCategory);

            if (id < 1)
            {
                TaxSchedule existing = MTApp.OrderServices.TaxSchedules.FindByName(item.Name);
                if (existing == null)
                {
                    // Create
                    MTApp.OrderServices.TaxSchedules.Create(item);
                }
                else
                {
                    item.Id = existing.Id;
                }
            }
            else
            {
                MTApp.OrderServices.TaxSchedules.Update(item);
            }
            response.Content = item.ToDto();

            data = MerchantTribe.Web.Json.ObjectToJson(response);
            return(data);
        }