示例#1
0
        static void Main(string[] args)
        {
            LeaveContext context = new LeaveContext
            {
                Request = new LeaveRequest
                {
                    Applicant = "张三",
                    Reason    = "世界那么大,我想去看看",
                    LeaveDays = new Random().Next(1, 10)
                }
            };

            HR hR = new HR();

            hR.AddManager(new TL("李四"));
            hR.AddManager(new PM("王五"));
            hR.AddManager(new CTO("赵六"));

            Manager manager = hR.GetManager();

            manager.HandleRequest(context);
            if (context.Response == null)
            {
                Console.WriteLine($"{context.Request.LeaveDays}天假期太长,没人处理请假申请,请假失败");
            }
            else
            {
                Console.WriteLine($"{context.Response.Approver}审批了{context.Request.Applicant}的{context.Request.LeaveDays}天请假申请");
            }
        }
示例#2
0
 protected override void Handle(LeaveContext context)
 {
     context.Response = new LeaveResponse
     {
         Approver = "TL:" + Name,
         IsAgreed = true
     };
 }
示例#3
0
        public void HandleRequest(LeaveContext context)
        {
            if (CanHandle(context))
            {
                Handle(context);
                return;
            }

            NextManager?.HandleRequest(context);
        }
示例#4
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            LeaveRequest leaveRequest = new LeaveRequest()
            {
                EmployeeName = "Kishor",
                LeaveDays    = 10
            };

            ILeaveRequestHandler <LeaveRequest> supervisor = new SupervisorConcreate();
            ILeaveRequestHandler <LeaveRequest> manager    = new ProjectManagerConcreate();
            ILeaveRequestHandler <LeaveRequest> hr         = new HRConcreate();

            LeaveContext leaveContext = new LeaveContext();

            leaveContext
            .Register <LeaveRequest>(supervisor, manager)
            .Register <LeaveRequest>(manager, hr)
            .Register <LeaveRequest>(hr, null)
            .Run <LeaveRequest>(leaveRequest);
        }
示例#5
0
        public string Get(int leaveDays)
        {
            LeaveContext context = new LeaveContext
            {
                Request = new LeaveRequest
                {
                    Applicant = "张三",
                    Reason    = "世界那么大,我想去看看",
                    LeaveDays = leaveDays
                }
            };
            Manager manager = _managerBuilder.Build();

            manager.HandleRequest(context);
            if (context.Response == null)
            {
                return($"{context.Request.LeaveDays}天假期太长,没人处理请假申请,请假失败");
            }
            else
            {
                return($"{context.Response.Approver}审批了{context.Request.Applicant}的{context.Request.LeaveDays}天请假申请");
            }
        }
示例#6
0
 protected abstract void Handle(LeaveContext context);
示例#7
0
 protected abstract bool CanHandle(LeaveContext context);
示例#8
0
 protected override bool CanHandle(LeaveContext context)
 {
     return(context.Request.LeaveDays <= 1);
 }