Ejemplo n.º 1
0
        public async Task <IActionResult> GetLuggages(int hotelId, [FromQuery] LuggageParam luggageParam)
        {
            var luggages = await _repo.GetLuggages(luggageParam, hotelId);

            var luggagesToReturn = _mapper.Map <IEnumerable <LuggageForListDto> >(luggages);

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

            return(Ok(luggagesToReturn));
        }
Ejemplo n.º 2
0
        public async Task <PagedList <Luggage> > GetLuggages(LuggageParam luggageParam, int HotelID)
        {
            var luggages = _context.Luggages.Where(h => h.HotelId == HotelID && h.IsDeleted == false)
                           .OrderBy(b => b.Id).AsQueryable();

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

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

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

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

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

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

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

            return(await PagedList <Luggage> .CreateAsync(luggages, luggageParam.PageNumber, luggageParam.PageSize));
        }