Esempio n. 1
0
        //DTO
        public ProductFileDTO ToDto()
        {
            ProductFileDTO dto = new ProductFileDTO();

            dto.AvailableMinutes = this.AvailableMinutes;
            dto.Bvin             = this.Bvin;
            dto.FileName         = this.FileName;
            dto.LastUpdated      = this.LastUpdated;
            dto.MaxDownloads     = this.MaxDownloads;
            dto.ProductId        = this.ProductId;
            dto.ShortDescription = this.ShortDescription;
            dto.StoreId          = this.StoreId;

            return(dto);
        }
        /// <summary>
        ///     Create DTO object for API
        /// </summary>
        /// <returns></returns>
        public ProductFileDTO ToDto()
        {
            var dto = new ProductFileDTO();

            dto.AvailableMinutes = AvailableMinutes;
            dto.Bvin             = Bvin;
            dto.FileName         = FileName;
            dto.LastUpdated      = LastUpdated;
            dto.MaxDownloads     = MaxDownloads;
            dto.ProductId        = ProductId;
            dto.ShortDescription = ShortDescription;
            dto.StoreId          = StoreId;

            return(dto);
        }
Esempio n. 3
0
        public void FromDto(ProductFileDTO dto)
        {
            if (dto == null)
            {
                return;
            }

            this.AvailableMinutes = dto.AvailableMinutes;
            this.Bvin             = dto.Bvin;
            this.FileName         = dto.FileName;
            this.LastUpdated      = dto.LastUpdated;
            this.MaxDownloads     = dto.MaxDownloads;
            this.ProductId        = dto.ProductId;
            this.ShortDescription = dto.ShortDescription;
            this.StoreId          = dto.StoreId;
        }
Esempio n. 4
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 <ProductFileDTO>();

            ProductFileDTO postedItem = null;

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

            var item = new ProductFile();

            item.FromDto(postedItem);

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

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

            data = Json.ObjectToJson(response);
            return(data);
        }
Esempio n. 5
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 <ProductFileDTO> response = new ApiResponse <ProductFileDTO>();

            ProductFileDTO postedItem = null;

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

            ProductFile item = new ProductFile();

            item.FromDto(postedItem);

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

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

            data = MerchantTribe.Web.Json.ObjectToJson(response);
            return(data);
        }
Esempio n. 6
0
        public void ProductFiles_CreateUpdateDelete()
        {
            //Create API Proxy.
            var proxy = CreateApiProxy();

            //Create Product File.
            var productfile = new ProductFileDTO
            {
                FileName         = "Test" + DateTime.Now.ToString("yyyyMMddHHmmss"),
                MaxDownloads     = 5,
                ShortDescription = "My test file for product",
                ProductId        = TestConstants.TestProductBvin,
                StoreId          = 1,
                AvailableMinutes = 20
            };
            var createResponse = proxy.ProductFilesCreate(productfile);

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

            //Update product file.
            createResponse.Content.ShortDescription = createResponse.Content.ShortDescription + "updated";
            var updateResponse = proxy.ProductFilesUpdate(createResponse.Content);

            CheckErrors(updateResponse);
            Assert.AreEqual(createResponse.Content.ShortDescription, updateResponse.Content.ShortDescription);

            //Find product file.
            var findResponse = proxy.ProductFilesFind(createResponse.Content.Bvin);

            CheckErrors(findResponse);
            Assert.AreEqual(updateResponse.Content.MaxDownloads, findResponse.Content.MaxDownloads);


            //Upload product file first part.
            var imagePath     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data/ProductImage.jpg");
            var imageData     = File.ReadAllBytes(imagePath);
            var firstPartData = new byte[imageData.Length / 2];
            var secondPart    = new byte[imageData.Length / 2];

            Array.Copy(imageData, 0, firstPartData, 0, imageData.Length / 2);
            Array.Copy(imageData, imageData.Length / 2, firstPartData, 0, imageData.Length / 2);
            var firstPartResponse = proxy.ProductFilesDataUploadFirstPart(findResponse.Content.Bvin, "ProductImage.jpg",
                                                                          "Test UPload", firstPartData);

            Assert.IsTrue(firstPartResponse.Content);

            //Upload product file second part
            var secondPartResponse = proxy.ProductFilesDataUploadAdditionalPart(findResponse.Content.Bvin,
                                                                                "ProductImage.jpg", secondPart);

            Assert.IsTrue(firstPartResponse.Content);

            //Add file to product.
            var addfileToProductResponse = proxy.ProductFilesAddToProduct(TestConstants.TestProductBvin,
                                                                          findResponse.Content.Bvin, 5, 10);

            Assert.IsTrue(addfileToProductResponse.Content);

            //Find product files for Product
            var findforProductResponse = proxy.ProductFilesFindForProduct(TestConstants.TestProductBvin);

            CheckErrors(findforProductResponse);
            Assert.IsTrue(findforProductResponse.Content.Count > 0);

            //Remove product files for Product
            var removefileToProductResponse = proxy.ProductFilesRemoveFromProduct(TestConstants.TestProductBvin,
                                                                                  findResponse.Content.Bvin);

            Assert.IsTrue(removefileToProductResponse.Content);

            //Delete product file
            var deleteResponse = proxy.ProductFilesDelete(findResponse.Content.Bvin);

            Assert.IsTrue(deleteResponse.Content);
        }