public static void Main()
public DataSourceResult GetKendoForApi(DataSourceRequest request, List<int> insuranceCompanyIds, string reportType)
Expression<Func<Job, bool>> expression;
if (reportType == "Premium")
expression = x => insuranceCompanyIds.Contains(x.InsuranceCompanyId.Value) && x.CurrentStage >= Stage.PremiumRequested && x.CurrentStage < Stage.PolicyRequested;
else if (reportType == "Policy")
expression = x => insuranceCompanyIds.Contains(x.InsuranceCompanyId.Value) && x.CurrentStage >= Stage.PolicyRequested && x.CurrentStage < Stage.EndorsementRequested;
else if (reportType == "Endorsement")
expression = x => insuranceCompanyIds.Contains(x.InsuranceCompanyId.Value) && x.CurrentStage >= Stage.EndorsementRequested && x.CurrentStage < Stage.WaitingApprovement;
else if (reportType == "Document")
expression = x => insuranceCompanyIds.Contains(x.InsuranceCompanyId.Value) && x.CurrentStage >= Stage.WaitingApprovement && x.CurrentStage <= Stage.ApprovementRejected;
expression = x => true && insuranceCompanyIds.Contains(x.InsuranceCompanyId.Value);
var context = _unitOfWork.Context;
return _unitOfWork.Repository<Job>()
.FindForKendo(expression,
CurrentStage = x.CurrentStage,
InsuranceCompanyId = x.InsuranceCompanyId,
InsuranceCompanyName = x.InsuranceCompany.Name,
ProductName = x.Product.Name,
CreateDate = x.Actions.FirstOrDefault().CreateDate,
LastActionDate = x.Actions.OrderByDescending(o => o.CreateDate).FirstOrDefault().CreateDate,
ParentAgentName = x.Actions.FirstOrDefault().Agent.ParentId == null ? x.Actions.FirstOrDefault().Agent.AgentName : context.Agents.FirstOrDefault(y => y.Id == x.Actions.FirstOrDefault().Agent.ParentId).AgentName,
AgentName = context.Agents.FirstOrDefault(z => z.Id == x.Actions.FirstOrDefault().AgentId).AgentName,
ProposalId = x.Actions.OrderByDescending(o => o.Id).FirstOrDefault().ProposalId,
PlatformProposalId = x.Actions.OrderByDescending(o => o.Id).FirstOrDefault(p => !string.IsNullOrEmpty(p.PlatformProposalId)).PlatformProposalId,
PolicyId = string.IsNullOrEmpty(x.Actions.OrderByDescending(o => o.Id).SelectMany(y => y.Proposal.Policies).FirstOrDefault().PolicyId) ?
GatewayHelper.GetRequestDetailForString(x.Actions.OrderByDescending(o => o.Id).FirstOrDefault(f => f.JobActionType == Stage.EndorsementRequested).RequestDetails, GatewayKey.PoliceNo) :
(string.IsNullOrEmpty(x.Actions.OrderByDescending(o => o.Id).SelectMany(y => y.Proposal.Policies).FirstOrDefault().PolicyId) ? null : x.Actions.OrderByDescending(o => o.Id).SelectMany(y => y.Proposal.Policies).FirstOrDefault().PolicyId),
PolicyOwner = x.Actions.FirstOrDefault().ProposalId != null && x.Actions.FirstOrDefault().Proposal.Policies.Any(z => insuranceCompanyIds.Contains(z.InsuranceCompanyId)),
FullName = x.Owner.FullName,
Order = x.CurrentStage == Stage.PremiumRequested ||
x.CurrentStage == Stage.PremiumReviseRequested ||
x.CurrentStage == Stage.PolicyRequested ||
x.CurrentStage == Stage.EndorsementRequested ||
x.CurrentStage == Stage.WaitingApprovement
ActionPermission = x.OwnerId == _userId || _userRoles.Any(r => r == Constants.Authorization.CompanyAdminRoleName)