public async Task <T> Insert(T entity)
        {
            context.Add(entity);

            await context.SaveChangesAsync();

            return(entity);
        }
Пример #2
0
        public async Task <ProductModel> CreateProduct(ProductModel model)
        {
            var product = new Product();

            model.MapTo(product);
            await _db.Products.AddAsync(product);

            await _db.SaveChangesAsync();

            return(product.MapToDto());
        }
Пример #3
0
        public async Task <OrderDetailModel> AddDetailToOrder(int id, OrderDetailModel model)
        {
            if (await OrderExists(id) == false)
            {
                throw new EntityNotFoundException <OrderModel>(id);
            }

            var detail = new OrderDetail();

            model.MapTo(detail);

            detail.OrderId = id;
            await _db.OrderDetails.AddAsync(detail);

            await _db.SaveChangesAsync();

            return(detail.MapToDto());
        }