public async Task <T> Insert(T entity) { context.Add(entity); await context.SaveChangesAsync(); return(entity); }
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()); }
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()); }