Example #1
0
        public List <ClassifiedModel> AdvancedSearch(SearchClassifiedModel model, int pageSize, int pageNumber, out int totalCount, out int totalPages)
        {
            var list = this._unitOfWork.ClassifiedRepository.FindBy(
                c => (model.AdType == null || c.AdType == model.AdType) &&
                (model.Country == null || c.Country == model.Country) &&
                (model.CategoryId == null || c.SubCategory.CategoryId == model.CategoryId) &&
                (model.City == null || c.City == model.City) &&
                (model.Lang == null || c.SubCategory.Category.Language == model.Lang) &&
                (model.SubCategoryId == null || c.SubCategoryId == model.SubCategoryId) &&
                (model.WithImage == null || (model.WithImage.Value && c.ClassifiedImages.Count > 0) || (!model.WithImage.Value && c.ClassifiedImages.Count == 0)) &&
                (model.MinPrice == null || (c.AdPrice.Value >= model.MinPrice && c.AdPrice.Value <= model.MaxPrice)) &&
                (model.MinPostingDate == null || (c.PostingDate >= model.MinPostingDate && c.PostingDate <= model.MaxPostingDate)) &&
                (model.keyword == null || (c.Title.Contains(model.keyword) || c.Description.Contains(model.keyword))) &&
                c.Status == AdStatusList.Active);

            if (list == null || !list.Any())
            {
                totalCount = 0;
                totalPages = 0;
                return(null);
            }
            totalCount = list.Count();
            totalPages = Convert.ToInt32(Math.Ceiling((double)totalCount / pageSize));

            var models = list.OrderByDescending(c => c.PostingDate).Skip((pageNumber - 1) * pageSize)
                         .Take(pageSize)
                         .ToList();

            if (models.Any())
            {
                return(Mapper.Map <IList <Classified>, IList <ClassifiedModel> >(models).ToList());
            }
            return(null);
        }
Example #2
0
        public IHttpActionResult AdvancedSearchClassifieds([FromBody] SearchClassifiedModel model, int pageSize, int pageNumber)
        {
            int totalCount  = 0;
            int totalPages  = 0;
            var classifieds = _classifiedService.AdvancedSearch(model, pageSize, pageNumber, out totalCount, out totalPages);

            if (classifieds == null)
            {
                throw new HttpResponseException(NotFoundMessage("لا يوجد إعلانات"));
            }
            var result = new
            {
                TotalCount  = totalCount,
                TotalPages  = totalPages,
                Classifieds = classifieds
            };

            return(Ok(result));
        }