private void ClearOldBookingBusByDate(IList <BusByDate> listBusByDate)
 {
     foreach (var busByDate in listBusByDate)
     {
         var listBookingBusByDate = TransferRequestByDateBLL
                                    .BookingBusByDateGetAllByCriterion(busByDate).Future().ToList();
         listBookingBusByDate.ForEach(x =>
         {
             TransferRequestByDateBLL.BookingBusByDateDelete(x);
         });
     }
 }
 public void SaveGroup(Repeater repeater)
 {
     foreach (RepeaterItem repeaterItemBooking in repeater.Items)
     {
         var bookingId    = ((HiddenField)repeaterItemBooking.FindControl("hidBookingId")).Value;
         var bookingIdInt = -1;
         try
         {
             bookingIdInt = Int32.Parse(bookingId);
         }
         catch { }
         var booking = TransferRequestByDateBLL.BookingGetById(bookingIdInt);
         if (booking == null || booking.Id <= 0)
         {
             ShowErrors("Booking doesn't exist. Please try again");
             return;
         }
         var ddlGroup = (DropDownList)repeaterItemBooking.FindControl("ddlGroup");
         var group    = -1;
         try
         {
             group = Int32.Parse(ddlGroup.SelectedValue);
         }
         catch { }
         var listBusByDate = new List <BusByDate>();
         if (group != -1)
         {
             listBusByDate = TransferRequestByDateBLL.BusByDateGetAllByCriterion(Date, BusType, Route, Way, group)
                             .Future().ToList();
         }
         var listBookingBusByDate = TransferRequestByDateBLL.BookingBusByDateGetAllByCriterion(booking)
                                    .Future().ToList()
                                    .Where(x => x.BusByDate.BusType.Id == BusType.Id)
                                    .Where(x => x.BusByDate.Route.Id == Route.Id && x.BusByDate.Route.Way == Way)
                                    .ToList();
         if (listBookingBusByDate == null)
         {
             listBookingBusByDate = new List <BookingBusByDate>();
         }
         for (int i = 0; i < listBusByDate.Count; i++)
         {
             var busByDate        = listBusByDate[i];
             var bookingBusByDate = new BookingBusByDate();
             bookingBusByDate.Booking   = booking;
             bookingBusByDate.BusByDate = busByDate;
             var addMore = true;
             for (int j = i; j < listBookingBusByDate.Count; j++)
             {
                 bookingBusByDate           = listBookingBusByDate[j];
                 bookingBusByDate.Booking   = booking;
                 bookingBusByDate.BusByDate = busByDate;
                 TransferRequestByDateBLL.BookingBusByDateSaveOrUpdate(bookingBusByDate);
                 addMore = false;
             }
             if (addMore)
             {
                 TransferRequestByDateBLL.BookingBusByDateSaveOrUpdate(bookingBusByDate);
             }
         }
         var numberOfBookingBusByDateUnnecessary = listBookingBusByDate.Count - listBusByDate.Count;
         if (numberOfBookingBusByDateUnnecessary > 0)
         {
             for (int i = 0; i < numberOfBookingBusByDateUnnecessary; i++)
             {
                 var bookingBusByDate = listBookingBusByDate.OrderByDescending(x => x.Id).ToList()[i];
                 TransferRequestByDateBLL.BookingBusByDateDelete(bookingBusByDate);
             }
         }
     }
 }
Exemple #3
0
        private void BusByDateCloneForRouteBackNextDay(BusByDate busByDate)
        {
            if (busByDate == null)
            {
                return;
            }
            var route = busByDate.Route;

            if (route.Way != "To")
            {
                return;
            }
            var routeBack = TransferRequestByDateBLL.RouteBackGetByRouteTo(busByDate.Route);
            var date      = busByDate.Date;
            var tomorrow  = date.HasValue ? date.Value.AddDays(1) : date;
            //Tạo bus cho chiều về vào ngày mai nếu được tạo
            BusByDate clonedBusByDateRouteBack = null;

            if (busByDate.Cloned)
            {
                clonedBusByDateRouteBack = busByDate.BusByDateRouteBackRef;
            }
            else
            {
                clonedBusByDateRouteBack = new BusByDate();
            }
            if (clonedBusByDateRouteBack == null)
            {
                return;
            }
            clonedBusByDateRouteBack.BusType = busByDate.BusType;
            clonedBusByDateRouteBack.Date    = tomorrow;
            clonedBusByDateRouteBack.Group   = busByDate.Group;
            clonedBusByDateRouteBack.Guide   = busByDate.Guide;
            clonedBusByDateRouteBack.Route   = routeBack;
            //Xóa hết các liên kết bookingbusbydate cũ của busByDateRouteBack
            var listBookingBusByDate = TransferRequestByDateBLL
                                       .BookingBusByDateGetAllByCriterion(clonedBusByDateRouteBack).Future().ToList();

            listBookingBusByDate.ForEach(x =>
            {
                TransferRequestByDateBLL.BookingBusByDateDelete(x);
            });
            //--
            TransferRequestByDateBLL.BusByDateSaveOrUpdate(clonedBusByDateRouteBack);
            busByDate.BusByDateRouteBackRef = clonedBusByDateRouteBack;
            busByDate.Cloned = true;
            TransferRequestByDateBLL.BusByDateSaveOrUpdate(busByDate);
            //Tìm các booking có chiều về vào ngày mai của bus hôm nay
            var listBookingNeedTransferBackOnTomorrow = busByDate.ListBookingBusByDate
                                                        .Select(x => x.Booking).Where(x => x.Transfer_DateBack == tomorrow).ToList();

            listBookingNeedTransferBackOnTomorrow.ForEach(booking =>
            {
                //Gắn booking chiều về vào bus chiều về
                TransferRequestByDateBLL.BookingBusByDateSaveOrUpdate(new BookingBusByDate()
                {
                    Booking   = booking,
                    BusByDate = clonedBusByDateRouteBack,
                });
                //--
            });
            //--
        }