//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); } }
public void AddBilling(int GuestID, decimal RoomCharge) { using (var context2 = new Sunshine_HotelEntities1()) { //select out the last guest ID, whichis the one above // var NewGuestID = context.Guests.Select(g => g.GuestID).ToList().LastOrDefault(); var saveRoomBilling = new Billing { GuestIDFK = GuestID, BarCharge = 0, WiFiCharge = 0, TelephoneCharge = 0, RoomCharge = RoomCharge }; context2.Billings.Add(saveRoomBilling); context2.SaveChanges(); } }
/// <summary> /// This does Update and New entries /// </summary> /// <returns>The total to the label</returns> public string SaveExpenses() { //save the expenses to the DB and return the Total if (GuestIDFK == 0) { MessageBox.Show("You must chose a Guest first"); return "Invalid"; } //get a list of all guestID to check against var id = new List<int?>(); //put the guestids into the list using (var context = new Sunshine_HotelEntities1()) { id = context.Billings.Select(b => b.GuestIDFK).ToList(); } //IF THERE IS ALREADY A GUEST THEN JUST UPDATE if (id.Contains(GuestIDFK)) { using (var context = new Sunshine_HotelEntities1()) { //get the entry that matches the guestid var update = context.Billings.Where(b => b.GuestIDFK == GuestIDFK); //get the first or only entry var bill = update.FirstOrDefault(); //pass the data across bill.BarCharge = BarCharge; bill.WiFiCharge = WifiCharge; bill.TelephoneCharge = PhoneCharge; bill.RoomCharge = RoomCharge; bill.GuestIDFK = GuestIDFK; //save changes context.SaveChanges(); } //ELSE ADD NEW GUEST } else { using (var context = new Sunshine_HotelEntities1()) { var NewBilling = new Billing(); NewBilling.BarCharge = BarCharge; NewBilling.WiFiCharge = WifiCharge; NewBilling.TelephoneCharge = PhoneCharge; NewBilling.RoomCharge = RoomCharge; NewBilling.GuestIDFK = GuestIDFK; //update db context.Billings.Add(NewBilling); context.SaveChanges(); } } var total = Convert.ToString(BarCharge + WifiCharge + PhoneCharge + RoomCharge); return total; }
public int AddNewGuest(AllGuests myAG) { using (var context = new Sunshine_HotelEntities1()) { //get the last booking ID from the new booking, really difficult needed to google this hard var bookingId = Convert.ToInt16( context.Bookings.OrderByDescending(b => b.BookingID).Select(c => c.BookingID).First()); //CREATE new entry var newGuest = new Guest { Name = myAG.Name, Address = myAG.Address, NumberOfGuests = myAG.NumberOfGuests, RoomBooked = myAG.RoomBooked, BookingIDFK = bookingId, //get the booking ID from the booking table, this BookingDate = DateTime.Today.Date }; // newGuest.CheckIn = DateTime.Now; context.Guests.Add(newGuest); context.SaveChanges(); //need to reload the guest just saved to get back the GuestID in case the checkin is immediatly done, instead of being selected from the dgv, cannot use .last as SQL doesn't recognise it var lastGuest = context.Guests.OrderByDescending(g => g.GuestID).Select(g => g.GuestID).FirstOrDefault(); return lastGuest; } }
public void CheckTheGuestIn(int GuestId) { using (var context = new Sunshine_HotelEntities1()) { var guest = context.Guests.SingleOrDefault(g => g.GuestID == GuestId); guest.CheckIn = DateTime.Now; context.SaveChanges(); } }
public bool CheckOutTheGuest(int GuestId) { var IsGuestCheckOut = false; using (var context = new Sunshine_HotelEntities1()) { //get the current guest var currentGuest = context.Guests.SingleOrDefault(g => g.GuestID == GuestId); // var CurrentBooking = // context.Bookings.Where(b => b.RoomIDFK == CurrentGuest.Select(g => g.RoomBooked)); //if they havn't checked in, they can't check out if (currentGuest.CheckIn == null) { MessageBox.Show("You havn't checked in yet"); return true; } //make sure only to get one entry, well there should only be one anyway var goodbyeGuest = currentGuest; goodbyeGuest.CheckOut = DateTime.Now; context.SaveChanges(); //turn the checkout bool to true IsGuestCheckOut = true; } return IsGuestCheckOut; }