Пример #1
0
        public async Task Create(Product product)
        {
            var newProduct = TinyMapper.Map <Persistence.Product>(product);

            newProduct.Id = Guid.NewGuid();
            _productsContext.Products.Add(newProduct);
            await _productsContext.SaveChangesAsync();
        }
Пример #2
0
        public async Task Update(Guid id, Product product)
        {
            var prod = await _productsContext.Products.FirstOrDefaultAsync(p => p.Id == id);

            // throw not found
            if (prod == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            // flag for update
            TinyMapper.Map(product, prod);

            await _productsContext.SaveChangesAsync();
        }