Ejemplo n.º 1
0
        //add a new booking passing roombooking means extra unneeded data is being shunted around.
        //public  void AddNewBookingToDB(int RoomIdfk, DateTime BookingFrom, DateTime BookingTo, Decimal Roomcost) {
        public void AddNewBookingToDB(RoomBooking myRB)
        {
            using (var context = new Sunshine_HotelEntities1())
            {
                // CREATE a new booking
                var newbooking = new Booking();
                newbooking.RoomIDFK = myRB.RoomIdfk;
                newbooking.BookingFrom = myRB.BookingFrom.Date;
                newbooking.BookingTo = myRB.BookingTo.Date;

                //add in the cost of the room extracted from the dictionary
                newbooking.RoomCost = myRB.roomCost;
                //   RoomCost =  (decimal) newbooking.RoomCost;
                //update db
                context.Bookings.Add(newbooking);
                context.SaveChanges();

                var BookedConfirmationMessage = Environment.NewLine + "You have booked Room " +
                                                myRB.RoomIdfk + Environment.NewLine + "From " +
                                                myRB.BookingFrom + " To " + Environment.NewLine +
                                                myRB.BookingTo + Environment.NewLine + " For " +
                                                (string.Format("{0:C}", myRB.roomCost));

                //show a confirmation message
                MessageBox.Show(BookedConfirmationMessage);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Adds a new booking if there isn't a conflict
 ///     this runs from the BookRoomClick method above if there is no date conflict
 /// </summary>
 public void AddNewBooking()
 {
     //make a new instance and pass that to the class
     var myRB = new RoomBooking {
         RoomIdfk = RoomIdfk,
         BookingFrom = BookingFrom,
         BookingTo = BookingTo,
         roomCost = RoomBookedPrice()
     };
     if (myRB.RoomIdfk != 0 && myRB.roomCost != 0) {
         //the DB call
         myModelCalls.AddNewBookingToDB(myRB);
     } else {
         MessageBox.Show(myRB.RoomIdfk + " RoomIDFK is null " + myRB.roomCost + " Roomcost is null");
     }
 }