Exemple #1
0
        public async override Task <IEnumerable <Person> > GetAllAsync()
        {
            var result = await Query <Person>
                         .Collection()
                         .Connection(PersonWithSpouseConnectionClass.GetConnectionName())
                         .StoredProcedure("[PersonBoundedContext].[pPerson_GetAll]")
                         .ExecuteAsync();

            return(result.Records);
        }
Exemple #2
0
 protected override Command CreateDeleteCommand(Person entity, IAuthenticatedUser user, string selector)
 {
     return(Command
            .NonQuery()
            .Connection(PersonWithSpouseConnectionClass.GetConnectionName())
            .StoredProcedure("[PersonBoundedContext].[pPerson_Delete]")
            .Parameters(
                p => p.Name("personId").Value(entity.Id)
                ));
 }
Exemple #3
0
 protected override Command CreateDeleteLinksCommand(Person entity, IAuthenticatedUser user, string selector)
 {
     return(Command
            .NonQuery()
            .Connection(PersonWithSpouseConnectionClass.GetConnectionName())
            .StoredProcedure("[PersonBoundedContext].[pPerson_UnlinkMarriedTo]")
            .ThrowWhenNoRecordIsUpdated(false)
            .Parameters(
                p => p.Name("personId").Value(entity.Id)
                ));
 }
Exemple #4
0
        public async override Task <(int, IEnumerable <Person>)> GetAsync(CollectionQueryParameters queryParameters)
        {
            var result = await Query <Person>
                         .Collection()
                         .Connection(PersonWithSpouseConnectionClass.GetConnectionName())
                         .StoredProcedure("[PersonBoundedContext].[pPerson_Get]")
                         .QueryParameters(queryParameters)
                         .Parameters(p => p.Name("count").Count())
                         .ExecuteAsync();

            return(result.Count, result.Records);
        }
Exemple #5
0
        public Person GetMarriedToForPerson(int personId)
        {
            var result = Query <Person>
                         .Single()
                         .Connection(PersonWithSpouseConnectionClass.GetConnectionName())
                         .StoredProcedure("[PersonBoundedContext].[pPerson_GetMarriedTo]")
                         .Parameters(
                p => p.Name("personId").Value(personId)
                )
                         .Execute();

            return(result.Record);
        }
Exemple #6
0
        public async override Task <Person> GetByIdAsync(int personId)
        {
            var result = await Query <Person>
                         .Single()
                         .Connection(PersonWithSpouseConnectionClass.GetConnectionName())
                         .StoredProcedure("[PersonBoundedContext].[pPerson_GetById]")
                         .Parameters(
                p => p.Name("personId").Value(personId)
                )
                         .ExecuteAsync();

            return(result.Record);
        }
Exemple #7
0
        protected override Command CreateInsertCommand(Person entity, IAuthenticatedUser user, string selector)
        {
            if (user != null)
            {
                entity.CreatedBy = (int)user.Id;
            }

            var command = Query <Person>
                          .Single()
                          .Connection(PersonWithSpouseConnectionClass.GetConnectionName())
                          .StoredProcedure("[PersonBoundedContext].[pPerson_Insert]")
                          .Parameters(
                p => p.Name("name").Value(entity.Name),
                p => p.Name("gender").Value(entity.Gender),
                p => p.Name("createdBy").Value(entity.CreatedBy)
                )
                          .OnBeforeCommandExecuted(cmd =>
            {
                var dependencies = Dependencies();

                var spouseDependency = (Person)dependencies?.SingleOrDefault()?.Entity;

                if (spouseDependency != null)
                {
                    entity.SpouseId = spouseDependency.Id;
                }

                cmd.Parameters(
                    p => p.Name("spouseId").Value(entity.SpouseId)
                    );
            })
                          .RecordInstance(entity)
                          .MapProperties(
                p => p.Name("Id").Index(0)
                );

            return(command);
        }
Exemple #8
0
        protected override Command CreateUpdateCommand(Person entity, IAuthenticatedUser user, string selector)
        {
            if (user != null)
            {
                entity.UpdatedBy = (int)user.Id;
            }

            return(Command
                   .NonQuery()
                   .Connection(PersonWithSpouseConnectionClass.GetConnectionName())
                   .StoredProcedure("[PersonBoundedContext].[pPerson_Update]")
                   .Parameters(
                       p => p.Name("name").Value(entity.Name),
                       p => p.Name("gender").Value(entity.Gender),
                       p => p.Name("updatedBy").Value(entity.UpdatedBy)
                       )
                   .OnBeforeCommandExecuted(cmd =>
            {
                var dependencies = Dependencies();

                cmd.Parameters(
                    p => p.Name("personId").Value(entity.Id)
                    );

                var entityForMarriedTo = (Person)dependencies.SingleOrDefault(d => d.Selector == "MarriedTo")?.Entity;

                if (entityForMarriedTo != null)
                {
                    entity.SpouseId = entityForMarriedTo.Id;
                }

                cmd.Parameters(
                    p => p.Name("spouseId").Value(entity.SpouseId)
                    );
            }));
        }
Exemple #9
0
 public SavePersonCommandAggregate() : base(new DomainFramework.DataAccess.RepositoryContext(PersonWithSpouseConnectionClass.GetConnectionName()))
 {
 }
Exemple #10
0
 public SavePersonCommandAggregate(PersonInputDto person, EntityDependency[] dependencies = null) : base(new DomainFramework.DataAccess.RepositoryContext(PersonWithSpouseConnectionClass.GetConnectionName()))
 {
     Initialize(person, dependencies);
 }