예제 #1
0
 public void addBooking(Booking b)
 {
     MBooking bk = new MBooking();
     bk.cId = b.cId;
     bk.createDate = DateTime.ParseExact(b.createDate, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture);
     bk.creaditCard = b.payStatus;
     bk.tripStart = DateTime.ParseExact(b.tripStart, "dd/MM/yyyy HH:mm", System.Globalization.CultureInfo.CurrentCulture);
     bk.totalPrice = b.totalPrice;
     List<MBookingLine> bkls = new List<MBookingLine>();
     List<BookingLine> bls = b.bookinglines.ToList<BookingLine>();
     for (int i = 0; i < bls.Count; i++)
     {
         MBookingLine bl = new MBookingLine();
         bl.price = bls[i].price;
         bl.quantity = bls[i].quantity;
         bl.Station.Id = bls[i].station.Id;
         bl.time = bls[i].time;
         bl.BatteryType.id = bls[i].BatteryType.ID;
         bkls.Add(bl);
     }
     bk.bookinglines = bkls;
     BookingCtr bCtr = new BookingCtr();
     if (!bCtr.addBooking(bk))
     {
         FaultException f = new FaultException("Booking failed because one of the station is fully booked");
         throw f;
     }
 }
예제 #2
0
        public bool addBooking(MBooking booking)
        {
            bool success = true;
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    //validate period for specific battery type

                    foreach (MBookingLine item in booking.bookinglines)
                    {
                        if (!bsCtr.validateBookingForStation(item.Station.Id, item.BatteryType.id, item.quantity.Value, item.time.Value))
                        {
                            throw new SystemException("Booking fail because one of the stations is fully booked");
                        }
                    }

                    int bId = addBookingRecord(booking.cId.Value, booking.totalPrice.Value, booking.createDate.Value, booking.tripStart.Value, booking.creaditCard);
                    //decrease the number in Period
                    foreach (MBookingLine item in booking.bookinglines)
                    {
                        bsCtr.addBookingForStation(item.Station.Id, item.BatteryType.id, item.quantity.Value, item.time.Value);
                    }

                    blCtr.insertAllBLForBooking(bId, booking.bookinglines);

                    scope.Complete();
                    return success;
                }
            }
            catch (SystemException)
            {
                success = false;
                return success;
            }
        }
예제 #3
0
 public void updateBooking(MBooking booking)
 {
     using (TransactionScope scope = new TransactionScope())
     {
         //validate whether update is valid
         //foreach (MBookingLine item in booking.bookinglines)
         //{
         //    if (!bsCtr.validateUpdateBookingForStation(item.Station.Id, item.BatteryType.id, item.quantity.Value, item.time.Value))
         //    {
         //        throw new SystemException("Update booking fail because one of the stations is fully booked");
         //    }
         //}
         updateBookingRecord(booking.Id, booking.cId.Value, booking.totalPrice.Value, booking.createDate.Value, booking.tripStart.Value, booking.creaditCard);
         //foreach (MBookingLine item in booking.bookinglines)
         //{
         //    bsCtr.updateBookingForStation(item.Station.Id, item.BatteryType.id, item.quantity.Value, item.time.Value);
         //}
         //blCtr.updateAllBLForBooking(booking.Id, booking.bookinglines);
         scope.Complete();
     }
 }
예제 #4
0
 private MBooking buildBooking(Booking b)
 {
     MBooking booking = new MBooking()
     {
         Id = b.Id,
         cId = b.cId.Value,
         customer = new MCustomer(){ID = b.cId.Value},
         totalPrice = b.totalPrice,
         creaditCard = b.creaditCard,
         createDate = b.createDate,
         tripStart = b.tripStart
     };
     return booking;
 }
예제 #5
0
 public void updateBooking(Booking b)
 {
     MBooking bk = new MBooking();
     bk.Id = b.Id;
     bk.cId = b.cId;
     bk.createDate = Convert.ToDateTime(b.createDate);
     bk.creaditCard = b.payStatus;
     bk.totalPrice = b.totalPrice;
     bk.tripStart = DateTime.ParseExact(b.createDate, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture);
     bk.tripStart = DateTime.ParseExact(b.tripStart, "dd/MM/yyyy HH:mm", System.Globalization.CultureInfo.CurrentCulture);
     BookingCtr bCtr = new BookingCtr();
     bCtr.updateBooking(bk);
 }