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);
             }
         }
     }
 }
 public void BookingBusByDateDelete(BookingBusByDate bookingBusByDate)
 {
     BookingBusByDateRepository.Delete(bookingBusByDate);
 }
 protected void btnSave_Click(object sender, EventArgs e)
 {
     foreach (RepeaterItem repeaterItemRouteByWay in rptRouteByWay.Items)
     {
         var routeId    = ((HiddenField)repeaterItemRouteByWay.FindControl("hidRouteId")).Value;
         var routeIdInt = -1;
         try
         {
             routeIdInt = Int32.Parse(routeId);
         }
         catch { }
         var route = TransferRequestByDateBLL.RouteGetById(routeIdInt);
         if (route == null || route.Id <= 0)
         {
             ShowErrors("Route doesn't exist. Please try again");
             return;
         }
         var rptBusType = (Repeater)repeaterItemRouteByWay.FindControl("rptBusType");
         foreach (RepeaterItem repeaterItemBusType in rptBusType.Items)
         {
             var busTypeId    = ((HiddenField)repeaterItemBusType.FindControl("hidBusTypeId")).Value;
             var busTypeIdInt = -1;
             try
             {
                 busTypeIdInt = Int32.Parse(busTypeId);
             }
             catch { }
             var busType = TransferRequestByDateBLL.BusTypeGetById(busTypeIdInt);
             if (route == null || route.Id <= 0)
             {
                 ShowErrors("Bus type doesn't exist. Please try again");
                 return;
             }
             var rptTransportBooking = (Repeater)repeaterItemBusType.FindControl("rptTransportBooking");
             //Xóa hết các liên kết BookingBusByDate cũ
             var listBusByDate = TransferRequestByDateBLL.BusByDateGetAllByCriterion(Date, busType, route, route.Way)
                                 .Future().ToList();
             ClearOldBookingBusByDate(listBusByDate);
             //--
             foreach (RepeaterItem repeaterItemBooking in rptTransportBooking.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 { }
                 //Tạo các liên kết BookingBusByDate mới
                 if (group != -1)
                 {
                     var busByDate = TransferRequestByDateBLL.BusByDateGetAllByCriterion(Date, busType, route, route.Way, group)
                                     .Future().ToList().FirstOrDefault();
                     var bookingBusByDate = new BookingBusByDate()
                     {
                         Booking   = booking,
                         BusByDate = busByDate,
                     };
                     TransferRequestByDateBLL.BookingBusByDateSaveOrUpdate(bookingBusByDate);
                 }
                 //--
             }
         }
     }
     ShowSuccess("Saved successfully");
     Session["Redirect"] = true;
     Response.Redirect(Request.RawUrl);
 }
 public void BookingBusByDateSaveOrUpdate(BookingBusByDate bookingBusByDate)
 {
     BookingBusByDateRepository.SaveOrUpdate(bookingBusByDate);
 }