public ActionResult Warenkorb(FormCollection formCollection)
        {
            Kunde      kunde      = Session["user"] as Kunde;
            Bestellung bestellung = new Bestellung();

            bestellung.KundeId = kunde.Id;
            _db.Bestellungen.Add(bestellung);
            _db.SaveChanges();
            foreach (var item in kunde.Warenkorb.Artikeln)
            {
                ArtikelBestellung artikelBestellung = new ArtikelBestellung
                {
                    ArtikelId    = item.Id,
                    BestellungId = bestellung.Id,
                    KundeId      = kunde.Id
                };
                _db.ArtikelBestellung.Add(artikelBestellung);
                _db.SaveChanges();
                bestellung.Total += item.Preis;
                //bestellung.Artikeln.Add(item);
                RedirectToAction("PutBestellung", "Bestellung", (bestellung.Id, bestellung));
                _db.SaveChanges();
            }

            kunde.Bestellungen.Add(bestellung);
            Session["bestellung"] = bestellung;
            return(RedirectToAction("checkout"));
        }
        private void OnButtonAddArtikel_Click(object sender, EventArgs e)
        {
            var ids    = (from ListViewItem item in listView.Items select((ArtikelBestellung)item.Tag).Artikel.Artikelnummer).ToList();
            var dialog = new ArtikelHinzufuegenView(ids)
            {
                StartPosition = FormStartPosition.CenterScreen
            };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                var artikelBestellung = new ArtikelBestellung(dialog.Artikel)
                {
                    Anzahl = 1
                };

                var listViewItem = CreateLvItemFromArtikelBestellung(artikelBestellung);
                listView.Items.Add(listViewItem);

                var index = listView.Items.IndexOf(listViewItem);
                listView.Items[index].Selected = true;
                listView.Select();

                OnButtonArtikelSpeichern_Click(sender, e);
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ArtikelBestellung artikelBestellung = db.ArtikelBestellung.Find(id);

            db.ArtikelBestellung.Remove(artikelBestellung);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,ArtikelId,BestellungId,KundeId")] ArtikelBestellung artikelBestellung)
 {
     if (ModelState.IsValid)
     {
         db.Entry(artikelBestellung).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(artikelBestellung));
 }
        public ActionResult Create([Bind(Include = "Id,ArtikelId,BestellungId,KundeId")] ArtikelBestellung artikelBestellung)
        {
            if (ModelState.IsValid)
            {
                db.ArtikelBestellung.Add(artikelBestellung);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(artikelBestellung));
        }
        private void FillDetails(ArtikelBestellung artikelBestellung)
        {
            var artikel = artikelBestellung.Artikel;

            Artikelnummer  = artikel.Artikelnummer;
            Bezeichnung    = artikel.Bezeichnung;
            Herstellername = artikel.Herstellername;
            Einzelpreis    = artikel.Einzelpreis;
            Anzahl         = artikelBestellung.Anzahl;
            TotalArtikel   = artikelBestellung.BerechneterPreis;
        }
 private ListViewItem CreateLvItemFromArtikelBestellung(ArtikelBestellung artikelBestellung)
 {
     return(new ListViewItem(new[]
     {
         artikelBestellung.Artikel.Artikelnummer.ToString(),
         artikelBestellung.Artikel.Bezeichnung,
         artikelBestellung.Anzahl.ToString(),
         string.Format("{0:c}", artikelBestellung.BerechneterPreis)
     })
     {
         Tag = artikelBestellung
     });
 }
        // GET: ArtikelBestellung/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ArtikelBestellung artikelBestellung = db.ArtikelBestellung.Find(id);

            if (artikelBestellung == null)
            {
                return(HttpNotFound());
            }
            return(View(artikelBestellung));
        }