Exemplo n.º 1
0
        public async Task Marry(IJournaledPersonGrain spouse)
        {
            if (State.IsMarried)
            {
                throw new NotSupportedException(string.Format("{0} is already married.", State.LastName));
            }

            var spouseData = await spouse.GetPersonalAttributes();

            var events = new List <IPersonEvent>();

            events.Add(new PersonMarried(spouse.GetPrimaryKey(), spouseData.FirstName, spouseData.LastName));

            if (State.LastName != spouseData.LastName)
            {
                events.Add(new PersonLastNameChanged(spouseData.LastName));
            }

            RaiseEvents(events);

            await ConfirmEvents();
        }
Exemplo n.º 2
0
        public async Task Marry(IJournaledPersonGrain spouse)
        {
            if (State.IsMarried)
            {
                throw new NotSupportedException(string.Format("{0} is already married.", State.LastName));
            }

            var spouseData = await spouse.GetPersonalAttributes();

            await RaiseStateEvent(
                new PersonMarried(spouse.GetPrimaryKey(), spouseData.FirstName, spouseData.LastName),
                commit : false); // We are not storing the first event here

            if (State.LastName != spouseData.LastName)
            {
                await RaiseStateEvent(
                    new PersonLastNameChanged(spouseData.LastName),
                    commit : false);
            }

            // We might need a different, more explicit, persstence API for ES.
            // Reusing the current API for now.
            await this.WriteStateAsync();
        }