Esempio n. 1
0
        async Task IConsumer <CreateEvent> .Consume(ConsumeContext <CreateEvent> context)
        {
            var command = context.Message;

            using (var session = await repository.BeginSessionFor(command.EventId, false))
            {
                if (session == null)
                {
                    // throw exception
                }

                if (!session.IsNewState)
                {
                    // throw concurrency exception
                }
                var state = session.GetCurrentState();

                var events = aggregate.CreateEvent(state, command.EventId, command.Title, command.Description);

                session.AddEvents(events);

                await session.SaveChanges();
            }
        }
        async Task IConsumer <UpdateEventTitle> .Consume(ConsumeContext <UpdateEventTitle> context)
        {
            var command = context.Message;

            using (var session = await repository.BeginSessionFor(command.EventId, false))
            {
                if (session == null)
                {
                    throw new Exception();
                }

                if (session.IsNewState)
                {
                    throw new Exception();
                }
                var state = session.GetCurrentState();

                var events = aggregate.ChangeEventTitle(state, command.EventId, command.Title);

                session.AddEvents(events);

                await session.SaveChanges();
            }
        }