public async Task <ApiResponse <UserActivityDto> > GetUserActivities(ReportGeneratorRequest request)
        {
            try
            {
                var nw = new NameValueCollection()
                {
                    { nameof(ReportGeneratorRequest.ProjectId), request.ProjectId.ToString() },
                    { nameof(ReportGeneratorRequest.UserId), request.UserId.ToString() },
                };
                _provider.SetBearerAuthorization(await _httpContextAccessor.HttpContext.GetTokenAsync("access_token"));

                var response = await _provider.GetAsync(_settings.Url + Routes.UserActivities + nw.ToQueryString());

                response.EnsureSuccessStatusCode();

                var activities = await response.Content.ReadAsAsync <ApiResponse <UserActivityDto> >();

                return(activities);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "An error occured while fetching user {0} activities {1}",
                                 request.UserId, request.ProjectId);
                return(ApiResponse <UserActivityDto> .InternalError());
            }
        }
        public async Task <ApiResponse <ReportExporterResponse> > GenerateReportAsync(
            ReportConfiguration reportConfiguration)
        {
            try
            {
                var reportGeneratorRequest = new ReportGeneratorRequest()
                {
                    ProjectId = reportConfiguration.ProjectId,
                    UserId    = reportConfiguration.UserId,
                };
                var apiResponse = await _workLogClientService.GetUserActivities(reportGeneratorRequest);

                if (!apiResponse.IsSuccess)
                {
                    return(apiResponse.ToFailed <ReportExporterResponse>());
                }

                var reportExportFile =
                    _reportExporter.GenerateReportForExport(apiResponse.Data, reportConfiguration.ReportFormatType);
                return(new ApiResponse <ReportExporterResponse>(reportExportFile));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "");
                return(ApiResponse <ReportExporterResponse> .InternalError());
            }
        }
        public async Task GenerateReport_WhenValidParameters_GeneratesReportAsFile()
        {
            var request = new ReportGeneratorRequest()
            {
                ProjectId = ProjectsDbSet.Get().First().Id,
                UserId    = UsersDbSet.Get().First().Id
            };

            var httpResponse = await GetAsync(ReportControllerRoutes.BaseRoute + "?" + request.ToQueryString());

            httpResponse.EnsureSuccessStatusCode();

            httpResponse.Content.Should().NotBeNull();
        }
        public async Task <ApiResponse <ReportExporterResponse> > GenerateReportAsync(ReportConfiguration reportConfiguration)
        {
            var reportGeneratorRequest = new ReportGeneratorRequest()
            {
                ProjectId = reportConfiguration.ReportParameters.ProjectId,
                UserId    = reportConfiguration.ReportParameters.UserId,
            };
            var apiResponse = await _workLogClientService.GetUserActivities(reportGeneratorRequest);

            if (!apiResponse.IsSuccess)
            {
                return(apiResponse.ToFailed <ReportExporterResponse>());
            }
            var reportExportFile = _reportExporter.GenerateReportForExport(apiResponse.Data, reportConfiguration.ReportFormatType);

            return(new ApiResponse <ReportExporterResponse>(reportExportFile));
        }
Beispiel #5
0
        public async Task <ApiResponse <UserActivityDto> > GetUserActivities(ReportGeneratorRequest request)
        {
            try
            {
                var nw = new NameValueCollection()
                {
                    { nameof(ReportGeneratorRequest.ProjectId), request.ProjectId.ToString() },
                    { nameof(ReportGeneratorRequest.UserId), request.UserId.ToString() },
                };

                var response = await Client.GetAsync(_settings + nw.ToQueryString());

                response.EnsureSuccessStatusCode();

                var activities = response.Content.ReadAsAsync <ApiResponse <UserActivityDto> >().Result;
                return(activities);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "An error occured while fetching user {0} activities {1}",
                                 request.UserId, request.ProjectId);
                return(ApiResponse <UserActivityDto> .InternalError());
            }
        }