Beispiel #1
0
        public bool Delete(Customer t)
        {
            using (var db = new EsbjergCityContext())
            {
                var customer  = db.Customers.Include(x => x.Orders.Select(y => y.GiftCards)).FirstOrDefault(x => x.Id == t.Id);
                var orders    = customer.Orders.ToList();
                var giftCards = customer.Orders.SelectMany(x => x.GiftCards).ToList();
                if (giftCards.Count != 0)
                {
                    foreach (var giftCard in giftCards)
                    {
                        db.Entry(giftCard).State = EntityState.Deleted;
                    }
                }
                if (orders.Count != 0)
                {
                    foreach (var order in orders)
                    {
                        db.Entry(order).State = EntityState.Deleted;
                    }
                }

                db.Entry(customer).State = EntityState.Deleted;
                db.SaveChanges();
                return(db.Orders.FirstOrDefault(x => x.Id == t.Id) == null);
            }
        }
Beispiel #2
0
 public bool Delete(Order t)
 {
     using (var db = new EsbjergCityContext())
     {
         var order = db.Orders.Include("GiftCards").FirstOrDefault(x => x.Id == t.Id);
         foreach (var giftcard in order.GiftCards.ToList())
         {
             db.Entry(giftcard).State = EntityState.Deleted;
         }
         db.Entry(order).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
         return(db.Orders.FirstOrDefault(x => x.Id == t.Id) == null);
     }
 }
 public Event Update(Event t)
 {
     using (var db = new EsbjergCityContext())
     {
         db.Entry(t).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(t);
     }
 }
 public bool Delete(Event t)
 {
     using (var db = new EsbjergCityContext())
     {
         db.Entry(t).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
         return(true);
     }
 }
Beispiel #5
0
 public Customer Update(Customer t)
 {
     using (var db = new EsbjergCityContext())
     {
         db.Entry(t).State = EntityState.Modified;
         db.SaveChanges();
         return(t);
     }
 }