Exemple #1
0
        protected override Command CreateDeleteLinksCommand(Person entity, IAuthenticatedUser user, string selector)
        {
            switch (selector)
            {
            case "UnlinkBestFriendOfFromPerson": return(Command
                                                        .NonQuery()
                                                        .Connection(PersonWithSpouseAndBestFriendConnectionClass.GetConnectionName())
                                                        .StoredProcedure("[PersonBoundedContext].[pPerson_UnlinkBestFriendOf]")
                                                        .ThrowWhenNoRecordIsUpdated(false)
                                                        .Parameters(
                                                            p => p.Name("personId").Value(entity.Id)
                                                            ));

            case "UnlinkMarriedToFromPerson": return(Command
                                                     .NonQuery()
                                                     .Connection(PersonWithSpouseAndBestFriendConnectionClass.GetConnectionName())
                                                     .StoredProcedure("[PersonBoundedContext].[pPerson_UnlinkMarriedTo]")
                                                     .ThrowWhenNoRecordIsUpdated(false)
                                                     .Parameters(
                                                         p => p.Name("personId").Value(entity.Id)
                                                         ));

            default: throw new InvalidOperationException();
            }
        }
Exemple #2
0
 protected override Command CreateDeleteCommand(Person entity, IAuthenticatedUser user, string selector)
 {
     return(Command
            .NonQuery()
            .Connection(PersonWithSpouseAndBestFriendConnectionClass.GetConnectionName())
            .StoredProcedure("[PersonBoundedContext].[pPerson_Delete]")
            .Parameters(
                p => p.Name("personId").Value(entity.Id)
                ));
 }
        public async override Task <IEnumerable <Person> > GetAllAsync()
        {
            var result = await Query <Person>
                         .Collection()
                         .Connection(PersonWithSpouseAndBestFriendConnectionClass.GetConnectionName())
                         .StoredProcedure("[PersonBoundedContext].[pPerson_GetAll]")
                         .ExecuteAsync();

            return(result.Records);
        }
        public async override Task <(int, IEnumerable <Person>)> GetAsync(CollectionQueryParameters queryParameters)
        {
            var result = await Query <Person>
                         .Collection()
                         .Connection(PersonWithSpouseAndBestFriendConnectionClass.GetConnectionName())
                         .StoredProcedure("[PersonBoundedContext].[pPerson_Get]")
                         .QueryParameters(queryParameters)
                         .Parameters(p => p.Name("count").Count())
                         .ExecuteAsync();

            return(result.Count, result.Records);
        }
        public Person GetBestFriendOfForPerson(int personId)
        {
            var result = Query <Person>
                         .Single()
                         .Connection(PersonWithSpouseAndBestFriendConnectionClass.GetConnectionName())
                         .StoredProcedure("[PersonBoundedContext].[pPerson_GetBestFriendOf]")
                         .Parameters(
                p => p.Name("personId").Value(personId)
                )
                         .Execute();

            return(result.Record);
        }
        public async override Task <Person> GetByIdAsync(int personId)
        {
            var result = await Query <Person>
                         .Single()
                         .Connection(PersonWithSpouseAndBestFriendConnectionClass.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(PersonWithSpouseAndBestFriendConnectionClass.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 marriedToDependency = (Person)dependencies?.SingleOrDefault(d => d.Selector == "MarriedTo")?.Entity;

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

                cmd.Parameters(
                    p => p.Name("spouseId").Value(entity.SpouseId)
                    );

                var bestFriendOfDependency = (Person)dependencies?.SingleOrDefault(d => d.Selector == "BestFriendOf")?.Entity;

                if (bestFriendOfDependency != null)
                {
                    entity.BestFriendId = bestFriendOfDependency.Id;
                }

                cmd.Parameters(
                    p => p.Name("bestFriendId").Value(entity.BestFriendId)
                    );
            })
                          .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(PersonWithSpouseAndBestFriendConnectionClass.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)
                    );

                var entityForBestFriendOf = (Person)dependencies.SingleOrDefault(d => d.Selector == "BestFriendOf")?.Entity;

                if (entityForBestFriendOf != null)
                {
                    entity.BestFriendId = entityForBestFriendOf.Id;
                }

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