public async Task <IHttpActionResult> GetDailyBookings(CarTeamSearchViewModel SearchModel) { List <CustomerBookingViewModel> data = new List <CustomerBookingViewModel>(); VerityResult result = new VerityResult(); result = JudgeUserIdentifyNameToVerityResult(); if (!result.IsOk) { return(ReturnResponseMessageResult(result, HttpStatusCode.Unauthorized)); } var user = await _authBLL.FindByName(User.Identity.Name); if (user != null) { int?queryGroupId = _usersService.GetGroupId(user.Id); if (queryGroupId.HasValue) { SearchModel.GroupId = queryGroupId.Value; } data = _bookingService.GetCustomerBookingList(SearchModel); } return(new ResponseMessageResult( Request.CreateResponse( HttpStatusCode.OK, data ))); }
/// <summary> /// 取得客戶與預約列表 /// </summary> /// <param name="SearchModel"></param> /// <returns></returns> public List <CustomerBookingViewModel> GetCustomerBookingList(CarTeamSearchViewModel SearchModel) { List <CustomerBookingViewModel> data = new List <CustomerBookingViewModel>(); var query = _passengerDb.Booking.Where(x => x.TaxiCompanyGroupId == SearchModel.GroupId).AsQueryable(); if (SearchModel.BookingDate.HasValue) { DateTime startTime = new DateTime(SearchModel.BookingDate.Value.Date.Year, SearchModel.BookingDate.Value.Date.Month, SearchModel.BookingDate.Value.Date.Day, 0, 0, 0); DateTime endTime = new DateTime(SearchModel.BookingDate.Value.Date.Year, SearchModel.BookingDate.Value.Date.Month, SearchModel.BookingDate.Value.Date.Day, 23, 59, 59); query = query.Where(x => x.BookingDate >= startTime && x.BookingDate <= endTime); } var tempResult = from booking in query join passenger in _passengerDb.AspNetUsers on booking.PassengerId equals passenger.Id join extendBarrier in _passengerDb.UserExtendBarriers on passenger.Id equals extendBarrier.UserId select new CustomerBookingViewModel { BookingId = booking.BookingId, BookingDate = booking.BookingDate, PassengerId = booking.PassengerId, RealName = passenger.RealName, PhoneNumber = passenger.PhoneNumber, BarriersLevel = extendBarrier.BarriersLevel, Wheelchair = extendBarrier.Wheelchair, Start_Address = booking.Start_Address, Target_Address = booking.Target_Address, IsCancel = booking.IsCancel, DriverId = booking.DriverId }; if (tempResult.Any()) { var finalResult = tempResult.ToList(); foreach (var item in finalResult) { var queryDriver = _TMSDb.Driver.Where(x => x.DriverId == item.DriverId); if (queryDriver.Any()) { item.DriverName = queryDriver.First().DriverName; } var queryTaxi = from main in _TMSDb.TaxiDriver.Where(x => x.DriverId == item.DriverId) join taxi in _TMSDb.Taxi on main.TaxiId equals taxi.TaxiId select taxi; if (queryTaxi.Any()) { item.TaxiCallNo = queryTaxi.First().TaxiCallNo; } } data = finalResult; } return(data); }