Esempio n. 1
0
        public async Task <IActionResult> GetTaxis(int hotelId, [FromQuery] TaxiParam taxiParam)
        {
            var taxis = await _repo.GetTaxis(taxiParam, hotelId);

            var taxisToReturn = _mapper.Map <IEnumerable <TaxiForListDto> >(taxis);

            Response.AddPagination(taxis.CurrentPage, taxis.PageSize, taxis.TotalCount, taxis.TotalPages);

            return(Ok(taxisToReturn));
        }
Esempio n. 2
0
        public async Task <PagedList <Taxi> > GetTaxis(TaxiParam taxiParam, int HotelID)
        {
            var taxis = _context.Taxis.Where(h => h.HotelId == HotelID && h.IsDeleted == false)
                        .OrderBy(b => b.Id).AsQueryable();

            if (!taxiParam.All)
            {
                if (!string.IsNullOrEmpty(taxiParam.Status))
                {
                    if (taxiParam.Status == "Pending,Processing")
                    {
                        taxis = taxis.Where(b => b.BookStatus == "Pending" || b.BookStatus == "Processing");
                    }
                    else
                    {
                        taxis = taxis.Where(b => b.BookStatus == taxiParam.Status);
                    }
                }
                if (!string.IsNullOrEmpty(taxiParam.RoomNumber))
                {
                    taxis = taxis.Where(b => b.RoomNumber == taxiParam.RoomNumber);
                }

                if (!string.IsNullOrEmpty(taxiParam.Fullname))
                {
                    taxis = taxis.Where(b => b.GuestName.Contains(taxiParam.Fullname));
                }

                if (!string.IsNullOrEmpty(taxiParam.Email))
                {
                    taxis = taxis.Where(b => b.Email.Contains(taxiParam.Email));
                }

                if (!string.IsNullOrEmpty(taxiParam.Phone))
                {
                    taxis = taxis.Where(b => b.Phone.Contains(taxiParam.Phone));
                }

                if (!string.IsNullOrEmpty(taxiParam.BookingDate))
                {
                    DateTime dt;
                    if (DateTime.TryParse(taxiParam.BookingDate, out dt))
                    {
                        taxis = taxis.Where(b => DateTime.Parse(b.ResDate).ToShortDateString() == dt.ToShortDateString());
                    }
                }
            }
            else
            {
                taxis = taxis.Where(b => b.CreatedOn > DateTime.Now.AddMonths(-1));
            }

            if (!string.IsNullOrEmpty(taxiParam.OrderBy))
            {
                switch (taxiParam.OrderBy)
                {
                case "Created":
                    taxis = taxis.OrderBy(b => b.CreatedOn);
                    break;

                default:
                    taxis = taxis.OrderBy(b => (DateTime.Parse(b.ResDate + " " + b.ResTime)));
                    break;
                }
            }

            return(await PagedList <Taxi> .CreateAsync(taxis, taxiParam.PageNumber, taxiParam.PageSize));
        }