コード例 #1
0
        public IActionResult AddToSearchHistory(SearchHistoryDTO searchDTO)
        {
            _dataService.SearchDS.AddToSearchHistory(searchDTO.UserId, searchDTO.SearchInput, searchDTO.DateTime);

            var response = " search created succesfully";

            return(CreatedAtRoute(null, response));
        }
コード例 #2
0
        public ICollection <SearchHistoryDTO> GetSearchHistories(int page, int pageSize)
        {
            using (var db = new SovaContext())
            {
                var searchHistories = db.SearchHistory.GroupBy(x => x.SearchContent).Select(g => g.First()).OrderByDescending(x => x.SearchDate)
                                      .Skip(page * pageSize)
                                      .Take(pageSize);
                List <SearchHistoryDTO> SearchHistoriesDTO = new List <SearchHistoryDTO>();

                foreach (var s in searchHistories)
                {
                    var newSearchHistory = new SearchHistoryDTO(s.Id, s.SearchContent, s.SearchDate);
                    SearchHistoriesDTO.Add(newSearchHistory);
                }
                return(SearchHistoriesDTO
                       .ToList());
            }
        }
コード例 #3
0
        public ICollection <SearchHistoryDTO> GetSearchHistories(int page, int pageSize)
        {
            using (var db = new SovaContext())
            {
                var searchHistories = db.SearchHistory.GroupBy(q => q.SearchContent)
                                      .OrderByDescending(gp => gp.Count())
                                      .Take(5)
                                      .Select(g => g.Key).ToList();

                List <SearchHistoryDTO> SearchHistoriesDTO = new List <SearchHistoryDTO>();

                foreach (var s in searchHistories)
                {
                    var newSearchHistory = new SearchHistoryDTO(1, s, DateTime.Now);
                    SearchHistoriesDTO.Add(newSearchHistory);
                }
                return(SearchHistoriesDTO
                       .ToList());
            }
        }
コード例 #4
0
        public SearchHistoryDTO GetLastFiveFilters()
        {
            var lastSearches = UnitOfWork.SearchHistories
                               .Query.Where(sh => sh.UserId == currentUser.Id)
                               .OrderByDescending(sh => sh.SearchDate)
                               .Take(5).ToList();

            var preparedObject = new SearchHistoryDTO
            {
                OverallQuality     = (float)lastSearches.Select(c => c.OverallQuality).Average(),
                OverallConditions  = (float)lastSearches.Select(c => c.OverallConditions).Average(),
                TotalNumberOfRooms = (float)lastSearches.Select(c => c.TotalNumberOfRooms).Average(),
                NumberOfBedrooms   = (float)lastSearches.Select(c => c.NumberOfBedrooms).Average(),
                NumberOfBathrooms  = (float)lastSearches.Select(c => c.NumberOfBathrooms).Average(),
                GarageNumberOfCars = (float)lastSearches.Select(c => c.GarageNumberOfCars).Average(),
                HouseStyleType     = (float)lastSearches.Select(c => c.HouseStyleType).Average(),
                BuildingType       = (float)lastSearches.Select(c => c.BuildingType).Average(),
                ExteriorQuality    = (float)lastSearches.Select(c => c.ExteriorQuality).Average(),
                HeatingQuality     = (float)lastSearches.Select(c => c.HeatingQuality).Average(),
                HasAirConditioning = (float)lastSearches.Select(c => Convert.ToInt32(c.HasAirConditioning)).Average()
            };

            return(preparedObject);
        }