Exemplo n.º 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));
        }
Exemplo n.º 2
0
        private IEnumerable <ThreadModel> GetThreads(List <string> keywords, string searchOptions, string sortingOptions)
        {
            var threads = _threadService.GetAll().Where(thread => thread.AlbumId == 1).Where(thread => thread.Flagged == false);

            if (searchOptions.Equals("Keywords"))
            {
                foreach (var keyword in keywords) //Performs one step lookup further into the search. If the next keyword lookup produces an empty result, then skip it
                {
                    var oneStepLookup = threads.Where(thread => StringContains(thread.Title, keyword) || StringContains(thread.Description, keyword));
                    if (oneStepLookup.FirstOrDefault() != null)
                    {
                        threads = oneStepLookup;
                    }
                }
            }
            else if (searchOptions.Equals("Tags"))
            {
                var tags = _channelService.GetAllTags();
                foreach (var keyword in keywords)
                {
                    var oneStepLookup = tags
                                        .Where(tag => StringContains(tag.Name, keyword))
                                        .Where(tag => tag.ThreadId != 0);
                    if (oneStepLookup.FirstOrDefault() != null)
                    {
                        tags = oneStepLookup;
                    }
                }
                if (tags.Select(tag => _threadService.GetById(tag.ThreadId)).FirstOrDefault() != null)
                {
                    threads = tags.Select(tag => _threadService.GetById(tag.ThreadId)).Distinct();
                }
            }
            if (sortingOptions.Equals("Votes"))
            {
                threads = threads.OrderByDescending(thread => thread.Votes);
            }
            else
            {
                threads = threads.OrderByDescending(thread => thread.CreateDate);
            }
            return(threads.Select(thread => new ThreadModel
            {
                Id = thread.ID,
                Title = thread.Title,
                Rating = thread.Votes,
                Description = thread.Description,
                Picture = thread.Image,
                Created = thread.CreateDate
            }));
        }
Exemplo n.º 3
0
        //[HttpGet("{id}")]
        public async Task <IActionResult> AI(int?id)
        {
            var thread = _threadService.GetById(id);

            if (thread == null)
            {
                return(BadRequest());
            }
            string imageUri = thread.Image;

            // Create a client
            ComputerVisionClient client = Authenticate(endpoint, subscriptionKey);

            var r = await _service.AnalyzeImageUrl(client, imageUri);

            _service.Faces(r);
            _service.Objects(r);
            _service.Tags(r);

            var boolHuman = _service.Description(r);

            //return RedirectToAction("Index", "Thread", new { @id = thread.ID });
            return(Json(boolHuman));
        }
Exemplo n.º 4
0
        public ActionResult Index(int threadId)
        {
            var thread = _threadService.GetById(threadId);

            if (thread.Lat == null || thread.Lng == null)
            {
                return(RedirectToAction("Index", "Thread", new { id = threadId }));
            }

            var model = new MapModel
            {
                Lat = thread.Lat,
                Lng = thread.Lng,
                Url = apiUrl + thread.Lat + "N%20" + thread.Lng + "W" + apiKey
            };

            return(View(model));
        }