public bool UpdateEntityInDb(object updatedUser) { bool entityUpdated = false; using (var db = new BookingDBEntities()) { db.Entry(updatedUser).State = EntityState.Modified; bool saveFailed; do { saveFailed = false; try { db.SaveChanges(); // saves changes in DB entityUpdated = true; } catch (DbUpdateConcurrencyException ex) { saveFailed = true; ex.Entries.Single().Reload(); // reloads entity from DB entityUpdated = false; } } while (saveFailed); } return(entityUpdated); }
public (List <string> rowList, List <int?> seatList) GetUnbookedAllSeatIdsFromAllSeats(List <int?> availableSeatsIdList) // Gets the seat and row from Allseats, from the availableSeatIds { List <string> rowList = new List <string>(); List <int?> seatList = new List <int?>(); using (var db = new BookingDBEntities()) { foreach (int?element in availableSeatsIdList) // gets the row from AllSeats and puts in list { var row = (from s in db.AllSeats where s.allSeatsId == element select s.rowNumber).ToList(); string convRow = row.First <string>(); rowList.Add(convRow); } foreach (int?element in availableSeatsIdList) // gets seatNumber from ALlSeats and puts in list { var seatNumber = (from s in db.AllSeats where s.allSeatsId == element select(int?) s.seatNumber).ToList(); int?convSeat = seatNumber.First <int?>(); seatList.Add(convSeat); } return(rowList, seatList); } }
public List <int?> CompareAllSeatsAndBookedSeats(List <int?> allSeats, List <int?> bookedSeats) // Compares allSeatsIds and bookedSeatsIds and return the difference { List <int?> availableSeatsId = new List <int?>(); using (var db = new BookingDBEntities()) { availableSeatsId = allSeats.Except(bookedSeats).ToList(); return(availableSeatsId); } }
public int GetMovieIdFromName(string movieName) { using (var db = new BookingDBEntities()) { var movieId = (from s in db.Movies where s.movieName == movieName select s.movieId).DefaultIfEmpty(0).FirstOrDefault(); return(movieId); } }
public List <int?> GetBookedSeatsInList(DateTime bookingDate) { using (var db = new BookingDBEntities()) { var list = (from s in db.Bookings where s.bookingForDate == bookingDate select s.allSeatsId).ToList(); return(list); } }
public int CheckIfMovieExists(string movieNameInput) // check if movie already exists in db { using (var db = new BookingDBEntities()) { var movieId = (from s in db.Movies where s.movieName == movieNameInput select s.movieId).DefaultIfEmpty(0).FirstOrDefault(); return(movieId); } }
public List <int?> GetAllSeatsInList(int loungeId) // Gets allSeatIds from AllSeats in a list { using (var db = new BookingDBEntities()) { var list = (from s in db.AllSeats where s.loungeId == loungeId select(int?) s.allSeatsId).ToList(); return(list); } }
public int GetBookingIdFromCustomerId(int?custId) { using (var db = new BookingDBEntities()) { var bookingId = (from s in db.Bookings where s.customerId == custId select s.bookingId).FirstOrDefault(); return(bookingId); } }
public int?CheckIfMovieShowingExists(DateTime movieShowing) // check if showing already exists in db { using (var db = new BookingDBEntities()) { var showingId = (from s in db.MovieShowings where s.movieShowingTime == movieShowing select s.movieId).DefaultIfEmpty(0).FirstOrDefault(); return(showingId); } }
public int GetCustomerIdFromUserAccountName(string accountName) { using (var db = new BookingDBEntities()) { var userAccId = (from s in db.UserAccounts where s.accountName == accountName select s.customerId).FirstOrDefault(); return(userAccId); } }
public string GetCustomerEmailFromAccountName(int custId) { using (var db = new BookingDBEntities()) { var email = (from s in db.Customers where s.customerId == custId select s.email).FirstOrDefault(); return(email); } }
public Customers GetCustomerEntity(string emailInput) // find customer id from email { using (var db = new BookingDBEntities()) { var accId = (from s in db.Customers where s.email == emailInput select s).FirstOrDefault <Customers>(); return(accId); } }
public int GetCustomerId(string emailInput) { using (var db = new BookingDBEntities()) { var custId = (from s in db.Customers where s.email == emailInput select s.customerId).FirstOrDefault(); return(custId); } }
public string GetPassword(string accountName) // Gets password from DB { using (var db = new BookingDBEntities()) { var password = db.UserAccounts .Where(s => s.accountName == accountName) .Select(s => s.accountPassword) .FirstOrDefault() .ToString(); return(password); } }
public List <int?> GetAllBookedSeatFromDate(DateTime showingDate) // Gets allSeatsIds from Bookings and puts in list { List <int?> bookedSeatsList = new List <int?>(); using (var db = new BookingDBEntities()) { bookedSeatsList = (from s in db.Bookings where s.bookingForDate == showingDate select(int?) s.allSeatsId).ToList(); return(bookedSeatsList); } }
public int GetSeatPlacementId(string row, int seatNumber) // Gets seat id from row and seatNumber { int allSeatId; using (var db = new BookingDBEntities()) { allSeatId = (from s in db.AllSeats where s.rowNumber == row && s.seatNumber == seatNumber select s.allSeatsId).FirstOrDefault(); } return(allSeatId); }
public int CheckIfSeatIsTaken(DateTime forDate, int?seatId) // Checks if a booking has been made on a date from allSeatId and date, returns bookings id { int bookingId; using (var db = new BookingDBEntities()) { bookingId = (from s in db.Bookings where s.bookingForDate == forDate && s.allSeatsId == seatId select s.bookingId).DefaultIfEmpty(0).FirstOrDefault(); } return(bookingId); // returns booking id, 0 if no booking has been found }
public int FetchLoungeId(int id) // fetch lounge { using (var db = new BookingDBEntities()) { var lounge = (from s in db.Lounges where s.loungeId == id select s.loungeId).FirstOrDefault(); return(lounge); } }
public UserAccounts GetUserAccountByName(string accountNameInput) // Gets user entity from db { try { using (var db = new BookingDBEntities()) { var userAcc = (from s in db.UserAccounts where s.accountName == accountNameInput select s).FirstOrDefault <UserAccounts>(); return(userAcc); } } catch { return(null); // returns null if entity is not found } }
public List <DateTime?> GetMovieShowingsFromMovieId(int movieIdInput) { using (var db = new BookingDBEntities()) { List <DateTime?> movieShowings = new List <DateTime?>(); try { movieShowings = (from s in db.MovieShowings where s.movieId == movieIdInput select s.movieShowingTime).ToList(); return(movieShowings); } catch { return(movieShowings); } } }
public Customers GetCustomerEntityFromId(int?custId) // Gets user entity from db { try { using (var db = new BookingDBEntities()) { var customer = (from s in db.Customers where s.customerId == custId select s).FirstOrDefault <Customers>(); return(customer); } } catch { return(null); // returns null if entity is not found } }
public bool CheckIfAccountNameExists(string accountNameInput) // Check if account name exists in DB { bool accountNameIsNotOk = true; using (var db = new BookingDBEntities()) { var accName = (from s in db.UserAccounts where s.accountName == accountNameInput select s.accountName).DefaultIfEmpty(String.Empty).First(); if (accName.Equals(String.Empty)) { accountNameIsNotOk = false; } ; return(accountNameIsNotOk); } }
public bool CheckIfEmailExists(string emailInput) // check if email exists in db { bool emailExists = false; using (var db = new BookingDBEntities()) { var email = (from s in db.Customers where s.email == emailInput select s.email).DefaultIfEmpty(String.Empty).First().ToString(); if (email != (String.Empty)) { emailExists = true; // returns if linq query returns an email from DB } ; return(emailExists); } }
public UserAccounts AddCustomerToUserAccount(string accountNameInput, Customers cust) // lägga till customer till useracount { var userAcc = new UserAccounts(); try { using (var db = new BookingDBEntities()) { userAcc = (from s in db.UserAccounts where s.accountName == accountNameInput select s).FirstOrDefault <UserAccounts>(); } userAcc.Customers = cust; return(userAcc); } catch { userAcc = null; return(userAcc); } }
public MovieShowings GetMovieShowingEntity(int movieIdInput) { var movieShowing = new MovieShowings(); try { using (var db = new BookingDBEntities()) { movieShowing = (from s in db.MovieShowings where s.movieId == movieIdInput select s).FirstOrDefault <MovieShowings>(); } return(movieShowing); } catch { movieShowing = null; return(movieShowing); } }
public string GetUserSalt(string accountNameInput) // Gets salt from DB { string salt = null; using (var db = new BookingDBEntities()) { try { salt = db.UserAccounts .Where(s => s.accountName == accountNameInput) .Select(s => s.salt) .FirstOrDefault() .ToString(); } catch { return(salt); } return(salt); } }
public AccountController() { objBookingDBEntities = new BookingDBEntities(); }
public RoomController() { objBookingDBEntities = new BookingDBEntities(); }