public ApiResponse <ProductOptionsDTO> UpdateOption(Guid productId, Guid id, [FromBody] ProductOptionDTO option)
 {
     if (id != null && productId != null && option != null)
     {
         try
         {
             this._service.UpdateChild(productId, id, option);
             return(new ApiResponse <ProductOptionsDTO>()
             {
                 StatusCode = (int)HttpStatusCode.OK, ErrorMessage = ""
             });
         }
         catch (Exception ex)
         {
             return(new ApiResponse <ProductOptionsDTO>()
             {
                 StatusCode = (int)HttpStatusCode.InternalServerError, ErrorMessage = ex.Message
             });
         }
     }
     return(new ApiResponse <ProductOptionsDTO>()
     {
         StatusCode = (int)HttpStatusCode.BadRequest, ErrorMessage = ""
     });
 }
        private string GetproductOptionsDescriptionByGuid(Guid productId, Guid productOptionId)
        {
            ProductOptionDTO productDto = new ProductOptionDTO();

            productDto = productOptionsController.GetProductOptions(productId, productOptionId) as ProductOptionDTO;
            return(productDto.Description);
        }
        private Guid GetproductOptionsByGuid(Guid productId, Guid productOptionId)
        {
            ProductOptionDTO productDto = new ProductOptionDTO();

            productDto = productOptionsController.GetProductOptions(productId, productOptionId) as ProductOptionDTO;
            return(productDto.Id);
        }
Beispiel #4
0
        private ProductOptionDTO[] GetOptions(Product product, ICollection <CustomOption> customOptions)
        {
            if (product.BaseOptions == null || product.BaseOptions.Count == 0)
            {
                return(new ProductOptionDTO[0]);
            }

            var hasCustomOptions = customOptions != null && customOptions.Count > 0;
            var result           = new List <ProductOptionDTO>();

            foreach (var opt in product.BaseOptions)
            {
                var option = new ProductOptionDTO
                {
                    Id   = opt.Id.ToString(),
                    Name = opt.Name,
                };
                var optionValue = opt.Value;

                if (hasCustomOptions)
                {
                    var relatedOption = customOptions.FirstOrDefault(co => co.ProductId == product.Id && co.OptionId == opt.Id);
                    if (relatedOption != null)
                    {
                        optionValue = relatedOption.Value;
                    }
                }
                option.Value = optionValue;
                result.Add(option);
            }

            return(result.ToArray());
        }
Beispiel #5
0
        public ProductOptionDTO GetProductOptions(Guid productId, Guid productOptionId)
        {
            ProductOptionDTO productOptionDTO = _productOptionService.GetProductOptions(productId, productOptionId);

            if (productOptionDTO == null)
            {
                var response = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent(string.Format("No Product Options Found with ProductID={0}", productId)),
                    ReasonPhrase = "No Product Options Found"
                };
                throw new HttpResponseException(response);
            }
            return(productOptionDTO);
        }
Beispiel #6
0
        public void Update(ProductOptionDTO option)
        {
            var productOptionValidator = new ProductOptionValidator();
            var results = productOptionValidator.Validate(option);

            if (!results.IsValid)
            {
                results.AddToModelState(ModelState, "ProductOption");
            }


            var dto = new ProductOption
            {
                Description = option.Description,
                Name        = option.Name,
                ProductId   = option.ProductId
            };

            base._RefactorMeProvider
            .ProductOptions.Edit(dto);
        }
Beispiel #7
0
        public ProductOptionDTO Create(ProductOptionDTO option)
        {
            var productOptionValidator = new ProductOptionValidator();
            var results = productOptionValidator.Validate(option);

            if (!results.IsValid)
            {
                results.AddToModelState(ModelState, "ProductOption");
            }


            var dto = new ProductOption
            {
                Description = option.Description,
                Name        = option.Name,
                ProductId   = option.ProductId
            };

            base._RefactorMeProvider
            .ProductOptions.AddAsync(dto);
            option.Id = dto.Id;
            return(option);
        }