public MediatorResponse <byte[]> GetUnsuccessfulCandidatesReportBytes( ReportUnsuccessfulCandidatesParameters parameters) { try { var reportResult = _reportingRepo.ReportUnsuccessfulCandidates(parameters.Type, parameters.FromDate.Date, parameters.ToDate.Date, parameters.AgeRange, parameters.ManagedBy, parameters.Region); var headerBuilder = new StringBuilder(); headerBuilder.AppendLine("PROTECT,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"); headerBuilder.AppendLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"); headerBuilder.AppendLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"); headerBuilder.AppendLine("Date,Total_Unsuccessful_Applications,Total_Candidates,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"); headerBuilder.Append(DateTime.Now.ToString("dd/MM/yyy")).Append(","); headerBuilder.Append(reportResult.Count).Append(","); headerBuilder.Append(reportResult.Select(i => i.CandidateId).Distinct().Count()); headerBuilder.AppendLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"); headerBuilder.AppendLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"); var bytes = parameters.IncludeCandidateIds ? GetCsvBytes <ReportUnsuccessfulCandidatesResultItem, ReportUnsuccessfulCandidatesWithIdsResultItemClassMap>( reportResult, headerBuilder.ToString()) : GetCsvBytes <ReportUnsuccessfulCandidatesResultItem, ReportUnsuccessfulCandidatesResultItemClassMap>( reportResult, headerBuilder.ToString()); return(GetMediatorResponse(ReportingMediatorCodes.ReportCodes.Ok, bytes)); } catch (Exception ex) { _logService.Warn(ex); return(GetMediatorResponse(ReportingMediatorCodes.ReportCodes.Error, new byte[0])); } }
public MediatorResponse <ReportUnsuccessfulCandidatesParameters> GetUnsuccessfulCandidatesReportParams() { var result = new ReportUnsuccessfulCandidatesParameters(); try { var localAuthorities = _reportingRepo.LocalAuthorityManagerGroups(); result.ManagedByList = localAuthorities.ToListItemList(); var regions = _reportingRepo.GeoRegionsIncludingAll(); result.RegionList = regions.ToListItemList(); return(GetMediatorResponse(ReportingMediatorCodes.ReportCodes.Ok, result)); } catch (Exception ex) { _logService.Warn(ex); return(GetMediatorResponse(ReportingMediatorCodes.ReportCodes.Error, result)); } }
public ActionResult ValidateUnsuccessfulCandidatesCsv(ReportUnsuccessfulCandidatesParameters parameters) { var validationResponse = _reportingMediator.Validate(parameters); var newParameterSet = _reportingMediator.GetUnsuccessfulCandidatesReportParams(); validationResponse.ViewModel.ManagedByList = newParameterSet.ViewModel.ManagedByList; validationResponse.ViewModel.RegionList = newParameterSet.ViewModel.RegionList; switch (validationResponse.Code) { case ReportingMediatorCodes.ReportCodes.Ok: return(View("UnsuccessfulCandidatesCsv", validationResponse.ViewModel)); case ReportingMediatorCodes.ReportCodes.ValidationError: default: ModelState.Clear(); validationResponse.ValidationResult.AddToModelStateWithSeverity(ModelState, string.Empty); return(View("UnsuccessfulCandidatesCsv", validationResponse.ViewModel)); } }
public ActionResult DownloadUnsuccessfulCandidatesCsv(ReportUnsuccessfulCandidatesParameters parameters) { var response = _reportingMediator.GetUnsuccessfulCandidatesReportBytes(parameters); return(File(response.ViewModel, "text/csv", "UnsuccessfulCandidatesCsv.csv")); }