示例#1
0
        public BaseResponse <PagedList <HotelViewModel> > Search(HotelSearchModel searchModel)
        {
            try
            {
                var merchantFid = Decrypt.ToInt32(searchModel.MerchantFid);
                if (searchModel != null)
                {
                    var pageIndex  = searchModel.PageIndex > 0 ? searchModel.PageIndex : 1;
                    var pageSize   = searchModel.PageSize > 0 ? searchModel.PageSize : 10;
                    var sortColumn = !string.IsNullOrEmpty(searchModel.SortColumn) ? searchModel.SortColumn : "HotelName";
                    var sortType   = !string.IsNullOrEmpty(searchModel.SortType) ? searchModel.SortType : "ASC";
                    var sortString = !string.IsNullOrEmpty(searchModel.SortString) ? searchModel.SortString : "HotelName DESC";
                    var query      = _dbContext.Hotels.AsNoTracking()
                                     .Where(x => x.Deleted != true &&
                                            (x.HotelName.Contains(searchModel.HotelName) || string.IsNullOrEmpty(searchModel.HotelName)) &&
                                            (x.MerchantFid == int.Parse(searchModel.MerchantFid) || x.MerchantFid == 0) &&
                                            (x.ActiveForOperation == searchModel.ActiveForOperation))
                                     .Select(x => _mapper.Map <Hotels, HotelViewModel>(x)).OrderBy(sortString).ToList();

                    query.ForEach(x => x.hotelInforLst       = _dbContext.HotelInformations.AsNoTracking().Where(y => y.Deleted != true && y.HotelFid == Int32.Parse(x.Id)).Select(y => _mapper.Map <HotelInformations, HotelInformationViewModel>(y)).ToList());
                    query.ForEach(x => x.hotelReservationLst = _dbContext.HotelReservations.AsNoTracking().Where(y => y.HotelFid == Int32.Parse(x.Id)).Select(y => _mapper.Map <HotelReservations, HotelReservationViewModel>(y)).ToList());
                    if (query.Select(x => x.hotelInforLst).Count() > 0 && query.Select(x => x.hotelReservationLst).Count() > 0)
                    {
                        query.ForEach(x => x.hotelInforLst.ForEach(z => z.hotelInforDetailLst       = _dbContext.HotelInformationDetails.AsNoTracking().Where(y => y.Deleted != true && y.InformationFid == z.Id).Select(y => _mapper.Map <HotelInformationDetails, HotelInformationDetailViewModel>(y)).ToList()));
                        query.ForEach(x => x.hotelReservationLst.ForEach(z => z.hotelReserDetailLst = _dbContext.HotelReservationDetails.AsNoTracking().Where(y => y.ReservationsFid == z.Id).Select(y => _mapper.Map <HotelReservationDetails, HotelReservationDetailViewModel>(y)).ToList()));
                    }
                    return(BaseResponse <PagedList <HotelViewModel> > .Success(new PagedList <HotelViewModel>(query.AsQueryable(), searchModel.PageIndex, searchModel.PageSize)));
                }
                return(BaseResponse <PagedList <HotelViewModel> > .NotFound());
            }
            catch (Exception ex)
            {
                return(BaseResponse <PagedList <HotelViewModel> > .InternalServerError(ex));
            }
        }
示例#2
0
        public BaseResponse <PagedList <HotelViewModel> > Search(HotelSearchModel model)
        {
            try
            {
                if (model != null)
                {
                    //Filter values
                    var merchantFid = Decrypt.DecryptToInt32(model.MerchantFid);

                    //Paging values
                    var pageIndex  = model.PageIndex > 0 ? model.PageIndex : 1;
                    var pageSize   = model.PageSize > 0 ? model.PageSize : 10;
                    var sortColumn = (!string.IsNullOrEmpty(model.SortColumn)) ? model.SortColumn : "HotelName";
                    var sortType   = !string.IsNullOrEmpty(model.SortType) ? model.SortType : "ASC";
                    var sortString = $"{sortColumn} {sortType}";

                    //Query data
                    var query = _db.Hotels.Include(k => k.Inventories)
                                .AsNoTracking()
                                .Where(k => !k.Deleted)
                                .Where(k => merchantFid != 0 && k.MerchantFid == merchantFid)
                                .Where(k => string.IsNullOrEmpty(model.HotelName) || k.HotelName.Contains(model.HotelName))
                                .Where(k => !model.ActiveForOperation.HasValue || k.ActiveForOperation == model.ActiveForOperation)
                                .Select(k => _mapper.Map <Hotels, HotelViewModel>(k))
                                .OrderBy(sortString);

                    var result = new PagedList <HotelViewModel>(query, pageIndex, pageSize);
                    return(BaseResponse <PagedList <HotelViewModel> > .Success(result));
                }
                return(BaseResponse <PagedList <HotelViewModel> > .BadRequest());
            }
            catch (Exception ex)
            {
                return(BaseResponse <PagedList <HotelViewModel> > .InternalServerError(ex));
            }
        }
示例#3
0
        public IActionResult Search(HotelSearchModel searchModel)
        {
            var res = _hotelService.Search(searchModel);

            return(Ok(res));
        }
示例#4
0
        public IActionResult Search([FromBody] HotelSearchModel model)
        {
            var response = _hotelService.Search(model);

            return(Ok(response));
        }