Пример #1
0
        public static BusinessEntity From(EntityTestId testId, Version version)
        {
            var bobj      = new BusinessEntity(testId, version);
            var validator = new BusinessEntityValidator();

            bobj.SetValidationResult(validator.Validate(bobj));

            return(bobj);
        }
Пример #2
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);
        }
Пример #3
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);
            }
        }
Пример #4
0
 public static TestAggregateRoot ReconstructFrom(BusinessEntity entity)
 {
     return(new TestAggregateRoot(BusinessEntity.From(entity.BusinessTestId, Version.Next(entity.Version))));
 }
Пример #5
0
 private BusinessEntity(EntityTestId businessTestId, Version version)
 {
     BusinessTestId = businessTestId;
     Version        = version;
 }
 public static TestEntityAggregateUpdatedDomainEvent From(EntityTestId aggregateId, Name name, Version version)
 {
     return(new TestEntityAggregateUpdatedDomainEvent(aggregateId, name, version));
 }
 private TestEntityAggregateUpdatedDomainEvent(EntityTestId aggregateId, Name name, Version version)
     : base(aggregateId, version)
 {
 }
 protected AggregateAddedDomainEvent(TEntityId aggregateId, Version version)
     : base(DateTime.Now, version)
 {
     AggregateId = aggregateId;
 }
 public static TestEntityAggregateAddedDomainEvent From(EntityTestId aggregateId, Name name, Email email, Version version)
 {
     return(new TestEntityAggregateAddedDomainEvent(aggregateId, name, email, version));
 }
 private TestEntityAggregateAddedDomainEvent(EntityTestId aggregateId, Name name, Email email, Version version)
     : base(aggregateId, version)
 {
 }