Exemplo n.º 1
0
        public async Task UpdateOptionAsync(Guid productId, Guid optionId, CreateOrUpdateOptionRequest body)
        {
            _validator.ValidateRequest(body);
            var dbOption             = Map(body);
            var numberOfRowsAffected = await _optionRepository.UpdateOption(productId, optionId, dbOption);

            if (numberOfRowsAffected == 0)
            {
                throw new NotFoundException($"No option found with Id: {optionId} belongs to product with Id: {productId}");
            }
        }
Exemplo n.º 2
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
            });
        }
Exemplo n.º 3
0
 private static ProductOption Map(CreateOrUpdateOptionRequest dtoOption)
 {
     return(new ProductOption {
         Name = dtoOption.Name, Description = dtoOption.Description
     });
 }
 public System.Threading.Tasks.Task UpdateOption(System.Guid id, System.Guid optionId, [Microsoft.AspNetCore.Mvc.FromBody] CreateOrUpdateOptionRequest body)
 {
     return(_implementation.UpdateOptionAsync(id, optionId, body));
 }
 public System.Threading.Tasks.Task <OptionAddedResponse> AddOption(System.Guid id, [Microsoft.AspNetCore.Mvc.FromBody] CreateOrUpdateOptionRequest body)
 {
     return(_implementation.AddOptionAsync(id, body));
 }