Exemplo n.º 1
0
        public async Task <ActionResult> GetReportOperationalList([FromBody] ReportRequestDto request)
        {
            int eventUserID = Request.GetUserID();

            SqlParameter[] parameters =
            {
                new SqlParameter("@UserID",    eventUserID),
                new SqlParameter("@StartDate", !(request.StartDate.HasValue) ? DBNull.Value : (object)request.StartDate),
                new SqlParameter("@EndDate",   !(request.EndDate.HasValue) ? DBNull.Value : (object)request.EndDate),
            };

            var response = new ResponseData <ResponseDataList <ReportOperationlDto> >
            {
                IsSuccess = true,
                Code      = Constants.ResponseCode.Success,
                Message   = "Success",
            };

            var query = _context.Query <ReportOperational>().FromSql($"dbo.spGetReportOperational @userID , @startDate, @endDate", parameters);
            var reportOperationals = await query.AsNoTracking().ToArrayAsync();

            response.Data = new ResponseDataList <ReportOperationlDto>
            {
                List = _mapper.Map <IEnumerable <ReportOperationlDto> >(reportOperationals)
            };

            return(Ok(response));
        }
Exemplo n.º 2
0
        public ReportDto CreateReport(int userId, ReportRequestDto request)
        {
            Func <OperationDto, bool> searchPredicate;

            if (request.TimeRange == TimeRangeDto.Day)
            {
                searchPredicate = x => x.OperationDate.Date == request.DateInRange.Date;
            }
            else if (request.TimeRange == TimeRangeDto.Month)
            {
                searchPredicate = x => x.OperationDate.Year == request.DateInRange.Year &&
                                  x.OperationDate.Month == request.DateInRange.Month;
            }
            else if (request.TimeRange == TimeRangeDto.Year)
            {
                searchPredicate = x => x.OperationDate.Year == request.DateInRange.Year;
            }
            else
            {
                searchPredicate = x => DateTime.Compare(x.OperationDate, request.StartingDate) >= 0 &&
                                  DateTime.Compare(x.OperationDate, request.EndingDate) <= 0;
            }

            return(CreateReport(userId, request, searchPredicate));
        }
Exemplo n.º 3
0
        public async Task <Result> Edit(int reportId, ReportRequestDto reportRequestDto)
        {
            var report = await _nyssContext.Reports
                         .Include(r => r.RawReport)
                         .Include(r => r.ProjectHealthRisk)
                         .ThenInclude(phr => phr.Project)
                         .SingleOrDefaultAsync(r => r.Id == reportId);

            if (report == null)
            {
                return(Error <ReportResponseDto>(ResultKey.Report.ReportNotFound));
            }

            if (report.ReportType != ReportType.Aggregate &&
                report.ReportType != ReportType.DataCollectionPoint)
            {
                return(Error <ReportResponseDto>(ResultKey.Report.Edit.HealthRiskCannotBeEdited));
            }

            var projectHealthRisk = await _nyssContext.ProjectHealthRisks
                                    .Include(phr => phr.HealthRisk)
                                    .SingleOrDefaultAsync(phr => phr.HealthRiskId == reportRequestDto.HealthRiskId &&
                                                          phr.HealthRisk.HealthRiskType == HealthRiskType.Human &&
                                                          phr.Project.Id == report.ProjectHealthRisk.Project.Id);

            if (projectHealthRisk == null)
            {
                return(Error <ReportResponseDto>(ResultKey.Report.Edit.HealthRiskNotAssignedToProject));
            }

            var updatedReceivedAt = new DateTime(reportRequestDto.Date.Year, reportRequestDto.Date.Month, reportRequestDto.Date.Day,
                                                 report.ReceivedAt.Hour, report.ReceivedAt.Minute, report.ReceivedAt.Second);

            report.RawReport.ReceivedAt                 = updatedReceivedAt;
            report.ReceivedAt                           = updatedReceivedAt;
            report.ProjectHealthRisk                    = projectHealthRisk;
            report.ReportedCase.CountMalesBelowFive     = reportRequestDto.CountMalesBelowFive;
            report.ReportedCase.CountMalesAtLeastFive   = reportRequestDto.CountMalesAtLeastFive;
            report.ReportedCase.CountFemalesBelowFive   = reportRequestDto.CountFemalesBelowFive;
            report.ReportedCase.CountFemalesAtLeastFive = reportRequestDto.CountFemalesAtLeastFive;

            report.ReportedCaseCount = reportRequestDto.CountMalesBelowFive +
                                       reportRequestDto.CountMalesAtLeastFive +
                                       reportRequestDto.CountFemalesBelowFive +
                                       reportRequestDto.CountFemalesAtLeastFive;

            if (report.ReportType == ReportType.DataCollectionPoint)
            {
                report.DataCollectionPointCase.ReferredCount          = reportRequestDto.ReferredCount;
                report.DataCollectionPointCase.DeathCount             = reportRequestDto.DeathCount;
                report.DataCollectionPointCase.FromOtherVillagesCount = reportRequestDto.FromOtherVillagesCount;
            }

            report.ModifiedAt = _dateTimeProvider.UtcNow;
            report.ModifiedBy = _authorizationService.GetCurrentUserName();

            await _nyssContext.SaveChangesAsync();

            return(SuccessMessage(ResultKey.Report.Edit.EditSuccess));
        }
Exemplo n.º 4
0
 private string GetReportName(TimeRangeDto timeRange, ReportRequestDto request)
 {
     return(timeRange switch
     {
         TimeRangeDto.Day => String.Format(ServiceMessages.DailyReport, request.DateInRange.Date.ToShortDateString()),
         TimeRangeDto.Month => String.Format(ServiceMessages.MonthlyReport, request.DateInRange.Month),
         TimeRangeDto.Year => String.Format(ServiceMessages.YearlyReport, request.DateInRange.Year),
         _ => String.Format(ServiceMessages.CustomReport, request.StartingDate.Date.ToShortDateString(),
                            request.EndingDate.Date.ToShortDateString())
     });
        private TReport GetReport <TReport>(TimeRange timeRange, BaseReportRequest request)
        {
            request.TimeRange = timeRange;
            var test = new ReportRequestDto();

            Mapper.Map(request, test);
            var requestDto = Mapper.Map <ReportRequestDto>(request);

            var reportDto = reportService.CreateReport(GetUserId(), requestDto);

            return(Mapper.Map <TReport>(reportDto));
        }
Exemplo n.º 6
0
        private ReportDto CreateReport(int userId, ReportRequestDto request,
                                       Func <OperationDto, bool> searchPredicate)
        {
            var wallet = VerifyUserWallet(userId, request.WalletId);

            var filteredOperations =
                wallet.Operations.Where(searchPredicate).OrderBy(x => x.OperationDate).ToList();
            var lastOperation = filteredOperations.LastOrDefault();

            return(new ReportDto
            {
                Name = GetReportName(request.TimeRange, request),
                Currency = wallet.Currency,
                OpeningBalance = filteredOperations.FirstOrDefault()?.CurrentBalance,
                EndingBalance = lastOperation?.CurrentBalance + lastOperation?.Amount,
                Income = SumAmount(filteredOperations, x => x.Amount > 0),
                Expense = SumAmount(filteredOperations, x => x.Amount < 0)
            });
        }
Exemplo n.º 7
0
        public IActionResult GetReport([FromBody] ReportRequestDto reportRequest)
        {
            ReportTemplateLoader loader   = new ReportTemplateLoader();
            StiReport            report   = new StiReport();
            IDataProvider        provider = null;

            try
            {
                loader.Load(report, reportRequest.Report);

                if (reportRequest.DataProvider.ToLower() == "xml")
                {
                    provider = new XmlFileDataProvider(reportRequest.Data["filename"].Value <string>());
                    report.RegData(provider.GetData());
                }
                else if (reportRequest.DataProvider.ToLower() == "database")
                {
                    StimulsoftRepository repository     = new StimulsoftRepository();
                    ReportSettings       reportSettings = repository.GetReportSettings(reportRequest.Report);

                    foreach (var tableName in reportSettings.TableNames)
                    {
                        provider = new DatabaseDataProvider(tableName, reportSettings.ConnectionString, reportRequest.Data);
                        report.RegData(provider.GetData());
                    }
                }
                else if (reportRequest.DataProvider.ToLower() == "url")
                {
                    provider = new UrlDataProvider("URL");
                    report.RegData(provider.GetData());
                }

                ExportFormat exporter = new ExportFormat();
                return(exporter.ExportReport(report, reportRequest.Output.ToLower()));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Exemplo n.º 8
0
        public virtual OperationResultWithData <IEnumerable <ACSessionDto> > GetSessionsReport([FromBody] ReportRequestDto request)
        {
            try
            {
                LmsCourseMeeting meeting = LmsCourseMeetingModel.GetOneByCourseAndId(LmsCompany.Id, CourseId, request.MeetingId);
                if (meeting == null)
                {
                    return(OperationResultWithData <IEnumerable <ACSessionDto> > .Error(Messages.MeetingNotFound));
                }

                IEnumerable <ACSessionDto> report = _reportService.GetSessionsReports(
                    meeting.GetMeetingScoId(),
                    GetAdminProvider(),
                    TimeZoneInfo.Utc,
                    request.StartIndex,
                    request.Limit);

                return(report.ToSuccessResult());
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("GetSessionsReport", ex);
                return(OperationResultWithData <IEnumerable <ACSessionDto> > .Error(errorMessage));
            }
        }
Exemplo n.º 9
0
        public virtual OperationResultWithData <IEnumerable <ACSessionParticipantDto> > GetAttendanceReport([FromBody] ReportRequestDto request)
        {
            try
            {
                LmsCourseMeeting meeting = this.LmsCourseMeetingModel.GetOneByCourseAndId(LmsCompany.Id, CourseId, request.MeetingId);
                if (meeting == null)
                {
                    return(OperationResultWithData <IEnumerable <ACSessionParticipantDto> > .Error(Messages.MeetingNotFound));
                }

                IEnumerable <ACSessionParticipantDto> report = _reportService.GetAttendanceReports(
                    meeting.GetMeetingScoId(),
                    this.GetAdminProvider(),
                    TimeZoneInfo.Utc,
                    request.StartIndex,
                    request.Limit);

                // TRICK: check that is not API call.
                if (SessionSave != null)
                {
                    // TRICK: clean not to serialize
                    foreach (var item in report)
                    {
                        item.login       = null;
                        item.principalId = null;
                    }
                }

                return(report.ToSuccessResult());
            }
            catch (Exception ex)
            {
                string errorMessage = GetOutputErrorMessage("GetAttendanceReport", ex);
                return(OperationResultWithData <IEnumerable <ACSessionParticipantDto> > .Error(errorMessage));
            }
        }
        public async Task <IActionResult> Get([FromBody] ReportRequestDto request)
        {
            var res = await _reportRepository.GetAnimalReport(request.AnimalType, request.Year);

            return(Ok(res));
        }
Exemplo n.º 11
0
 public async Task <Result> Edit(int reportId, [FromBody] ReportRequestDto reportRequestDto) =>
 await _reportService.Edit(reportId, reportRequestDto);