Пример #1
0
        public async Task UpdateOption(Guid id, ProductOption option)
        {
            var opt = await _productsContext.ProductOptions.FirstOrDefaultAsync(o => o.Id == id);

            // check if option exists before attempt to update
            if (opt == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            // update
            TinyMapper.Map(option, opt);

            // save
            await _productsContext.SaveChangesAsync();
        }
Пример #2
0
        public async Task CreateOption(Guid productId, ProductOption option)
        {
            var prod = await _productsContext.Products.FirstOrDefaultAsync(p => p.Id == productId);

            // check if product exists before attempt to add new option
            if (prod == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var newOption = TinyMapper.Map <Persistence.ProductOption>(option);

            newOption.Id = Guid.NewGuid();
            prod.ProductOptions.Add(newOption);

            await _productsContext.SaveChangesAsync();
        }