Exemple #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);
        }
Exemple #2
0
        // List or Find Single
        public override string GetAction(string parameters, System.Collections.Specialized.NameValueCollection querystring)
        {
            string data = string.Empty;

            if (string.Empty == (parameters ?? string.Empty))
            {
                // List
                ApiResponse <List <PriceGroupDTO> > response = new ApiResponse <List <PriceGroupDTO> >();

                List <PriceGroup>    results = MTApp.ContactServices.PriceGroups.FindAll();
                List <PriceGroupDTO> dto     = new List <PriceGroupDTO>();

                foreach (PriceGroup item in results)
                {
                    dto.Add(item.ToDto());
                }
                response.Content = dto;
                data             = MerchantTribe.Web.Json.ObjectToJson(response);
            }
            else
            {
                // Find One Specific Category
                ApiResponse <PriceGroupDTO> response = new ApiResponse <PriceGroupDTO>();
                string     bvin = FirstParameter(parameters);
                PriceGroup item = MTApp.ContactServices.PriceGroups.Find(bvin);
                if (item == null)
                {
                    response.Errors.Add(new ApiError("NULL", "Could not locate that item. Check bvin and try again."));
                }
                else
                {
                    response.Content = item.ToDto();
                }
                data = MerchantTribe.Web.Json.ObjectToJson(response);
            }

            return(data);
        }