public void Create(Location location) { // map to EF model var entity = new LocationEntity { Name = location.Name, Stock = location.Stock }; _context.Locations.Add(entity); // write changes to DB _context.SaveChanges(); }
// only support changing stock public void Update(Location location) { // query the DB var entity = _context.Locations.First(l => l.Name == location.Name); entity.Stock = location.Stock; // write changes to DB _context.SaveChanges(); }
public void Create(Order order) { // query the DB for the location var locationEntity = _context.Locations.First(l => l.Name == order.Location.Name); // map to EF model var orderEntity = new OrderEntity { Quantity = order.Quantity, Location = locationEntity }; _context.Orders.Add(orderEntity); // push the changes to the DB _context.SaveChanges(); // update the domain model with the new ID order.Id = orderEntity.Id; }