Exemplo n.º 1
0
        public void Create(ProductOptionView product)
        {
            var productOptionToAdd = product;

            productOptionToAdd.Id = Guid.NewGuid();
            _productOptionRepository.Add(Mapper.Map <ProductOption>(productOptionToAdd));
            _productOptionRepository.SaveChanges();
        }
Exemplo n.º 2
0
 public IHttpActionResult UpdateOption(ProductOptionView option)
 {
     try
     {
         _productOptionLibrary.Update(option);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message + ex.InnerException?.Message + ex.InnerException?.StackTrace));
     }
 }
Exemplo n.º 3
0
        public async Task <ProductDetailView> GetDetailAsync(int productId)
        {
            var productInfo = await _unitOfWork.ProductRepository.GetAsync(productId);

            if (productInfo == null)
            {
                throw new RestException(HttpStatusCode.NotFound, new { customer = "Not found" });
            }

            ProductDetailView result = new ProductDetailView()
            {
                Id                 = productInfo.Id,
                BasePrice          = productInfo.BasePrice,
                Description        = productInfo.Description,
                MaxAllowedOrderQty = productInfo.MaxAllowedOrderQty,
                Name               = productInfo.Name
            };

            //Get Options
            var options = await _unitOfWork.ProductOptionRepository.GetByProductAsync(productId);

            if (options != null)
            {
                List <ProductOptionView> optViews = new List <ProductOptionView>();
                foreach (var opt in options)
                {
                    ProductOptionView optView = new ProductOptionView()
                    {
                        AdditionalCost    = opt.AdditionalCost,
                        Id                = opt.Id,
                        OptionDescription = opt.OptionDescription
                    };
                    optViews.Add(optView);
                }
                result.ProductOptions = optViews;
            }

            return(result);
        }
Exemplo n.º 4
0
 public void Update(ProductOptionView product)
 {
     _productOptionRepository.Update(Mapper.Map <ProductOption>(product));
     _productOptionRepository.SaveChanges();
 }