Example #1
0
        public async Task <Result <PaginatedList <NationalSocietyReportListResponseDto> > > List(int nationalSocietyId, int pageNumber, NationalSocietyReportListFilterRequestDto filter)
        {
            var userApplicationLanguageCode = await _userService.GetUserApplicationLanguageCode(_authorizationService.GetCurrentUserName());

            var supervisorProjectIds = await _projectService.GetSupervisorProjectIds(_authorizationService.GetCurrentUserName());

            var rowsPerPage = _config.PaginationRowsPerPage;

            var baseQuery = _nyssContext.RawReports
                            .Where(r => r.NationalSociety.Id == nationalSocietyId)
                            .Where(r => r.IsTraining == null || r.IsTraining == false)
                            .Where(r =>
                                   filter.ReportsType == NationalSocietyReportListType.FromDcp ? r.DataCollector.DataCollectorType == DataCollectorType.CollectionPoint :
                                   filter.ReportsType == NationalSocietyReportListType.Main ? r.DataCollector.DataCollectorType == DataCollectorType.Human :
                                   r.DataCollector == null)
                            .Where(r => filter.HealthRiskId == null || r.Report.ProjectHealthRisk.HealthRiskId == filter.HealthRiskId)
                            .Where(r => filter.Status
                    ? r.Report != null && !r.Report.MarkedAsError
                    : r.Report == null || (r.Report != null && r.Report.MarkedAsError))
                            .FilterByArea(MapToArea(filter.Area));

            if (_authorizationService.IsCurrentUserInRole(Role.Supervisor))
            {
                baseQuery = baseQuery
                            .Where(r => r.DataCollector == null || supervisorProjectIds == null || supervisorProjectIds.Contains(r.DataCollector.Project.Id));
            }

            var result = await baseQuery.Select(r => new NationalSocietyReportListResponseDto
            {
                Id              = r.Id,
                DateTime        = r.ReceivedAt,
                HealthRiskName  = r.Report.ProjectHealthRisk.HealthRisk.LanguageContents.Where(lc => lc.ContentLanguage.LanguageCode == userApplicationLanguageCode).Select(lc => lc.Name).Single(),
                IsValid         = r.Report != null,
                IsMarkedAsError = r.Report.MarkedAsError,
                ProjectName     = r.Report != null
                        ? r.Report.ProjectHealthRisk.Project.Name
                        : r.DataCollector.Project.Name,
                ProjectTimeZone = r.Report != null
                        ? r.Report.ProjectHealthRisk.Project.TimeZone
                        : r.DataCollector.Project.TimeZone,
                Region   = r.Village.District.Region.Name,
                District = r.Village.District.Name,
                Village  = r.Village.Name,
                Zone     = r.Zone.Name,
                DataCollectorDisplayName = r.DataCollector.DataCollectorType == DataCollectorType.CollectionPoint
                        ? r.DataCollector.Name
                        : r.DataCollector.DisplayName,
                PhoneNumber             = r.Sender,
                Message                 = r.Text,
                CountMalesBelowFive     = r.Report.ReportedCase.CountMalesBelowFive,
                CountMalesAtLeastFive   = r.Report.ReportedCase.CountMalesAtLeastFive,
                CountFemalesBelowFive   = r.Report.ReportedCase.CountFemalesBelowFive,
                CountFemalesAtLeastFive = r.Report.ReportedCase.CountFemalesAtLeastFive,
                ReferredCount           = r.Report.DataCollectionPointCase.ReferredCount,
                DeathCount              = r.Report.DataCollectionPointCase.DeathCount,
                FromOtherVillagesCount  = r.Report.DataCollectionPointCase.FromOtherVillagesCount
            })
                         //ToDo: order base on filter.OrderBy property
                         .OrderBy(r => r.DateTime, filter.SortAscending)
                         .Page(pageNumber, rowsPerPage)
                         .ToListAsync();

            foreach (var report in result.Where(r => r.ProjectTimeZone != null))
            {
                report.DateTime = TimeZoneInfo.ConvertTimeFromUtc(report.DateTime, TimeZoneInfo.FindSystemTimeZoneById(report.ProjectTimeZone));
            }

            return(Success(result.AsPaginatedList(pageNumber, await baseQuery.CountAsync(), rowsPerPage)));
        }
Example #2
0
 List(int nationalSocietyId, int pageNumber, [FromBody] NationalSocietyReportListFilterRequestDto filterRequest) =>
 await _nationalSocietyReportService.List(nationalSocietyId, pageNumber, filterRequest);