Esempio n. 1
0
        public async Task GetStringsResources_WhenThrowsException_ShouldReturnError()
        {
            _nyssBlobProvider.GetStringsResources().Throws(new InvalidOperationException());

            var result = await _stringsResourcesService.GetStringsResources(DefaultLanguageCode);

            result.IsSuccess.ShouldBeFalse();
        }
        public async Task <byte[]> Export(int projectId)
        {
            var userName = _authorizationService.GetCurrentUserName();
            var userApplicationLanguage = _nyssContext.Users.FilterAvailable()
                                          .Where(u => u.EmailAddress == userName)
                                          .Select(u => u.ApplicationLanguage.LanguageCode)
                                          .Single();

            var stringResources = (await _stringsResourcesService.GetStringsResources(userApplicationLanguage)).Value;

            var dataCollectors = await _nyssContext.DataCollectors
                                 .FilterByProject(projectId)
                                 .Where(dc => dc.DeletedAt == null)
                                 .Select(dc => new ExportDataCollectorsResponseDto
            {
                DataCollectorType = dc.DataCollectorType,
                Name                  = dc.Name,
                DisplayName           = dc.DisplayName,
                PhoneNumber           = dc.PhoneNumber,
                AdditionalPhoneNumber = dc.AdditionalPhoneNumber,
                Sex = dc.Sex,
                BirthGroupDecade = dc.BirthGroupDecade,
                Region           = dc.Village.District.Region.Name,
                District         = dc.Village.District.Name,
                Village          = dc.Village.Name,
                Zone             = dc.Zone.Name,
                Latitude         = dc.Location.Y,
                Longitude        = dc.Location.X,
                Supervisor       = dc.Supervisor.Name,
                TrainingStatus   = dc.IsInTrainingMode
                        ? GetStringResource(stringResources, "dataCollectors.export.isInTraining")
                        : GetStringResource(stringResources, "dataCollectors.export.isNotInTraining")
            })
                                 .OrderBy(dc => dc.Name)
                                 .ThenBy(dc => dc.DisplayName)
                                 .ToListAsync();

            return(GetExcelData(dataCollectors, stringResources));
        }
Esempio n. 3
0
 public async Task <Result <IDictionary <string, string> > > GetStrings(string languageCode) =>
 await _inMemoryCache.GetCachedResult(
     $"{nameof(GetStrings)}.{languageCode}",
     TimeSpan.FromMinutes(5),
     () => _stringsResourcesService.GetStringsResources(languageCode));
Esempio n. 4
0
        public async Task <byte[]> GetExcelData(List <IReportListResponseDto> reports)
        {
            var userName = _authorizationService.GetCurrentUserName();
            var userApplicationLanguage = _nyssContext.Users.FilterAvailable()
                                          .Where(u => u.EmailAddress == userName)
                                          .Select(u => u.ApplicationLanguage.LanguageCode)
                                          .Single();

            var stringResources = (await _stringsResourcesService.GetStringsResources(userApplicationLanguage)).Value;

            var columnLabels = new List <string>
            {
                GetStringResource(stringResources, "reports.export.date"),
                GetStringResource(stringResources, "reports.export.time"),
                GetStringResource(stringResources, "reports.list.status"),
                GetStringResource(stringResources, "reports.list.dataCollectorDisplayName"),
                GetStringResource(stringResources, "reports.list.dataCollectorPhoneNumber"),
                GetStringResource(stringResources, "reports.list.region"),
                GetStringResource(stringResources, "reports.list.district"),
                GetStringResource(stringResources, "reports.list.village"),
                GetStringResource(stringResources, "reports.list.zone"),
                GetStringResource(stringResources, "reports.list.healthRisk"),
                GetStringResource(stringResources, "reports.list.malesBelowFive"),
                GetStringResource(stringResources, "reports.list.malesAtLeastFive"),
                GetStringResource(stringResources, "reports.list.femalesBelowFive"),
                GetStringResource(stringResources, "reports.list.femalesAtLeastFive"),
                GetStringResource(stringResources, "reports.export.totalBelowFive"),
                GetStringResource(stringResources, "reports.export.totalAtLeastFive"),
                GetStringResource(stringResources, "reports.export.totalMale"),
                GetStringResource(stringResources, "reports.export.totalFemale"),
                GetStringResource(stringResources, "reports.export.total"),
                GetStringResource(stringResources, "reports.export.location"),
                GetStringResource(stringResources, "reports.export.message"),
                GetStringResource(stringResources, "reports.export.epiYear"),
                GetStringResource(stringResources, "reports.export.epiWeek")
            };

            var reportData = reports.Select(r =>
            {
                var report = (ExportReportListResponseDto)r;
                return(new
                {
                    Date = report.DateTime.ToString("yyyy-MM-dd"),
                    Time = report.DateTime.ToString("HH:mm"),
                    Status = GetReportStatus(report, stringResources),
                    report.DataCollectorDisplayName,
                    report.PhoneNumber,
                    report.Region,
                    report.District,
                    report.Village,
                    report.Zone,
                    report.HealthRiskName,
                    report.CountMalesBelowFive,
                    report.CountMalesAtLeastFive,
                    report.CountFemalesBelowFive,
                    report.CountFemalesAtLeastFive,
                    TotalBelowFive = report.CountFemalesBelowFive + report.CountMalesBelowFive,
                    TotalAtLeastFive = report.CountMalesAtLeastFive + report.CountFemalesAtLeastFive,
                    TotalMale = report.CountMalesAtLeastFive + report.CountMalesBelowFive,
                    TotalFemale = report.CountFemalesAtLeastFive + report.CountFemalesBelowFive,
                    Total = report.CountMalesBelowFive + report.CountMalesAtLeastFive + report.CountFemalesBelowFive + report.CountFemalesAtLeastFive,
                    Location = report.Location != null
                        ? $"{report.Location.Y}/{report.Location.Coordinate.X}"
                        : "",
                    report.Message,
                    EpiYear = report.EpiWeek,
                    EpiWeek = report.EpiYear
                });
            });

            return(_excelExportService.ToCsv(reportData, columnLabels));
        }