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());
        }
Ejemplo n.º 2
0
        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));
        }