Ejemplo n.º 1
0
        public void Remove(User entity)
        {
            var oldState = Get(entity.Id);

            if (Version.Next(oldState.Version) > entity.Version)
            {
                throw new DbUpdateConcurrencyException("This version is not the most updated for this object.");
            }

            var entry = entity.ToUserState();

            DbContext.Users.Remove(entry);
        }
Ejemplo n.º 2
0
        // https://docs.microsoft.com/en-us/ef/core/saving/disconnected-entities

        public void Add(User entity)
        {
            var entry = entity.ToUserState();

            var oldState = Get(entity.Id);

            if (oldState.Equals(User.Empty()))
            {
                DbContext.Users.Add(entry);
            }
            else
            {
                if (Version.Next(oldState.Version) > entity.Version)
                {
                    throw new DbUpdateConcurrencyException("This version is not the most updated for this object.");
                }

                DbContext.Entry(oldState).CurrentValues.SetValues(entry);
            }
        }
Ejemplo n.º 3
0
        public static EventStream <TEntityId> AppendStream(EventStream <TEntityId> stream, IImmutableList <IDomainEvent> appendEvents)
        {
            var newStream = stream.Events.AddRange(appendEvents);

            return(From(stream.AggregationId, stream.Name, Version.Next(stream.Version), newStream));
        }
Ejemplo n.º 4
0
 public static TestAggregateRoot ReconstructFrom(BusinessEntity entity)
 {
     return(new TestAggregateRoot(BusinessEntity.From(entity.BusinessTestId, Version.Next(entity.Version))));
 }