Пример #1
0
        /// <summary>
        /// Search a list of stations based on conditions supplied
        /// </summary>
        /// <param name="searchConditions"></param>
        /// <returns></returns>
        public IEnumerable<Observation> SearchStation(SearchConditions searchConditions)
        {
            if (searchConditions == null) return null;

            Specification<Observation> specification = null;
            if (!string.IsNullOrEmpty(searchConditions.SearchString))
            {
                specification = new StationNameContainsText(searchConditions.SearchString);
            }

            if (searchConditions.FromDate != DateTime.MinValue)
            {
                specification = specification != null ? specification.And(new WeatherDataRecordedFromDate(searchConditions.FromDate)) : new WeatherDataRecordedFromDate(searchConditions.FromDate);
            }

            if (searchConditions.ToDate != DateTime.MinValue)
            {
                specification = specification != null ? specification.And(new WeatherDataRecordedToDate(searchConditions.ToDate)) : new WeatherDataRecordedToDate(searchConditions.ToDate);
            }

            if (specification == null)
            {
                return _repository.GetAll(x => x.StationName);
            }

            return _repository.Get(specification);
        }
Пример #2
0
        public ActionResult SearchStation(SearchPanelViewModel searchCondition)
        {
            if (ModelState.IsValid)
            {
                var searchConditions = new SearchConditions
                    {
                        SearchString = searchCondition.StationName
                    };

                if (searchCondition.FromDate.HasValue)
                {
                    searchConditions.FromDate = searchCondition.FromDate.Value;
                }

                if (searchCondition.ToDate.HasValue)
                {
                    searchConditions.ToDate = searchCondition.ToDate.Value;
                }

                var list = _weatherService.SearchStation(searchConditions).ToList();

                return Json(list);
            }

            return View("Search");
        }