private List <SeatBooking> GetSeatBookings(int showingId, string resString, int userPhoneNumber) { List <SeatBooking> seatBookings = null; SeatBooking seatBooking; int tempSeatId, rowNo, seatNo; bool parseOk; if (!string.IsNullOrWhiteSpace(resString)) { seatBookings = new List <SeatBooking>(); DateTime resTime = DateTime.Now; bool reserve = true; string[] seatIds = resString.Split(':'); foreach (string seatId in seatIds) { parseOk = int.TryParse(seatId, out tempSeatId); if (parseOk) { rowNo = tempSeatId / 1000; seatNo = tempSeatId - (rowNo * 1000); seatBooking = new SeatBooking(showingId, reserve, rowNo, seatNo, userPhoneNumber); seatBookings.Add(seatBooking); } } } return(seatBookings); }
public async Task <IActionResult> PutSeatBooking([FromRoute] int id, [FromBody] SeatBooking seatBooking) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != seatBooking.ID) { return(BadRequest()); } _context.Entry(seatBooking).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SeatBookingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult DeleteConfirmed(int id) { SeatBooking seatBooking = db.SeatBookings.Find(id); db.SeatBookings.Remove(seatBooking); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> PostSeatBooking([FromBody] SeatBooking seatBooking) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.SeatBooking.Add(seatBooking); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSeatBooking", new { id = seatBooking.ID }, seatBooking)); }
public ActionResult Edit([Bind(Include = "SeatBookingID,EventID,Booked,SeatID")] SeatBooking seatBooking) { if (ModelState.IsValid) { db.Entry(seatBooking).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EventID = new SelectList(db.Events, "EventID", "EventTitle", seatBooking.EventID); ViewBag.SeatID = new SelectList(db.Seats, "SeatID", "SeatNumber", seatBooking.SeatID); return(View(seatBooking)); }
public IHttpActionResult Get(int id) { SeatBooking seatBooking = seatBookingRepository.Get(id); if (seatBooking == null) { return(StatusCode(HttpStatusCode.NoContent)); } else { return(Ok(seatBooking)); } }
// GET: SeatBookings/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SeatBooking seatBooking = db.SeatBookings.Find(id); if (seatBooking == null) { return(HttpNotFound()); } return(View(seatBooking)); }
private static void ReadSeatbookings(Booking aBooking, out int rowNo, out int seatNo, out SeatBooking foundSeatBooking, SqlCommand readCommand, SeatBooking sb) { rowNo = sb.RowNo; seatNo = sb.SeatNo; foundSeatBooking = null; // using (SqlConnection con2 = new SqlConnection(_connectionString)) // Put the Id parameter into the command so that we know which room to read readCommand.Parameters.Clear(); SqlParameter rowNoParam = new SqlParameter("@RowNo", rowNo); SqlParameter seatNoParam = new SqlParameter("@SeatNo", seatNo); readCommand.Parameters.Add(rowNoParam); readCommand.Parameters.Add(seatNoParam); // con2.Open(); // SQLDatareader reads data from the database SqlDataReader productReader = readCommand.ExecuteReader(); if (productReader.HasRows) { while (productReader.Read()) { int tempId; bool tempIsReserved; int tempRowNo; int tempSeatNo; int tempShowId; int tempPhoneNumber = productReader["PhoneNumber"] as int? ?? -1; ThreadStatus(aBooking, " is reading "); tempId = productReader.GetInt32(productReader.GetOrdinal("SeatBookingID")); tempIsReserved = productReader.GetBoolean(productReader.GetOrdinal("IsReserved")); tempRowNo = productReader.GetInt32(productReader.GetOrdinal("RowNo")); tempSeatNo = productReader.GetInt32(productReader.GetOrdinal("SeatNo")); tempShowId = productReader.GetInt32(productReader.GetOrdinal("ShowingID")); //Build the booking with the values from the database foundSeatBooking = new SeatBooking(tempId, tempShowId, tempIsReserved, tempRowNo, tempSeatNo, tempPhoneNumber); } } productReader.Close(); }
// GET: SeatBookings/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SeatBooking seatBooking = db.SeatBookings.Find(id); if (seatBooking == null) { return(HttpNotFound()); } ViewBag.EventID = new SelectList(db.Events, "EventID", "EventTitle", seatBooking.EventID); ViewBag.SeatID = new SelectList(db.Seats, "SeatID", "SeatNumber", seatBooking.SeatID); return(View(seatBooking)); }
public async Task <IActionResult> Create([Bind("ID,SeatDate,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12,S13,S14,S15 ")] SeatBooking seatBooking) { //Show data for the next 4 weeks ViewData["CheckFullSession"] = _sessions.GetSingleWeekStats(seatBooking.SeatDate); if (ModelState.IsValid) { //Save locally for sending to calendar in GenerateCalendarEvents _dbCallsSessionDataDTO.AllSeatBookings.Add(seatBooking); //get the user email seatBooking.StudentEmail = _userManager.GetUserName(User); //get the user name var name = _context.Students.Where(s => s.Email == seatBooking.StudentEmail).Select(s => s.Name).FirstOrDefault(); //add to the booking seatBooking.Name = name.ToString(); // get session with the same date and same email // UPDATE them if they exist //var matchSeatBooking = _context.SeatBooking.FirstOrDefault(s => s.SeatDate == seatBooking.SeatDate && s.StudentEmail == _userManager.GetUserName(User)); //if (matchSeatBooking != null) //{ // //just need the id of the saved entry // seatBooking.ID = matchSeatBooking.ID; // matchSeatBooking.ID = 10000; //need to get rid of the other id throws an error // //update the existing record // _context.Update(seatBooking); //} //else //{//create a new record // _context.Add(seatBooking); //} _context.Add(seatBooking); await _context.SaveChangesAsync(); //delete out old session booking to keep db small await DeleteOldSessionBookings(); return(RedirectToAction(nameof(Index))); } return(View(seatBooking)); }
public void TestCreateSeatBooking() { //Arrange int phoneNumber = 112; Showing showing = _showingAccess.GetById(1); bool isReserved = true; int rowNo = 52; int seatNo = 1; SeatBooking insertSeatBooking = new SeatBooking(showing.ID, isReserved, rowNo, seatNo, phoneNumber); //Act _seatBookingAccess.Create(insertSeatBooking); //Assert }
public ActionResult SelectSeats(int[] SeatNo) { if (ModelState.IsValid) { Booking booking = new Booking(); booking.UserId = Convert.ToInt32(Session["UserId"]); booking.ShowId = Convert.ToInt32(Session["ShowId"]); booking.MovieId = Convert.ToInt32(Session["MovieId"]); db.Bookings.Add(booking); db.SaveChanges(); Booking book = db.Bookings.Where(m => m.UserId == booking.UserId && m.ShowId == booking.ShowId && m.MovieId == booking.MovieId).OrderByDescending(m => m.BookingId).FirstOrDefault(); SeatBooking seatBooking = new SeatBooking(); for (int i = 0; i < SeatNo.Length; i++) { seatBooking.BookingId = book.BookingId; seatBooking.SeatId = SeatNo[i]; db.SeatBookings.Add(seatBooking); db.SaveChanges(); } var message = new MailMessage(); message.To.Add(new MailAddress(Convert.ToString(Session["UserEmail"]))); message.From = new MailAddress("*****@*****.**"); message.Subject = "Movie Tickets Booked"; message.Body = "Your seats have been booked. Thank you for booking."; message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", Password = "******" }; smtp.Credentials = credential; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; smtp.Send(message); } return(RedirectToAction("MyBooking")); } return(View()); }
public async Task <IActionResult> Edit(int id, [Bind("ID,SeatDate,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12,S13,S14,S15, StudentEmail, Name")] SeatBooking seatBooking) { //get the date of last month DateTime LastMonth = DateTime.Today; LastMonth.AddMonths(-1); //if the date is older than lastmonth - catches when the date isn't being carried across if (id != seatBooking.ID && seatBooking.SeatDate < LastMonth && seatBooking.StudentEmail != string.Empty) { return(NotFound()); } //only run if there is an email address if (ModelState.IsValid && !string.IsNullOrEmpty(seatBooking.StudentEmail)) { try { Students name = _context.Students.FirstOrDefault(s => s.Email == seatBooking.StudentEmail); seatBooking.Name = name.Name; _context.Update(seatBooking); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SeatBookingExists(seatBooking.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(seatBooking)); }
public void TestCreateBooking() { //Arrange //User user = _userAccess.GetById(1); Showing showing = _showingAccess.GetById(1); SeatBooking seatBooking = _seatBookingAccess.GetById(15); string seatsBooked = "Row: " + seatBooking.RowNo.ToString() + " SeatNumber: " + seatBooking.SeatNo.ToString(); decimal price = 200.0m; Booking insertBooking = new Booking(555, 1, price); int showId = 1; List <SeatBooking> seatBookings = new List <SeatBooking>(); SeatBooking seatBooking1 = new SeatBooking(15, showId, false, 1, 9, 90122); seatBookings.Add(seatBooking1); //Act _bookingAccess.Create(insertBooking, showId, seatBookings); //int showingId, bool isReserved, int rowNo, int seatNo, int phoneNumber //Assert }
/// <summary> /// Generate an event from the Seat number /// </summary> private void NewEvent(SeatBooking seats, int sessionID, int dayNext, TimeSpan morningSessStart, TimeSpan morningSessEnd, string day, string session) { //add the time of the sessions to the date to get DateTime DateTime sessionStart = seats.SeatDate.AddDays(dayNext).Add(morningSessStart); DateTime sessionEnd = seats.SeatDate.AddDays(dayNext).Add(morningSessEnd); string description = day + session; string seatId = sessionID.ToString(); string sessID = seats.ID.ToString(); string[] descArray = { day, session }; //todo create a new class to pass all the bookings to so that the variable names actually match the data //Create a new event with event details var vEvent = new CalendarEvent { Start = new CalDateTime(sessionStart), End = new CalDateTime(sessionEnd), Description = description, Class = seatId, //session ID Summary = sessID, //the DB id of the week booking - use it to generate the click event for edit Name = "NZBAT at Vision College", Categories = descArray }; calendar.Events.Add(vEvent); //adding in the new events //create a list of timetable bookings var Timetable = new TimetableBooking { StudentEmail = seats.StudentEmail, StudentName = seats.Name, SeatDate = sessionStart, SessionName = seatId }; alltimetableBookings.Add(Timetable); }
public SeatBooking GetViewFromReader(SqlDataReader productReader) { //TODO: Replace GetFromReader in seatbookingaccess with this method SeatBooking foundSeatBooking; int tempId; int tempRowNo; int tempSeatNo; bool tempIsReserved; tempId = productReader.GetInt32(productReader.GetOrdinal("showingId")); tempRowNo = productReader.GetInt32(productReader.GetOrdinal("RowNo")); tempSeatNo = productReader.GetInt32(productReader.GetOrdinal("SeatNo")); tempIsReserved = productReader.GetBoolean(productReader.GetOrdinal("IsReserved")); //Build the booking with the values from the database foundSeatBooking = new SeatBooking(tempId, tempIsReserved, tempRowNo, tempSeatNo); return(foundSeatBooking); }
public ActionResult Create([Bind(Include = "EventID,EventTitle,EventLocation,EventDate,EventDescription,BasePrice, TypeID")] Event @event) { if (ModelState.IsValid) { db.Events.Add(@event); var seats = db.Seats; foreach (var seat in seats) { SeatBooking sb = new SeatBooking { SeatID = seat.SeatID, EventID = @event.EventID, Booked = false }; db.SeatBookings.Add(sb); } db.SaveChanges(); ViewBag.TypeID = new SelectList(db.EventTypes, "TypeID", "TypeName", @event.TypeID); return(RedirectToAction("Index")); } return(View(@event)); }
public void TestUpdateSeatBookings() { //Arrange int phoneNumber = 112; Showing showing = _showingAccess.GetById(1); bool isReserved = true; List <SeatBooking> seatBookings = new List <SeatBooking>(); SeatBooking updateSeatbooking1 = new SeatBooking(showing.ID, isReserved, 1, 1, phoneNumber); SeatBooking updateSeatbooking2 = new SeatBooking(showing.ID, isReserved, 1, 2, phoneNumber); SeatBooking updateSeatbooking3 = new SeatBooking(showing.ID, isReserved, 1, 3, phoneNumber); seatBookings.Add(updateSeatbooking1); seatBookings.Add(updateSeatbooking2); seatBookings.Add(updateSeatbooking3); //Act _seatBookingAccess.Update(showing.ID, seatBookings); //Assert }
public int Create(Booking aBooking, int showId, List <SeatBooking> newReservations) { // I think we use -1 because then we are sure that it is not from the database if it returns that int insertedId = -1; string insertString = "insert into Booking(PhoneNumber, ShowingId, Price) OUTPUT INSERTED.BookingID values (@PhoneNumber, @ShowingID, @Price)"; try { using (SqlConnection con = new SqlConnection(_connectionString)) { //Create the command with a sql script // Opens the connection con.Open(); using (SqlTransaction transaction = con.BeginTransaction(System.Data.IsolationLevel.RepeatableRead)) { using (SqlCommand CreateCommand = new SqlCommand(insertString, con, transaction)) { int rowNo; int seatNo; SeatBooking foundSeatBooking = new SeatBooking(); //bool isAlreadyReserved = false; string queryString = "select SeatBookingID, IsReserved, RowNo, SeatNo, ShowingID, PhoneNumber from SeatBooking where RowNo = @RowNo AND SeatNo = @SeatNo"; using (SqlCommand readCommand = new SqlCommand(queryString, con, transaction)) { foreach (SeatBooking sb in newReservations) { ReadSeatbookings(aBooking, out rowNo, out seatNo, out foundSeatBooking, readCommand, sb); if (foundSeatBooking.IsReserved) { ThreadStatus(aBooking, " is rolled back"); transaction.Rollback(); return(-1); } } } //_delay -= 10000; //System.Threading.Thread.Sleep(_delay); foreach (SeatBooking seatBooking in newReservations) { CreateBookings(aBooking, out insertedId, CreateCommand, out rowNo, out seatNo, seatBooking); } //bool wentOk = _sbAccess.Update(showId, newReservations); UpdateSeatBookings(aBooking, showId, newReservations, con, transaction); transaction.Commit(); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } // Returns the new id, if it's -1 something is wrong return(insertedId); }
private void CreateBookings(Booking aBooking, out int insertedId, SqlCommand CreateCommand, out int rowNo, out int seatNo, SeatBooking seatBooking) { rowNo = seatBooking.RowNo; seatNo = seatBooking.SeatNo; CreateCommand.Parameters.Clear(); // Prepare SQL // Prepares a parameters inside the database to receive a property from the class SqlParameter PhoneNumberParam = new SqlParameter("@PhoneNumber", aBooking.PhoneNumber); SqlParameter showingIdParam = new SqlParameter("@ShowingID", aBooking.ShowingId); SqlParameter priceParam = new SqlParameter("@Price", aBooking.Price); //aBooking.SeatsBooked.Substring(0, 2); int seatBookingId = _sbAccess.GetByRowNoAndSeatNo(rowNo, seatNo).ID; //Adds the above parameter to a Command CreateCommand.Parameters.Add(PhoneNumberParam); CreateCommand.Parameters.Add(showingIdParam); CreateCommand.Parameters.Add(priceParam); ThreadStatus(aBooking, " is creating booking "); // Execute the command, save and read generated key (ID) insertedId = (int)CreateCommand.ExecuteScalar(); }
public void Post([FromBody] SeatBooking value) { _testData.Add(value); }
public void Put(int PID, [FromBody] SeatBooking value) { _testData.Update(value); }
public ActionResult BookingProceed(EventSeatBookingModel model) { var id = model.EventDetails.EventID; var eventDetail = db.Events.Find(id); if (eventDetail == null) { return(HttpNotFound()); } var eventBooking = new EventSeatBookingModel(); var newBooking = new Booking(); eventBooking.EventDetails = eventDetail; eventBooking.UserName = (string)Session["userFullName"]; eventBooking.SeatBookingID = model.SeatBookingID; eventBooking.SeatNumber = model.SeatNumber; eventBooking.SelectedLevel = model.SelectedLevel; eventBooking.SelectedRow = model.SelectedRow; eventBooking.CardType = model.CardType; eventBooking.CardNumber = model.CardNumber; eventBooking.SecurityNumber = model.SecurityNumber; if (model.SelectedLevel == "L3") { eventBooking.ticketPrice = eventDetail.BasePrice; } else if (model.SelectedLevel == "L2") { eventBooking.ticketPrice = eventDetail.BasePrice * 1.5; } else { eventBooking.ticketPrice = eventDetail.BasePrice * 1.5 * 1.5; } int?userID = (int?)Session["userID"]; if (userID != null && userID > 0) { model.DisplayName = model.UserName; } //For Museum if (model.SeatBookingID == null) { model.SeatBookingID = 0; } if (!eventDetail.EventLocation.ToUpper().Contains("MUSEUM")) { if (!ModelState.IsValid) { return(View(eventBooking)); } } Booking booking = new Booking(); booking.EventID = eventBooking.EventDetails.EventID; if (userID != null && userID > 0) { booking.UserID = userID.GetValueOrDefault(); booking.DisplayName = eventBooking.UserName; eventBooking.DisplayName = eventBooking.UserName; } else { booking.UserID = null; booking.DisplayName = model.DisplayName; eventBooking.DisplayName = model.DisplayName; } booking.SeatBookingID = eventBooking.SeatBookingID; booking.Booked = true; booking.BookingDate = DateTime.Now; db.Bookings.Add(booking); SeatBooking seatBooking = db.SeatBookings.FirstOrDefault(x => x.SeatBookingID == eventBooking.SeatBookingID); if (seatBooking != null) { seatBooking.Booked = true; } try { // Your code... // Could also be before try if you know the exception occurs in SaveChanges db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"", ve.PropertyName, eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName), ve.ErrorMessage); } } throw; } eventBooking.Booking = booking; eventBooking.EventDetails = eventDetail; TempData["BookingData"] = eventBooking; return(RedirectToAction("ConfirmBooking")); }
public static SummaryStatsVM ConvertToInt(SeatBooking sb) { SummaryStatsVM ssVM = new SummaryStatsVM(); if (sb.S1 == true) { ssVM.S1 = 1; } if (sb.S2 == true) { ssVM.S2 = 1; } if (sb.S3 == true) { ssVM.S3 = 1; } if (sb.S4 == true) { ssVM.S4 = 1; } if (sb.S5 == true) { ssVM.S5 = 1; } if (sb.S6 == true) { ssVM.S6 = 1; } if (sb.S7 == true) { ssVM.S7 = 1; } if (sb.S8 == true) { ssVM.S8 = 1; } if (sb.S9 == true) { ssVM.S9 = 1; } if (sb.S10 == true) { ssVM.S10 = 1; } if (sb.S11 == true) { ssVM.S11 = 1; } if (sb.S12 == true) { ssVM.S12 = 1; } if (sb.S13 == true) { ssVM.S13 = 1; } if (sb.S14 == true) { ssVM.S14 = 1; } if (sb.S15 == true) { ssVM.S15 = 1; } return(ssVM); }
public IHttpActionResult Put([FromBody] SeatBooking seatBooking, [FromUri] string id) { seatBooking.Id = id; this.seatBookingRepository.Update(seatBooking); return(Ok(seatBooking)); }