示例#1
0
        public int addRecord(int CId, decimal TotalPrice, DateTime CreateDate, DateTime TripStart, string CreditCard)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    int newid = -1;

                    using (ElectricCarEntities context = new ElectricCarEntities())
                    {
                        if (context.Bookings.Count() == 0)
                        {
                            newid = 1;
                        }
                        else
                        {
                            newid = context.Bookings.Max(x => x.Id) + 1;
                        }

                        Booking b = new Booking();
                        b.Id = newid;
                        b.cId = CId;
                        b.totalPrice = TotalPrice;
                        b.createDate = CreateDate;
                        b.tripStart = TripStart;
                        b.creaditCard = CreditCard;
                        context.Bookings.Add(b);
                        //context.Bookings.Add(new Booking()
                        //{
                        //Id = newid,
                        //cId = CId,
                        //totalPrice = TotalPrice,
                        //createDate = CreateDate,
                        //tripStart = TripStart,
                        //creaditCard = CreditCard
                        //});
                    context.SaveChanges();
                    }
                    scope.Complete();
                    return newid;
                }
            }
            catch (TransactionAbortedException)
            {

                throw new SystemException("Can not add new booking");
            }
        }
示例#2
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;
 }