public static void CleanUp() { if (CustomerId != 0) { var customer = context.Customer.SingleOrDefault(c => c.CustomerId == CustomerId); // var details = context.SelectedRooms.SingleOrDefault(s => s.HotelId == HotelId); context.Customer.Remove(customer); // context.SelectedRooms.Remove(details); context.SaveChanges(); } if (PaymentInvoiceNo != 0) { var bookingid = context.Payment.Where(c => c.PaymentInvoiceNo == PaymentInvoiceNo).Select(c => c.BookingId).FirstOrDefault(); var booking = context.Booking.SingleOrDefault(b => b.BookingId == bookingid); var bookingdetails = context.BookingDetails.Where(d => d.BookingId == bookingid).ToArray(); context.BookingDetails.RemoveRange(bookingdetails); var payment = context.Payment.SingleOrDefault(p => p.PaymentInvoiceNo == PaymentInvoiceNo); context.Payment.Remove(payment); context.Booking.Remove(booking); context.SaveChanges(); } }
//public void AddRecord(Customer c1) //{ // throw new NotImplementedException(); //} public int AddRecord(Customer c1) { Customer customer = context.Customer.Where(d => d.Email == c1.Email).SingleOrDefault(); if (customer == null) { context.Customer.Add(c1); context.SaveChanges(); return(0); // } return(1); // duplicate email }
public InvoiceData MakeBooking(AllData allData) { Booking booking = new Booking(); booking.CustomerId = allData.CustomerId; booking.Checkin = allData.userinfo.CheckIn; booking.Checkout = allData.userinfo.CheckOut; booking.HotelId = allData.userinfo.HotelId; int days = (allData.userinfo.CheckOut - allData.userinfo.CheckIn).Days + 1; int sum = 0; for (int i = 0; i < allData.SelectedRooms.Count; i++) { sum += (int)allData.SelectedRooms[i].RoomPrice * days; } booking.TotalAmount = sum; context.Booking.Add(booking); context.SaveChanges(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int Roomcount = allData.SelectedRooms.Count; BookingDetails[] bookingDetails = new BookingDetails[Roomcount]; BookingDetails temp; for (int i = 0; i < Roomcount; i++) { temp = new BookingDetails(); temp.BookingId = booking.BookingId; temp.HotelId = booking.HotelId; temp.RoomId = allData.SelectedRooms[i].RoomId; temp.Days = days; temp.RoomPrice = allData.SelectedRooms[i].RoomPrice; bookingDetails[i] = temp; // context.BookingDetails.Add(bookingDetails[i]); } context.BookingDetails.AddRange(bookingDetails); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Payment payment = new Payment(); payment.BookingId = booking.BookingId; payment.CustomerId = booking.CustomerId.Value; payment.HotelId = booking.HotelId.Value; payment.PaymentType = allData.payMode; payment.TotalAmount = sum; payment.Date = DateTime.Now; context.Payment.Add(payment); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ context.SaveChanges(); Customer customer = context.Customer.SingleOrDefault(c => c.CustomerId == allData.CustomerId); InvoiceData data = new InvoiceData(); data.customer = customer; data.customer.Booking = null; data.customer.Payment = null; data.InvoiceNo = payment.PaymentInvoiceNo; return(data); }
public void AddBooking(Booking b1) { context.Booking.Add(b1); context.SaveChanges(); }