Ejemplo n.º 1
0
        public Order UpdateOrder(Order order)
        {
            var newOrderLines = new List <OrderLine>(order.OrderLines);

            _ctx.Attach(order).State = EntityState.Modified;
            _ctx.OrderLines.RemoveRange(_ctx.OrderLines.Where(ol => ol.OrderId == order.Id));

            foreach (var ol in newOrderLines)
            {
                _ctx.Entry(ol).State = EntityState.Added;
            }

            _ctx.Entry(order).Reference(o => o.Customer).IsModified = true;
            _ctx.SaveChanges();
            return(order);
        }
Ejemplo n.º 2
0
        public Manufacturer Update(Manufacturer manufacturer)
        {
            _ctx.Attach(manufacturer).State = EntityState.Modified;
            _ctx.Entry(manufacturer).Collection(m => m.Drones).IsModified = true;

            var drones = _ctx.Drones.Where(d => d.Manufacturer.Id == manufacturer.Id && !manufacturer.Drones.Exists(dm => dm.Id == d.Id));

            foreach (var drone in drones)
            {
                drone.Manufacturer = null;
                _ctx.Entry(drone).Reference(d => d.Manufacturer).IsModified = true;
            }

            _ctx.SaveChanges();
            return(manufacturer);
        }
Ejemplo n.º 3
0
        public Drone Update(Drone droneUpdate)
        {
            _ctx.Attach(droneUpdate).State = EntityState.Modified;

            _ctx.Entry(droneUpdate).Reference(d => d.Manufacturer).IsModified = true;

            _ctx.SaveChanges();

            return(droneUpdate);
        }
Ejemplo n.º 4
0
 public User Update(User user)
 {
     _ctx.Entry(user).State = EntityState.Modified;
     _ctx.SaveChanges();
     return(user);
 }