public async Task <IActionResult> ShowReport(int reportId) { var report = _reportService.GetReportById(reportId); var currentUser = await _userManager.GetUserAsync(HttpContext.User); /*I: check if there are any reports - case where yes*/ if (report != null) { var listOfCommentsForReport = _commentService.GetAllCommentsByReportId(reportId); var commentListDto = new List <CommentViewModel>(); foreach (var c in listOfCommentsForReport) { var commentUser = _userManager.FindByIdAsync(c.UserId).Result; var commentDto = new CommentViewModel() { CommentCreateDate = c.CommentCreateDate, CommentText = c.CommentText, CommentOwner = commentUser.UserName, UserId = commentUser.Id, CommentId = c.CommentId //ReportId = c.ReportId, //CommentId = c.CommentId }; commentListDto.Add(commentDto); } string currentUserId; currentUserId = currentUser == null ? "" : currentUser.Id; /*Check if an investigator is assinged to the report*/ if (report.ReportInvestigatorId != null) { var replikes = _likeService.GetAlLikesForReport(reportId).Count; if (replikes != 0) { if (currentUser != null) { var boollike = false; var c = _likeService.GetLikeBasedOnReportIdAndUserId(reportId, currentUserId); if (c != null) { boollike = c.Liked; } var currentReport = new SpecificReportViewModel() { ReportId = report.ReportId, ReportTitle = report.ReportTitle, ReportDescription = report.ReportDescription, HazardTitle = _hazardService.GetHazardTitleById(report.ReportHazardId), PicturePath = report.ReportPicturePath, ReportRegisterTime = report.ReportRegisterTime, ReportLongitude = report.ReportLongitude, ReportLatitude = report.ReportLatitude, ReportCommentList = commentListDto, CurrentUserId = currentUserId, ReporterId = report.ReportReporterId, ReporterName = _userManager.FindByIdAsync(report.ReportReporterId).Result.UserName, ReportStausText = _reportStatus.GetReportStatusById(report.ReportStatus).StatusName, InvestigatorId = report.ReportInvestigatorId, InvestigatorName = _userManager.FindByIdAsync(report.ReportInvestigatorId).Result.UserName, Liked = boollike ? true : false }; return(View(currentReport)); } else { var currentReport = new SpecificReportViewModel() { ReportId = report.ReportId, ReportTitle = report.ReportTitle, ReportDescription = report.ReportDescription, HazardTitle = _hazardService.GetHazardTitleById(report.ReportHazardId), PicturePath = report.ReportPicturePath, ReportRegisterTime = report.ReportRegisterTime, ReportLongitude = report.ReportLongitude, ReportLatitude = report.ReportLatitude, ReportCommentList = commentListDto, CurrentUserId = currentUserId, ReporterId = report.ReportReporterId, ReporterName = _userManager.FindByIdAsync(report.ReportReporterId).Result.UserName, ReportStausText = _reportStatus.GetReportStatusById(report.ReportStatus).StatusName, InvestigatorId = report.ReportInvestigatorId, InvestigatorName = _userManager.FindByIdAsync(report.ReportInvestigatorId).Result.UserName }; return(View(currentReport)); } } else { var currentReport = new SpecificReportViewModel() { ReportId = report.ReportId, ReportTitle = report.ReportTitle, ReportDescription = report.ReportDescription, HazardTitle = _hazardService.GetHazardTitleById(report.ReportHazardId), PicturePath = report.ReportPicturePath, ReportRegisterTime = report.ReportRegisterTime, ReportLongitude = report.ReportLongitude, ReportLatitude = report.ReportLatitude, ReportCommentList = commentListDto, CurrentUserId = currentUserId, ReporterId = report.ReportReporterId, ReporterName = _userManager.FindByIdAsync(report.ReportReporterId).Result.UserName, ReportStausText = _reportStatus.GetReportStatusById(report.ReportStatus).StatusName, InvestigatorId = report.ReportInvestigatorId, InvestigatorName = _userManager.FindByIdAsync(report.ReportInvestigatorId).Result.UserName, //ReportLikes = _likeService.GetAlLikesForReport(reportId).Count, //Liked = _likeService.GetLikeBasedOnReportIdAndUserId(reportId, currentUserId).Liked }; return(View(currentReport)); } } else { var replikes = _likeService.GetAlLikesForReport(reportId).Count; /*I: check if the report has any likes*/ if (replikes != 0) { if (User.Identity.IsAuthenticated) { bool liked = _likeService.CheckIfLikeExists(reportId, currentUserId); var currentReport = new SpecificReportViewModel() { ReportId = report.ReportId, ReportTitle = report.ReportTitle, ReportDescription = report.ReportDescription, HazardTitle = _hazardService.GetHazardTitleById(report.ReportHazardId), PicturePath = report.ReportPicturePath, ReportRegisterTime = report.ReportRegisterTime, ReportLongitude = report.ReportLongitude, ReportLatitude = report.ReportLatitude, ReportCommentList = commentListDto, CurrentUserId = currentUserId, ReporterId = report.ReportReporterId, ReporterName = _userManager.FindByIdAsync(report.ReportReporterId).Result.UserName, ReportStausText = _reportStatus.GetReportStatusById(report.ReportStatus).StatusName, //InvestigatorId = report.ReportInvestigatorId, InvestigatorName = "not assigned yet.", Liked = liked }; return(View(currentReport)); } else { var currentReport = new SpecificReportViewModel() { ReportId = report.ReportId, ReportTitle = report.ReportTitle, ReportDescription = report.ReportDescription, HazardTitle = _hazardService.GetHazardTitleById(report.ReportHazardId), PicturePath = report.ReportPicturePath, ReportRegisterTime = report.ReportRegisterTime, ReportLongitude = report.ReportLongitude, ReportLatitude = report.ReportLatitude, ReportCommentList = commentListDto, CurrentUserId = currentUserId, ReporterId = report.ReportReporterId, ReporterName = _userManager.FindByIdAsync(report.ReportReporterId).Result.UserName, ReportStausText = _reportStatus.GetReportStatusById(report.ReportStatus).StatusName, //InvestigatorId = report.ReportInvestigatorId, InvestigatorName = "not assigned yet.", //Liked = _likeService.GetLikeBasedOnReportIdAndUserId(reportId, currentUserId).Liked }; return(View(currentReport)); } } else { var currentReport = new SpecificReportViewModel() { ReportId = report.ReportId, ReportTitle = report.ReportTitle, ReportDescription = report.ReportDescription, HazardTitle = _hazardService.GetHazardTitleById(report.ReportHazardId), PicturePath = report.ReportPicturePath, ReportRegisterTime = report.ReportRegisterTime, ReportLongitude = report.ReportLongitude, ReportLatitude = report.ReportLatitude, ReportCommentList = commentListDto, CurrentUserId = currentUserId, ReporterId = report.ReportReporterId, ReporterName = _userManager.FindByIdAsync(report.ReportReporterId).Result.UserName, ReportStausText = _reportStatus.GetReportStatusById(report.ReportStatus).StatusName, //InvestigatorId = report.ReportInvestigatorId, InvestigatorName = "not assigned yet.", //ReportLikes = _likeService.GetAlLikesForReport(reportId).Count, //Liked = _likeService.GetLikeBasedOnReportIdAndUserId(reportId, currentUserId).Liked }; return(View(currentReport)); } } } //get report by id then create object and send it to the page return(NotFound()); }