/// <summary> /// Booking details are added to Database /// </summary> /// <param name="confirmbooking"></param> /// <returns>int</returns> public bool Confirm_Booking(BookingTransfer confirmbooking) { //book is the object for Booking class //assigning the values of Booking Transfer to Confirmbooking ConfirmBooking book = new ConfirmBooking(); book.bookingAmount = confirmbooking.bookingAmount; book.checkInDate = confirmbooking.checkInDate; book.checkOutDate = confirmbooking.checkOutDate; book.discountAmount = confirmbooking.discountAmount; book.bookingDate = DateTime.Today; confirmbooking.bookingDate = book.bookingDate; List <int> findbooking = dbContext.roomBookingDetails.Where(x => x.roomId == confirmbooking.roomId).Select(y => y.bookingId).ToList(); foreach (var bookId in findbooking) { ConfirmBooking findbook = dbContext.booking.Find(bookId); if (!((findbook.checkInDate >= confirmbooking.checkInDate && findbook.checkInDate >= confirmbooking.checkOutDate) || (findbook.checkOutDate <= confirmbooking.checkInDate && findbook.checkOutDate <= confirmbooking.checkOutDate))) { return(false); } } //updating the database with object try { // Adding new row to Booking table with Add method dbContext.booking.Add(book); //After adding saving changes with SaveChanges method dbContext.SaveChanges(); } //catch block will be called when any error occurs while saving in database catch { return(false); } return(true); }
public void BookMyRoom_ConfirmBooking_WrongDetails() { //Arrange BookMyRoomManager booking = new BookMyRoomManager(); BookingTransfer bookingTransfer = new BookingTransfer(); bookingTransfer.bookingAmount = 10000; bookingTransfer.bookingDate = DateTime.Today; bookingTransfer.checkInDate = DateTime.Today; bookingTransfer.checkOutDate = DateTime.Today.AddDays(8); bookingTransfer.discountAmount = 100; bookingTransfer.roomId = 1; var confirmbooking = booking.Confirm_Booking(bookingTransfer); //Assert Assert.AreEqual(false, confirmbooking); }
/// <summary> /// For Mapping table so that the booked rooms will not be shown /// </summary> /// <param name="obj"></param> public bool RoomIdBookingIdUpdate(BookingTransfer obj) { obj.bookingDate = DateTime.Today; List <int> bookingIds = (from booking in dbContext.booking where booking.bookingDate == obj.bookingDate && booking.checkInDate == obj.checkInDate && booking.checkOutDate == obj.checkOutDate && booking.bookingAmount == obj.bookingAmount && booking.discountAmount == obj.discountAmount select booking.bookingId).ToList(); List <int> allBookingIds = (from map in dbContext.roomBookingDetails select map.bookingId).ToList(); List <int> idsToBeExcluded = new List <int>(); foreach (int id in bookingIds) { foreach (int ids in allBookingIds) { if (id == ids) { idsToBeExcluded.Add(id); } } } if (idsToBeExcluded.Count != 0) { bookingIds.RemoveAll(x => idsToBeExcluded.Any(y => y == x)); } try { int bookingIdToMap = bookingIds[0]; RoomBookingDetails roomBookingUpdate = new RoomBookingDetails(); roomBookingUpdate.bookingId = bookingIdToMap; roomBookingUpdate.roomId = obj.roomId; roomBookingUpdate.userId = obj.userId; //Adding the roomBookingUpdate object to database dbContext.roomBookingDetails.Add(roomBookingUpdate); dbContext.SaveChanges(); } catch (Exception ex) { return(false); } return(true); }
public HttpResponseMessage RoomBookingMapping(BookingTransfer bookingdetails) { //Calling Confirm_Booking method in Business Layer by passing bookingdetails parameter which returns an integer if (bookingdetails == null) { //If the bookingdetails is null ArgumentNullException will be thrown throw new ArgumentNullException("Bookingdetails cannot be null"); } bool result = bookMyRoomManager.RoomBookingMapping(bookingdetails); //Checking whether the result is true or false if (result) { return(Request.CreateErrorResponse(HttpStatusCode.OK, "Room Mapping is done Sucessfully")); } else { //If the result is false the InternalServerError will be thrown throw new DivideByZeroException("InternalServerError"); } }
public int Storedata(BookingTransfer obj) { Booking book = new Booking(); book.bookingAmount = obj.bookingAmount; book.checkInDate = obj.checkInDate; book.checkOutDate = obj.checkOutDate; book.discountAmount = obj.discountAmount; book.bookingDate = DateTime.Now; obj.bookingDate = book.bookingDate; try { db.booking.Add(book); db.SaveChanges(); // RoomIdBookingIdUpdate(obj); return(1); } catch { return(0); } }
public void RoomIdBookingIdUpdate(BookingTransfer obj) { int bookingIdToMap = (from booking in db.booking where booking.bookingDate == obj.bookingDate && booking.checkInDate == obj.checkInDate && booking.checkOutDate == obj.checkOutDate && booking.bookingAmount == obj.bookingAmount && booking.discountAmount == obj.discountAmount select booking.bookingId).FirstOrDefault(); RoomBookingDetails roomBookingUpdate = new RoomBookingDetails(); try { // roomBookingUpdate.bookingId = Convert.ToInt32(bookingIdToMap); roomBookingUpdate.bookingId = bookingIdToMap; roomBookingUpdate.roomId = obj.roomId; db.roomBookingDetails.Add(roomBookingUpdate); db.SaveChanges(); } catch { Console.WriteLine("Alert"); } }
public int Storedata(BookingTransfer obj) { return(hotelObj.Storedata(obj)); }
public bool RoomBookingMapping(BookingTransfer savebooking) { //Calling Confirm_Booking method in DataAccessLayer return(getroomdetails.RoomIdBookingIdUpdate(savebooking)); }
public bool Confirm_Booking(BookingTransfer savebooking) { //Calling Confirm_Booking method in DataAccessLayer return(getroomdetails.Confirm_Booking(savebooking)); }