Esempio n. 1
0
        public void Execute(UpdateGrapeBlend cmd)
        {
            if (cmd.Grapes.Sum(x => x.Percentage.Value) > 1)
            {
                throw DomainError.Because("Grape blends cannot exceed 100% combined");
            }

            if (cmd.Grapes.GroupBy(x => x.GrapeVariety).Any(x => x.Count() > 1))
            {
                throw DomainError.Because("A grape can only appear once in the blend");
            }

            RaiseEvent(new GrapeBlendUpdated(Id, cmd.Grapes));
        }
Esempio n. 2
0
        public async Task <Response> Handle(RenameChampagneCommand cmd)
        {
            var pagne =
                await AggregateRepo.LoadAsync <Domain.Aggregates.Champagne.Champagne>(new AggregateId(cmd.ChampagneId));

            if (pagne == null)
            {
                throw DomainError.Because($"Champagne with Id '{cmd.ChampagneId}' could not be found");
            }

            pagne.Execute(new RenameChampagne(new AggregateId(cmd.ChampagneId), new ChampagneName(cmd.NewName)));

            await AggregateRepo.StoreAsync(pagne);

            return(Response.Success());
        }
Esempio n. 3
0
        public async Task <Response> Handle(UpdateGrapeBlendCommand cmd)
        {
            var pagne =
                await AggregateRepo.LoadAsync <Domain.Aggregates.Champagne.Champagne>(new AggregateId(cmd.ChampagneId));

            if (pagne == null)
            {
                throw DomainError.Because($"Champagne with Id '{cmd.ChampagneId}' could not be found");
            }

            var grapes = cmd.Grapes.Select(x =>
                                           new GrapeBlend(new GrapeBlendPercentage(x.Percentage), new GrapeVariety(x.GrapeVariety)));

            pagne.Execute(new UpdateGrapeBlend(new AggregateId(cmd.ChampagneId), grapes));

            await AggregateRepo.StoreAsync(pagne);

            return(Response.Success());
        }