public void Abschliessen()
        {
            BestellungSpecs.NichtAbgeschlossen
            .And(Specs.Existiert)
            .ThrowDomainErrorIfNotStatisfied(this);

            ArtikelSpecs.Zugeordnet
            .And(ArtikelSpecs.Status(ArtikelStatus.Offen))
            .ForAll()
            .ThrowDomainErrorIfNotStatisfied(this.Artikel);

            var zugeordneteArtikel = (from artikel in this.Artikel
                                      group artikel by artikel.Benutzer
                                      into artikelNachBenutzer
                                      select artikelNachBenutzer).ToArray();

            foreach (var artikelNachBenutzer in zugeordneteArtikel)
            {
                var beschreibung = $"Bestellung bei {this.state.Lieferdienst}";
                var betrag       = artikelNachBenutzer.Sum(a => a.Betrag);
                var datum        = this.state.Datum;
                var e            = new BezahlungAngefordert(artikelNachBenutzer.Key, beschreibung, betrag, datum);
                this.Emit(e);
            }

            if (!zugeordneteArtikel.Any())
            {
                this.Emit(new BestellungAbgeschlossen());
            }
        }
        public void Abbrechen()
        {
            Specs.Existiert.ThrowDomainErrorIfNotStatisfied(this);

            ArtikelSpecs.Status(ArtikelStatus.Offen)
            .ForAll()
            .ThrowDomainErrorIfNotStatisfied(this.Artikel);

            this.Emit(new BestellungAbgebrochen());
        }
        public void ArtikelEntfernen(ArtikelId artikelId)
        {
            Specs.Existiert.ThrowDomainErrorIfNotStatisfied(this);

            var artikel = this.state.GetArtikel(artikelId);

            ArtikelSpecs.Status(ArtikelStatus.Offen)
            .ThrowDomainErrorIfNotStatisfied(artikel);

            this.Emit(new ArtikelEntfernt(artikelId));
        }
        public void ArtikelZuordnen(ArtikelId artikelId, Benutzer benutzer)
        {
            Specs.Existiert.ThrowDomainErrorIfNotStatisfied(this);

            var artikel = this.state.GetArtikel(artikelId);

            ArtikelSpecs.Status(ArtikelStatus.Offen)
            .ThrowDomainErrorIfNotStatisfied(artikel);

            if (artikel.Benutzer != benutzer)
            {
                this.Emit(new ArtikelBenutzerZugeordnet(artikelId, benutzer));
            }
        }
        public void BezahlungAbschliessen(Benutzer benutzer)
        {
            Specs.Existiert.ThrowDomainErrorIfNotStatisfied(this);

            var artikel = this.Artikel.Where(a => a.Benutzer == benutzer);

            ArtikelSpecs.Zugeordnet
            .And(ArtikelSpecs.Status(ArtikelStatus.BezahlungAngefordert))
            .ForAll()
            .ThrowDomainErrorIfNotStatisfied(artikel);

            this.Emit(new BestellungBezahlt(benutzer));

            if (this.Artikel.All(a => a.Status == ArtikelStatus.Bezahlt))
            {
                this.Emit(new BestellungAbgeschlossen());
            }
        }