コード例 #1
0
        //To view ONE thread
        public IActionResult Index(int?id)
        {
            //get the id of the thread
            var thread = _service.GetById(id);

            if (thread == null)
            {
                return(NotFound());                //if the thread number does not exist then not found
            }
            //make a list of users that liked the thread
            var listOfLikes = _service.ListOfLikes(id);
            //get the list of reports
            var numberOfReports = _service.ListOfReports(id).Count();
            var tags            = _service.GetThreadTags(thread);

            //make a view model for the thread
            var model = new ThreadModel
            {
                Id             = thread.ID,
                AuthorId       = thread.UserID,
                AuthorUserName = thread.UserName,
                Created        = thread.CreateDate,
                Description    = thread.Description,
                Picture        = thread.Image,
                Title          = thread.Title,
                Rating         = listOfLikes.Count(),
                LikedBy        = listOfLikes,
                NoReports      = numberOfReports,
                Tags           = tags,
                Lat            = thread.Lat,
                Lng            = thread.Lng
            };

            return(View(model));
        }