コード例 #1
0
        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);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
        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);
            }
        }
コード例 #14
0
 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);
     }
 }
コード例 #15
0
        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);
            }
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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
        }
コード例 #18
0
ファイル: LoungeManager.cs プロジェクト: jwengelin/BookingBio
        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);
            }
        }
コード例 #19
0
        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
            }
        }
コード例 #20
0
 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);
         }
     }
 }
コード例 #21
0
        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
            }
        }
コード例 #22
0
        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);
            }
        }
コード例 #23
0
        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);
            }
        }
コード例 #24
0
        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);
            }
        }
コード例 #25
0
        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);
            }
        }
コード例 #26
0
        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);
            }
        }
コード例 #27
0
 public AccountController()
 {
     objBookingDBEntities = new BookingDBEntities();
 }
コード例 #28
0
 public RoomController()
 {
     objBookingDBEntities = new BookingDBEntities();
 }