Beispiel #1
0
        public async Task SubmitApproval(Leave leave, Approver approver)
        {
            LeaveEvent leaveEvent = null;
            string     eventKey   = string.Empty;

            if (leave.CurrentApprovalInfo.ApprovalType == ApprovalType.REJECT)
            {
                eventKey = DomainEventKeys.LeaveRejectedEventKey;
                leave.Reject(approver);
                leaveEvent = new LeaveEvent(LeaveEventType.REJECT_EVENT, leave);
            }
            else
            {
                if (approver == null)
                {
                    eventKey = DomainEventKeys.LeaveNeedsAgreeEventKey;
                    leave.Approve(approver);
                    leaveEvent = new LeaveEvent(LeaveEventType.AGREE_EVENT, leave);
                }
                else
                {
                    eventKey = DomainEventKeys.LeaveApprovedEventKey;
                    leave.Finish();
                    leaveEvent = new LeaveEvent(LeaveEventType.APPROVED_EVENT, leave);
                }
            }

            leave.AddHistoryApprovalInfo(leave.CurrentApprovalInfo);

            _leaveRepository.Save(_leaveFactory.CreateLeavePO(leave));
            _leaveRepository.SaveEvent(_leaveFactory.CreateLeaveEventPO(leaveEvent));
            var successCount = await _leaveRepository.UnitOfWork.SaveChangesAsync();

            if (successCount > 0)
            {
                _eventPublisher.Publish(eventKey, leaveEvent);
            }
        }