/// <summary> /// Adds the given Customer as a new Customer to the database. /// </summary> /// <param name="c"></param> public void AddCustomer(Domain.Customer c) { Customer entity = new Customer() { FirstName = c.FirstName, LastName = c.LastName, DefaultLocationId = c.DefaultLocationID }; _context.Set <Customer>().Add(entity); _context.SaveChanges(); }
/// <summary> /// Adds the given Order to the database. /// </summary> /// <param name="o"></param> public void AddOrder(Domain.Order o) { Order entity = new Order() { CustomerId = o.CustomerID, LocationId = o.LocationID, Time = o.Time.UtcDateTime, TotalPrice = o.Total }; _context.Set <Order>().Add(entity); _context.SaveChanges(); foreach (var kv in o.Items) { OrderLine ol = new OrderLine() { OrderId = entity.Id, ProductId = kv.Key.ID, Amount = kv.Value }; _context.Set <OrderLine>().Add(ol); } _context.SaveChanges(); }
/// <summary> /// Updates the given Location in the database. /// </summary> /// <param name="l"></param> public void UpdateLocation(Domain.Location l) { var entity = _context.Locations.SingleOrDefault(x => x.Id == l.ID); if (entity != null) { entity.Name = l.Name; _context.Entry(entity).State = EntityState.Modified; foreach (KeyValuePair <Domain.Product, int> kv in l.Inventory) { var i = _context.Find <Inventory>(l.ID, kv.Key.ID); if (i.Amount != kv.Value) { i.Amount = kv.Value; _context.Entry(i).State = EntityState.Modified; } } _context.SaveChanges(); } }