protected override Command CreateDeleteLinksCommand(Person entity, IAuthenticatedUser user, string selector) { switch (selector) { case "UnlinkDependantsFromPerson": return(Command .NonQuery() .Connection(PersonWithSpouseAndDependantsConnectionClass.GetConnectionName()) .StoredProcedure("[PersonBoundedContext].[pPerson_UnlinkDependants]") .ThrowWhenNoRecordIsUpdated(false) .Parameters( p => p.Name("personId").Value(entity.Id) )); case "UnlinkSpouseFromPerson": return(Command .NonQuery() .Connection(PersonWithSpouseAndDependantsConnectionClass.GetConnectionName()) .StoredProcedure("[PersonBoundedContext].[pPerson_UnlinkSpouse]") .ThrowWhenNoRecordIsUpdated(false) .Parameters( p => p.Name("personId").Value(entity.Id) )); default: throw new InvalidOperationException(); } }
public async override Task <IEnumerable <Person> > GetAllAsync() { var result = await Query <Person> .Collection() .Connection(PersonWithSpouseAndDependantsConnectionClass.GetConnectionName()) .StoredProcedure("[PersonBoundedContext].[pPerson_GetAll]") .ExecuteAsync(); return(result.Records); }
protected override Command CreateDeleteCommand(Person entity, IAuthenticatedUser user, string selector) { return(Command .NonQuery() .Connection(PersonWithSpouseAndDependantsConnectionClass.GetConnectionName()) .StoredProcedure("[PersonBoundedContext].[pPerson_Delete]") .Parameters( p => p.Name("personId").Value(entity.Id) )); }
public async override Task <(int, IEnumerable <Person>)> GetAsync(CollectionQueryParameters queryParameters) { var result = await Query <Person> .Collection() .Connection(PersonWithSpouseAndDependantsConnectionClass.GetConnectionName()) .StoredProcedure("[PersonBoundedContext].[pPerson_Get]") .QueryParameters(queryParameters) .Parameters(p => p.Name("count").Count()) .ExecuteAsync(); return(result.Count, result.Records); }
public IEnumerable <Person> GetAllDependantsForPerson(int personId) { var result = Query <Person> .Collection() .Connection(PersonWithSpouseAndDependantsConnectionClass.GetConnectionName()) .StoredProcedure("[PersonBoundedContext].[pPerson_GetAllDependants]") .Parameters( p => p.Name("personId").Value(personId) ) .Execute(); return(result.Records); }
public async override Task <Person> GetByIdAsync(int personId) { var result = await Query <Person> .Single() .Connection(PersonWithSpouseAndDependantsConnectionClass.GetConnectionName()) .StoredProcedure("[PersonBoundedContext].[pPerson_GetById]") .Parameters( p => p.Name("personId").Value(personId) ) .ExecuteAsync(); return(result.Record); }
public Person GetSpouseForPerson(int personId) { var result = Query <Person> .Single() .Connection(PersonWithSpouseAndDependantsConnectionClass.GetConnectionName()) .StoredProcedure("[PersonBoundedContext].[pPerson_GetSpouse]") .Parameters( p => p.Name("personId").Value(personId) ) .Execute(); return(result.Record); }
protected override Command CreateInsertCommand(Person entity, IAuthenticatedUser user, string selector) { if (user != null) { entity.CreatedBy = (int)user.Id; } var command = Query <Person> .Single() .Connection(PersonWithSpouseAndDependantsConnectionClass.GetConnectionName()) .StoredProcedure("[PersonBoundedContext].[pPerson_Insert]") .Parameters( p => p.Name("name").Value(entity.Name), p => p.Name("createdBy").Value(entity.CreatedBy) ) .OnBeforeCommandExecuted(cmd => { var dependencies = Dependencies(); var spouseDependency = (Person)dependencies?.SingleOrDefault(d => d.Selector == "Spouse")?.Entity; if (spouseDependency != null) { entity.MarriedPersonId = spouseDependency.Id; } cmd.Parameters( p => p.Name("marriedPersonId").Value(entity.MarriedPersonId) ); var dependantsDependency = (Person)dependencies?.SingleOrDefault(d => d.Selector == "Dependants")?.Entity; if (dependantsDependency != null) { entity.ProviderPersonId = dependantsDependency.Id; } cmd.Parameters( p => p.Name("providerPersonId").Value(entity.ProviderPersonId) ); }) .RecordInstance(entity) .MapProperties( p => p.Name("Id").Index(0) ); return(command); }
protected override Command CreateUpdateCommand(Person entity, IAuthenticatedUser user, string selector) { if (user != null) { entity.UpdatedBy = (int)user.Id; } return(Command .NonQuery() .Connection(PersonWithSpouseAndDependantsConnectionClass.GetConnectionName()) .StoredProcedure("[PersonBoundedContext].[pPerson_Update]") .Parameters( p => p.Name("name").Value(entity.Name), p => p.Name("updatedBy").Value(entity.UpdatedBy), p => p.Name("providerPersonId").Value(entity.ProviderPersonId) ) .OnBeforeCommandExecuted(cmd => { var dependencies = Dependencies(); cmd.Parameters( p => p.Name("personId").Value(entity.Id) ); var entityForSpouse = (Person)dependencies.SingleOrDefault(d => d.Selector == "Spouse")?.Entity; if (entityForSpouse != null) { entity.MarriedPersonId = entityForSpouse.Id; } cmd.Parameters( p => p.Name("marriedPersonId").Value(entity.MarriedPersonId) ); })); }
public SavePersonCommandAggregate() : base(new DomainFramework.DataAccess.RepositoryContext(PersonWithSpouseAndDependantsConnectionClass.GetConnectionName())) { }
public SavePersonCommandAggregate(SavePersonInputDto person, EntityDependency[] dependencies = null) : base(new DomainFramework.DataAccess.RepositoryContext(PersonWithSpouseAndDependantsConnectionClass.GetConnectionName())) { Initialize(person, dependencies); }