Exemplo n.º 1
0
        public void Speichern(PizzaEntity pizza)
        {
            using (var ctx = new PizzaContext())
            {
                var entity = ctx.Entry(pizza);
                entity.State = pizza.Id == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;

                ctx.SaveChanges();
            }
        }
Exemplo n.º 2
0
 public List<PizzaEntity> Pizzen()
 {
     using (var ctx = new PizzaContext())
     {
         return ctx.Pizzen.ToList();
     }
 }
Exemplo n.º 3
0
        public void Bestellen(string besteller, List<PizzaEntity> pizzen)
        {
            using (var ctx = new PizzaContext())
            {
                var pizzenById = pizzen.ToLookup(p => p.Id);
                foreach (var pizza in pizzenById)
                {
                    var entity = ctx.Entry(pizza.First());
                    entity.State = System.Data.Entity.EntityState.Unchanged;
                }
                var bestellung = new BestellungEntity
                {
                    Datum = DateTime.Now,
                    Besteller = besteller,
                    Pizzen = new List<BestellungPositionEntity>(pizzen.Select(p => new BestellungPositionEntity { Pizza = pizzenById[p.Id].First() }))
                };

                ctx.Bestellungen.Add(bestellung);
                ctx.SaveChanges();
            }
        }
Exemplo n.º 4
0
 public List<BestellungEntity> Bestellungen(string von)
 {
     using (var ctx = new PizzaContext())
     {
         return ctx.Bestellungen.Include("Pizzen.Pizza").Where(b => b.Besteller == von).ToList();
     }
 }
Exemplo n.º 5
0
 public List<BestellungEntity> AlleBestellungen()
 {
     using (var ctx = new PizzaContext())
     {
         return ctx.Bestellungen.Include("Pizzen.Pizza").ToList();
     }
 }