public IHttpActionResult PostProductOption(Guid productId, ProductOption productOption)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                productOption.ProductId = productId;
                db.Add(productOption);
            }
            catch (DbUpdateException)
            {
                if (ProductOptionExists(productOption.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            return(GetProductOption(productId, productOption.Id));
        }
예제 #2
0
        public void ProductOptionRepositoryAddTest()
        {
            //Arrange
            ProductOption productOption = new ProductOption
            {
                Id          = Guid.NewGuid(),
                ProductId   = new Guid("de1287c0-4b15-4a7b-9d8a-dd21b3cafec3"),
                Name        = "New Color",
                Description = "New Color Apple",
            };

            //Action
            using (ProductOptionRepository productOptionRepository = new ProductOptionRepository())
            {
                //Assert
                Assert.AreEqual(1, productOptionRepository.Add(productOption));
            }
        }