예제 #1
0
        // Create or Update
        public override string PostAction(string parameters, NameValueCollection querystring, string postdata)
        {
            var data     = string.Empty;
            var bvin     = FirstParameter(parameters);
            var response = new ApiResponse <ProductImageDTO>();

            ProductImageDTO postedItem = null;

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

            var item = new ProductImage();

            item.FromDto(postedItem);

            if (string.IsNullOrEmpty(bvin))
            {
                if (HccApp.CatalogServices.ProductImageCreate(item))
                {
                    bvin = item.Bvin;
                }
            }
            else
            {
                HccApp.CatalogServices.ProductImageUpdate(item);
            }

            var resultItem = HccApp.CatalogServices.ProductImages.Find(bvin);

            if (resultItem != null)
            {
                response.Content = resultItem.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 bvin = FirstParameter(parameters);
            ApiResponse <ProductImageDTO> response = new ApiResponse <ProductImageDTO>();

            ProductImageDTO postedItem = null;

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

            ProductImage item = new ProductImage();

            item.FromDto(postedItem);

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

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

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