Ejemplo n.º 1
0
        public IHttpActionResult Get(ODataQueryOptions <DriveReport> queryOptions, string status = "", int leaderId = 0, bool getReportsWhereSubExists = false)
        {
            IQueryable <DriveReport> queryable = null;

            try
            {
                queryable = GetQueryable(queryOptions);

                ReportStatus reportStatus;
                if (ReportStatus.TryParse(status, true, out reportStatus))
                {
                    if (reportStatus == ReportStatus.Accepted)
                    {
                        // If accepted reports are requested, then return accepted and invoiced.
                        // Invoiced reports are accepted reports that have been processed for payment.
                        // So they are still accepted reports.
                        queryable =
                            queryable.Where(dr => dr.Status == ReportStatus.Accepted || dr.Status == ReportStatus.Invoiced);
                    }
                    else
                    {
                        queryable = queryable.Where(dr => dr.Status == reportStatus);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"{GetType().Name}, Get(), queryOption={queryOptions}, status={status}, leaderId={leaderId}, getReportsWhereSubExists={getReportsWhereSubExists}", ex);
            }
            return(Ok(queryable));
        }
        public IActionResult Get(ODataQueryOptions <DriveReport> queryOptions, string from = "", string status = "", int leaderId = 0, bool getReportsWhereSubExists = false)
        {
            IQueryable <DriveReport> queryable = null;

            try
            {
                queryable = GetQueryable(queryOptions)
                            .Include(r => r.DriveReportPoints)
                            .Include(r => r.PersonReports)
                            .Include(r => r.Employment).ThenInclude(e => e.OrgUnit)
                            .Include(r => r.Person).ThenInclude(p => p.PersonalAddresses)
                            .Include(r => r.ApprovedBy);

                ReportStatus reportStatus;
                if (ReportStatus.TryParse(status, true, out reportStatus))
                {
                    if (reportStatus == ReportStatus.Accepted)
                    {
                        // If accepted reports are requested, then return accepted and invoiced.
                        // Invoiced reports are accepted reports that have been processed for payment.
                        // So they are still accepted reports.
                        queryable =
                            queryable.Where(dr => dr.Status == ReportStatus.Accepted || dr.Status == ReportStatus.APIReady || dr.Status == ReportStatus.APIFetched || dr.Status == ReportStatus.Invoiced);
                    }
                    else
                    {
                        queryable = queryable.Where(dr => dr.Status == reportStatus);
                    }

                    switch (from)
                    {
                    case "approve":
                        queryable = queryable.Where(dr => dr.PersonReports.Any(pr => pr.Person.Id == CurrentUser.Id));
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"{GetType().Name}, Get(), queryOption={queryOptions}, status={status}, leaderId={leaderId}, getReportsWhereSubExists={getReportsWhereSubExists}");
            }
            return(Ok(queryable));
        }
        public IActionResult Get(ODataQueryOptions <VacationReport> queryOptions, string status = "", int leaderId = 0, bool getReportsWhereSubExists = false)
        {
            var queryable = GetQueryable(queryOptions);

            ReportStatus reportStatus;

            if (ReportStatus.TryParse(status, true, out reportStatus))
            {
                if (reportStatus == ReportStatus.Accepted)
                {
                    // If accepted reports are requested, then return accepted and invoiced.
                    // Invoiced reports are accepted reports that have been processed for payment.
                    // So they are still accepted reports.
                    queryable =
                        queryable.Where(dr => dr.Status == ReportStatus.Accepted || dr.Status == ReportStatus.Invoiced);
                }
                else
                {
                    queryable = queryable.Where(dr => dr.Status == reportStatus);
                }
            }
            return(Ok(queryable));
        }