public IHttpActionResult CustomerBooking(CustomerBookingDTO booking) // BOOKING WITHOUT USER ACCOUNT, ONLY AS CUSTOMER { if (!ModelState.IsValid) { var errors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors); return(BadRequest(ModelState)); } TextResult httpResponse = new TextResult("", msg); SeatManager smgr = new SeatManager(); CustomerManager cmgr = new CustomerManager(); BookingManager bmgr = new BookingManager(); Customers custEntity = new Customers(); Bookings bookingEntity = new Bookings(); int? customerId = null; DateTime currentDate = DateTime.Now; var convertedForDate = bmgr.DateTimeConverter(booking.BookingForDate); // Convert dates passed from fronted to DateTime objects int? allSeatsId = smgr.GetSeatPlacementId(booking.RowNumber, booking.SeatNumber); // Gets the allSeatsId from AllSeats from row and seatnumber try { custEntity = cmgr.AddCustomer(booking.Email); // try to create new customer entity db.Customers.Add(custEntity); db.SaveChanges(); // if customer entity exists, trying to insert a new customer will cause exception due to duplicate keys } catch { customerId = cmgr.FindCustomerId(booking.Email); // if customer entity already exists, get customerID from email input } if (customerId != null) // if customer entity already exists, customerId is not null, use customerId instead of entity { bookingEntity = bmgr.CustomerBooking(convertedForDate, currentDate, allSeatsId, customerId); // creates booking entity with customerId try { db.Bookings.Add(bookingEntity); // creates booking enitity, with customerId db.SaveChanges(); } catch { httpResponse.ChangeHTTPMessage("Could not make booking!", msg); return(httpResponse); } } bookingEntity = bmgr.CustomerBooking(custEntity, convertedForDate, currentDate, allSeatsId); // creates booking entity, with customerEntity try { db.Bookings.Add(bookingEntity); db.SaveChanges(); } catch { httpResponse.ChangeHTTPMessage("Could not make booking!", msg); return(httpResponse); } httpResponse.ChangeHTTPMessage("Booking completed!", msg); return(httpResponse); }
public IHttpActionResult UserAccountBooking(UserAccountBookingDTO booking) // BOOKING WITH USER ACCOUNT, NOT FINISHED { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TextResult httpResponse = new TextResult("", msg); SeatManager smgr = new SeatManager(); CustomerManager cmgr = new CustomerManager(); BookingManager bmgr = new BookingManager(); UserAccountsManager umgr = new UserAccountsManager(); DateTime currentDate = DateTime.Now; string token = umgr.CreateToken(booking.AccountName); var loginOk = umgr.CheckIfUserIsLoggedIn(booking.LoginToken, token); // token passed from frontend to check if user is logged in, token variabel content? if (loginOk.Equals(false)) { httpResponse.ChangeHTTPMessage("User is not logged in!", msg); return(httpResponse); } ; var convertedForDate = bmgr.DateTimeConverter(booking.BookingForDate); // Converting dates into DateTime objects if (convertedForDate.Equals(null)) // checking if date input is valid { httpResponse.ChangeHTTPMessage("Date input is not correct!", msg); return(httpResponse); } ; int?allSeatsId = smgr.GetSeatPlacementId(booking.RowNumber, booking.SeatNumber); // Gets the allSeatsId from AllSeats from row and seatnumber int bookingId = smgr.CheckIfSeatIsTaken(convertedForDate, allSeatsId); // checks if seat is taken, returns bookingId if (bookingId != 0) { httpResponse.ChangeHTTPMessage("That seat is taken!", msg); // http response if seat is taken return(httpResponse); } var custId = umgr.GetCustomerIdFromUserAccountName(booking.AccountName); var email = cmgr.GetCustomerEmailFromAccountName(custId); var bookingEntity = bmgr.UserAccountBooking(allSeatsId, custId, convertedForDate, currentDate); db.Bookings.Add(bookingEntity); db.SaveChanges(); httpResponse.ChangeHTTPMessage("Booking has been made!", msg); // HTTP response if fails to savechanges to DB return(httpResponse); }
public IHttpActionResult PostMovieShowings(MovieShowingDTO movieShowings) // ADD NEW MOVIE SHOWING { MoviesManager mvmgr = new MoviesManager(); BookingManager bmgr = new BookingManager(); TextResult httpResponse = new TextResult("", msg); DateTime convertedShowingDate = new DateTime(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } convertedShowingDate = bmgr.DateTimeConverter(movieShowings.MovieShowingTime); int?showingExists = mvmgr.CheckIfMovieShowingExists(convertedShowingDate); // Checks if movieshowing already exists if (showingExists != 0) { httpResponse.ChangeHTTPMessage("Showing already exists on that date!", msg); // http response return(httpResponse); } int?movieId = mvmgr.CheckIfMovieExists(movieShowings.MovieName); var movieShowingEntity = mvmgr.AddNewMovieShowing(convertedShowingDate, movieId, movieShowings.LoungeId); // creates movieshowing entity try { db.MovieShowings.Add(movieShowingEntity); db.SaveChanges(); } catch { httpResponse.ChangeHTTPMessage("Movieshowing could not be added!", msg); return(httpResponse); } httpResponse.ChangeHTTPMessage("Movieshowing added!", msg); return(httpResponse); }
public IHttpActionResult GetAvailableSeats(DateAndLoungeDTO dateAndLounge) // GETS AVAILABLE SEATS { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TextResult httpResponse = new TextResult("", msg); SeatManager smgr = new SeatManager(); CustomerManager cmgr = new CustomerManager(); BookingManager bmgr = new BookingManager(); UserAccountsManager umgr = new UserAccountsManager(); SeatAndRowDTO seatAndRowLists = new SeatAndRowDTO(); DateTime currentDate = DateTime.Now; var convertedBookingDate = bmgr.DateTimeConverter(dateAndLounge.BookingForDate); // Conert to datetime object var seatsList = smgr.GetAllSeatsInList(dateAndLounge.LoungeId); // get AllSeatsIds from AllSeats and puts in list var bookedSeatsList = smgr.GetAllBookedSeatFromDate(convertedBookingDate); // Gets AllseatsIds from Bookings from a date var availableSeatsIdList = smgr.CompareAllSeatsAndBookedSeats(seatsList, bookedSeatsList); // compares AllSeats and Booked seat and return difference var(rowList, seatList) = smgr.GetUnbookedAllSeatIdsFromAllSeats(availableSeatsIdList); // Gets row and seat from available seats and puts in lists seatAndRowLists.Row = rowList; seatAndRowLists.SeatNumber = seatList; return(Ok(seatAndRowLists)); // Returns available seats }