public ICommandHandlerResult Execute(ICommandContext context, ChangeEmployeeOwnerCommand command) { var department = this.departmentRepository.Rebuild(command.DepartmentId); if (department == null) { return(context.CreateResult(CommandHandlerStatus.NotExists)); } var root = context.GetAggregateRoot(command.AggregateId, () => employeeRepository.Rebuild(command.AggregateId)); if (root == null) { return(context.CreateResult(CommandHandlerStatus.NotExists)); } root.ChangeOwner(context, command); if (root.CanNotCommit()) { return(context.CreateResult(CommandHandlerStatus.NothingChanged)); } if (employeeRepository.Change(root) <= 0) { throw new RepositoryExcutingException("执行失败,请稍后再试"); } return(context.CreateResult(CommandHandlerStatus.Success)); }
public void ChangeOwner(IWorkContext context, ChangeEmployeeOwnerCommand command) { //if (command.GroupSort >= current.GroupSort) // throw new DomainException("你当前权限不能分配更高级的权限给别人"); if (command.GroupSort >= GroupSort.Super) { throw new DomainException("你当前权限不能分配更高级的权限给别人"); } this.ApplyEvent(new ChangeEmployeeOwnerEvent() { AggregateId = this.AggregateId, Creator = context.GetWorkerName(), CreateDate = context.WorkTime, Version = this.Version, DepartmentId = command.DepartmentId, GroupSort = command.GroupSort, }); }