public async Task <IActionResult> Index() { var listofReports = _reportService.GetAllReports(); var user = await _userManager.GetUserAsync(HttpContext.User); string currentUserId; currentUserId = user == null ? "" : user.Id; if (listofReports.Count != 0) { var listDto = new List <ReportViewModel>(); foreach (var report in listofReports) { var reportLikes = _likeService.GetAlLikesForReport(report.ReportId).Count; var statusName = _reportStatus.GetReportStatusById(report.ReportStatus).StatusName; var r = new ReportViewModel() { ReportId = report.ReportId, ReportDescription = report.ReportDescription, ReportTitle = report.ReportTitle, PicturePath = report.ReportPicturePath, ReportLatitude = report.ReportLatitude, ReportLongitude = report.ReportLongitude, ReportStausText = statusName, HazardTitle = _hazardService.GetHazardTitleById(report.ReportHazardId), ReportRegisterTime = report.ReportRegisterTime, ReportCommentCount = _commentService.CountCommentsByReportId(report.ReportId), ReporterName = _userManager.FindByIdAsync(report.ReportReporterId).Result.UserName, ReportLikes = reportLikes, CurrentUserId = currentUserId, ReporterId = report.ReportReporterId }; listDto.Add(r); } return(View(listDto)); } return(NotFound()); }
public async Task <IActionResult> Index() { /*I: get all the user with all reports and sort it */ var bestReporters = _fameService.GetBestReporters().OrderByDescending(o => o.ReportsNumber); var bestInvestigators = _fameService.GetBestInvestigators().OrderByDescending(o => o.InvestigationNumber); var reportWithMostComments = _fameService.GetReportWithMostComments().OrderByDescending(o => o.ReportComments); var reportWithMostLikes = _fameService.GetReportWithMostLikes().OrderByDescending(o => o.ReportLikes); var listofReports = _reportService.GetAllReports(); //listofReports.Clear(); //this line is to mimic if there arent any reports in the database. var listOfInvestigations = _investigationService.GetAllInvestigations(); var user = await _userManager.GetUserAsync(HttpContext.User); string currentUserId; currentUserId = user == null ? "" : user.Id; var reportViewModelList = new List <ReportViewModel>(); foreach (var report in listofReports) { var reportLikes = _likeService.GetAlLikesForReport(report.ReportId).Count; var statusName = _reportStatus.GetReportStatusById(report.ReportStatus).StatusName; var r = new ReportViewModel() { ReportId = report.ReportId, ReportDescription = report.ReportDescription, ReportTitle = report.ReportTitle, PicturePath = report.ReportPicturePath, ReportLatitude = report.ReportLatitude, ReportLongitude = report.ReportLongitude, ReportStausText = statusName, HazardTitle = _hazardService.GetHazardTitleById(report.ReportHazardId), ReportRegisterTime = report.ReportRegisterTime, ReportCommentCount = _commentService.CountCommentsByReportId(report.ReportId), ReporterName = _userManager.FindByIdAsync(report.ReportReporterId).Result.UserName, ReportLikes = reportLikes, CurrentUserId = currentUserId, ReporterId = report.ReportReporterId }; reportViewModelList.Add(r); } var homeInvestigationViewModelsList = new List <HomeInvestigationViewModel>(); foreach (var investigation in listOfInvestigations) { var report = _reportService.GetReportById(investigation.ReportId); var i = new HomeInvestigationViewModel() { ReportId = investigation.ReportId, ReporterName = _userManager.FindByIdAsync(report.ReportReporterId).Result.UserName, ReportTitle = report.ReportTitle, ReporterId = report.ReportReporterId, InvestigatorId = investigation.InvestigatorId, InvestigatorName = _userManager.FindByIdAsync(investigation.InvestigatorId).Result.UserName, CurrentUserId = currentUserId, InvestigationDescription = investigation.InvestigationDescription, InvestigationId = investigation.InvestigationId, StatusId = report.ReportStatus, StatusText = _reportStatus.GetReportStatusById(report.ReportStatus).StatusName }; homeInvestigationViewModelsList.Add(i); } var passModel = new HomePageViewModel() { BestInvestigators = bestInvestigators.ToList(), BestReporterViewModels = bestReporters.ToList(), CommentsList = reportWithMostComments.ToList(), LikesList = reportWithMostLikes.ToList(), ReportViewModels = reportViewModelList, HomeInvestigationViewModels = homeInvestigationViewModelsList }; return(View(passModel)); }
public async Task <IActionResult> Index() { //we shall pass a list of reports together with the current user var listOfReports = _reportService.GetAllReports(); var user = await _userManager.GetUserAsync(HttpContext.User); var pendingReports = new List <SpecificReportViewModel>(); var activeReports = new List <SpecificReportViewModel>(); foreach (var r in listOfReports) { /*I: if the report is pending - i.e. in this case an investigator can be assigned to a report ONLY in this case*/ if (r.ReportStatus == 1) { var report = new SpecificReportViewModel() { ReportId = r.ReportId, ReportDescription = r.ReportDescription, ReportTitle = r.ReportTitle, HazardTitle = _hazardService.GetHazardTitleById(r.ReportHazardId), CurrentUserId = user.Id, ReportRegisterTime = r.ReportRegisterTime, ReporterName = _userManager.FindByIdAsync(r.ReportReporterId).Result.UserName, ReporterId = r.ReportReporterId, Status = r.ReportStatus, ReportStausText = _reportStatus.GetReportStatusById(r.ReportStatus).StatusName //InvestigatorId = investigatroId, //InvestigatorName = _userManager.FindByIdAsync(r.ReportInvestigatorId).Result.UserName }; pendingReports.Add(report); } /*I: if the report is not pending i.e. anything else - an investigator is already assigned to the report*/ else { var report = new SpecificReportViewModel() { ReportId = r.ReportId, ReportDescription = r.ReportDescription, ReportTitle = r.ReportTitle, HazardTitle = _hazardService.GetHazardTitleById(r.ReportHazardId), CurrentUserId = user.Id, ReportRegisterTime = r.ReportRegisterTime, ReporterName = _userManager.FindByIdAsync(r.ReportReporterId).Result.UserName, ReporterId = r.ReportReporterId, Status = r.ReportStatus, InvestigatorId = r.ReportInvestigatorId, InvestigatorName = _userManager.FindByIdAsync(r.ReportInvestigatorId).Result.UserName, ReportStausText = _reportStatus.GetReportStatusById(r.ReportStatus).StatusName }; activeReports.Add(report); } } var Dto = new ActiveOrPendingReportsViewModel() { PendingReports = pendingReports, UnderInvestigationReports = activeReports }; return(View(Dto)); }