public IResult GetApprovalEvents(int approvalId, Guid entityId)
        {
            var result = new Result
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                var approvalEventAndTransactionDetail = new ApprovalEventAndTransactionDetail();
                var data = _approvalRepository.GetApprovalEvents(approvalId);
                if (data.Any())
                {
                    approvalEventAndTransactionDetail.approvalEventViewModel = data.Select(t =>
                    {
                        var eventViewModel = new ApprovalEventViewModel();
                        eventViewModel.MapFromModel(t);
                        if (t.ApprovalActions.Any())
                        {
                            var actionViewModel            = new List <ApprovalActionViewModel>();
                            eventViewModel.ApprovalActions = actionViewModel
                                                             .MapFromModel <ApprovalActions, ApprovalActionViewModel>(t.ApprovalActions.ToList());
                            var users            = _approvalRepository.GetApprovedUsers(t.ApprovalEventId);
                            var userModels       = new List <UserViewModel>();
                            eventViewModel.Users = userModels.MapFromModel <Users, UserViewModel>(users);
                        }
                        return(eventViewModel);
                    }).ToList();
                }

                var userId           = GetUserId();
                var permissibleEvent = 0;
                if (entityId != Guid.Empty)
                {
                    var approvalTransactionViewModel = new ApprovalTransactionViewModel();
                    var approvalTransactionModel     = _approvalRepository.GetApprovalTransactionByEntity(entityId);
                    if (approvalTransactionModel != null)
                    {
                        approvalEventAndTransactionDetail.approvalTransactionViewModel = (ApprovalTransactionViewModel)approvalTransactionViewModel.MapFromModel(approvalTransactionModel);
                    }
                    permissibleEvent = _approvalRepository.GetApprovalEventOrderOfUser(entityId, userId, approvalId);
                }

                if (permissibleEvent > 0 && approvalEventAndTransactionDetail.approvalTransactionViewModel != null)
                {
                    approvalEventAndTransactionDetail.approvalTransactionViewModel.PermissibleEvent = permissibleEvent;
                }

                result.Body = approvalEventAndTransactionDetail;
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                result.Status  = Status.Error;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public IResult GetAllCandidate()
        {
            var result = new Result
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                var allCandidates = _candidateRepository.GetAll();
                var candidateList = allCandidates.Select(candidate =>
                {
                    var openingCandidate   = _candidateRepository.GetOpeningCandidate(candidate.CandidateId);
                    var candidateListModel = new CandidateListModel();
                    if (openingCandidate != null)
                    {
                        candidateListModel.Opening      = openingCandidate.Opening.Title;
                        candidateListModel.ModifiedDate = openingCandidate.Opening.ModifiedDate;
                    }

                    var assignedUsers = _candidateRepository.GetAssignedUsersByID(candidate.CandidateId);
                    candidateListModel.AssignedUsers = assignedUsers.Count;
                    candidateListModel.Documents     = candidate.CandidateDocuments.Count;
                    var approvalTransaction          = _approvalRepository.GetApprovalTransactionByEntity(candidate.CandidateId);
                    candidateListModel.Status        = approvalTransaction == null ? "Created" : approvalTransaction.ApprovalAction.ApprovalActionName;

                    return(candidateListModel.MapFromModel(candidate));
                }).ToList();
                List <CandidateListModel> candidateListViewModel = candidateList.Cast <CandidateListModel>().ToList();
                result.Body = candidateListViewModel.OrderByDescending(x => x.ModifiedDate);
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                result.Status  = Status.Error;
            }
            return(result);
        }