Exemple #1
0
        public ActionResult <List <ExhibitResponse> > GetHighLightObject()
        {
            var rs = _exhibitService.GetHightLightExhibit();

            return(Ok(rs));
        }
        //dựa vào thời gian user nhập vào để đưa ra list exhibit phù hợp
        public async Task <List <ExhibitResponse> > SuggestExhibitFromDuration(TimeSpan time)
        {
            List <ExhibitResponse> listResponse = new List <ExhibitResponse>();

            TimeSpan duration = new TimeSpan(00, 00, 00);

            if (duration == time)
            {
                listResponse = _exhibitService.GetHightLightExhibit();
                return(listResponse);
            }


            //tạo list chứa event và topic để sort theo rating
            List <SortEventAndTopicRespnse> listEventAndTopic = new List <SortEventAndTopicRespnse>();

            //lấy ra list topic
            var listTopic = _unitOfWork.Repository <Topic>().GetAll().Where(t => t.Status == (int)TopicStatus.Status.Active &&
                                                                            DateTime.Now >= t.StartDate).ToList();

            if (listTopic.Count() > 0)
            {
                foreach (var item in listTopic)
                {
                    SortEventAndTopicRespnse sortEventAndTopicRespnse = new SortEventAndTopicRespnse()
                    {
                        Id     = item.Id,
                        Rating = (double)item.Rating,
                        RoomId = (int)item.RoomId,
                        Type   = "Topic"
                    };
                    listEventAndTopic.Add(sortEventAndTopicRespnse);
                }
            }

            //lấy ra list event
            var listEvent = _unitOfWork.Repository <Event>().GetAll().Where(e => e.Status == (int)EventStatus.Status.Active &&
                                                                            DateTime.Now >= e.StartDate &&
                                                                            DateTime.Now <= e.EndDate).ToList();

            if (listEvent.Count() > 0)
            {
                foreach (var item in listEvent)
                {
                    SortEventAndTopicRespnse sortEventAndTopicRespnse = new SortEventAndTopicRespnse()
                    {
                        Id     = item.Id,
                        Rating = (double)item.Rating,
                        RoomId = (int)item.RoomId,
                        Type   = "Event"
                    };
                    listEventAndTopic.Add(sortEventAndTopicRespnse);
                }
            }

            //sort list theo rating
            listEventAndTopic = listEventAndTopic.OrderByDescending(sort => sort.Rating).ToList();


            List <int> roomId = new List <int>();

            TimeSpan timeToVisitExhibit = new TimeSpan(00, 00, 00);
            TimeSpan timeToMove         = new TimeSpan(00, 00, 00);

            //ShortestPathAndSuggestRouteService shortestPathAndSuggestRoute = new ShortestPathAndSuggestRouteService(_unitOfWork, _roomService);

            if (listEventAndTopic.Count() > 0)
            {
                foreach (var item in listEventAndTopic)
                {
                    if (item.Type == "Topic")
                    {
                        var exhibitInTopic = _unitOfWork.Repository <ExhibitInTopic>()
                                             .GetAll().Where(e => e.TopicId == item.Id).ToList();

                        roomId.Add(item.RoomId);
                        if (exhibitInTopic.Count() > 0)
                        {
                            foreach (var item2 in exhibitInTopic)
                            {
                                ExhibitResponse exhibitResponse = new ExhibitResponse()
                                {
                                    Id             = item2.Exhibit.Id,
                                    Name           = item2.Exhibit.Name,
                                    Description    = item2.Exhibit.Description,
                                    NameEng        = item2.Exhibit.NameEng,
                                    DescriptionEng = item2.Exhibit.DescriptionEng,
                                    Image          = item2.Exhibit.Image,
                                    Rating         = (double)item2.Topic.Rating,
                                    Duration       = (TimeSpan)item2.Exhibit.Duration
                                };
                                listResponse.Add(exhibitResponse);

                                //xét điều kiện thời gian xem và thời gian di chuyển
                                timeToVisitExhibit = (TimeSpan)(timeToVisitExhibit + item2.Exhibit.Duration);
                                timeToMove         = await _shortestPathAndSuggestRouteService.GetTimeToMoveFromRoom(roomId);

                                duration = timeToMove + timeToVisitExhibit;
                                if (duration >= time)
                                {
                                    return(listResponse);
                                }
                            }
                        }
                    }

                    if (item.Type == "Event")
                    {
                        var exhibitInEvent = _unitOfWork.Repository <ExhibitInEvent>()
                                             .GetAll().Where(e => e.EventId == item.Id).ToList();

                        roomId.Add(item.RoomId);
                        if (exhibitInEvent.Count() > 0)
                        {
                            foreach (var item2 in exhibitInEvent)
                            {
                                ExhibitResponse exhibitResponse = new ExhibitResponse()
                                {
                                    Id             = item2.Exhibit.Id,
                                    Name           = item2.Exhibit.Name,
                                    Description    = item2.Exhibit.Description,
                                    NameEng        = item2.Exhibit.NameEng,
                                    DescriptionEng = item2.Exhibit.DescriptionEng,
                                    Image          = item2.Exhibit.Image,
                                    Rating         = (double)item2.Event.Rating,
                                    Duration       = (TimeSpan)item2.Exhibit.Duration
                                };
                                listResponse.Add(exhibitResponse);
                                //xét điều kiện thời gian xem và thời gian di chuyển
                                timeToVisitExhibit = (TimeSpan)(timeToVisitExhibit + item2.Exhibit.Duration);
                                timeToMove         = await _shortestPathAndSuggestRouteService.GetTimeToMoveFromRoom(roomId);

                                duration = timeToMove + timeToVisitExhibit;
                                if (duration >= time)
                                {
                                    return(listResponse);
                                }
                            }
                        }
                    }
                }
            }
            return(listResponse);
        }