コード例 #1
0
        public async Task <OptionAddedResponse> AddOptionAsync(Guid productId, CreateOrUpdateOptionRequest body)
        {
            _validator.ValidateRequest(body);

            var product = await _productRepository.RetrieveProduct(productId);

            if (product == null)
            {
                // TODO add foreign key constrain between Products and ProductOptions tables
                // https://stackoverflow.com/questions/1884818/how-do-i-add-a-foreign-key-to-an-existing-sqlite-table?answertab=active#tab-top
                throw new NotFoundException($"Product with Id: {productId} not found");
            }

            var dbOption = Map(body);

            dbOption.ProductId = productId;
            var optionId = await _optionRepository.AddOption(productId, dbOption);

            return(new OptionAddedResponse {
                Id = optionId
            });
        }