Example #1
0
        public User UpdateUser(User user)
        {
            _ctx.Attach(user).State = EntityState.Modified;
            _ctx.Entry(user).Reference(u => u.Customer).IsModified = true;
            _ctx.Entry(user).Reference(u => u.Employee).IsModified = true;
            _ctx.SaveChanges();

            return(user);
        }
        public Customer Update(Customer cust)
        {
            _ctx.Attach(cust).State = EntityState.Modified;
            _ctx.Entry(cust).Collection(c => c.Orders).IsModified = true;
            if (cust.Orders == null)
            {
                cust.Orders = new List <Order>();
            }
            var orders = _ctx.Orders.Where(o => o.Customer.ID == cust.ID && !cust.Orders.Exists(co => co.ID == o.ID));

            foreach (var order in orders)
            {
                order.Customer = null;
                _ctx.Entry(order).Reference(o => o.Customer).IsModified = true;
            }

            _ctx.SaveChanges();
            return(cust);
        }
 public Product Update(Product productUpdate)
 {
     _ctx.Attach(productUpdate).State = EntityState.Modified;
     _ctx.SaveChanges();
     return(productUpdate);
 }
Example #4
0
 public Beer Update(Beer beer)
 {
     _ctx.Attach(beer).State = EntityState.Modified;
     _ctx.SaveChanges();
     return(beer);
 }
 public WhiskeyType Update(WhiskeyType whiskeyType)
 {
     _WSctx.Attach(whiskeyType).State = EntityState.Modified;
     _WSctx.SaveChanges();
     return(whiskeyType);
 }