public List <Movies> ShowUserBookings() { using (var db = new CinemaDb()) { return(db.Movies.OrderBy(m => m.Title).ToList()); } }
public Categories GetACategory(int id) { using (var db = new CinemaDb()) { return(db.Categories.FirstOrDefault(c => c.Id == id)); } }
public Bookings CurrentBooking(int id) { using (var db = new CinemaDb()) { return(db.Bookings.FirstOrDefault(b => b.Id == id)); } }
public List <Movies> GetMovies() { using (var db = new CinemaDb()) { return(db.Movies.OrderBy(c => c.Title).ToList()); } }
//get movies by their category public List <Movies> GetMoviesByCategory(int category) { using (var db = new CinemaDb()) { return(db.Movies.Where(m => m.Category == category).ToList()); } }
public Movies OneMovie(int id) { using (var db = new CinemaDb()) { return(db.Movies.FirstOrDefault(m => m.Id == id)); } }
public List <Bookings> UserBookings() { using (var db = new CinemaDb()) { return(db.Bookings.OrderBy(b => b.SelectedTime).ToList()); } }
public List <SeatTypes> GetSeatTypes() { using (var db = new CinemaDb()) { return(db.SeatTypes.OrderBy(s => s.SeatTypeId).ToList()); } }
public Users GetUser(string username, string password) { using (var db = new CinemaDb()) { return(db.Users.FirstOrDefault(u => u.Username.ToLower() == username.ToLower() && u.Password == password)); } }
public SeatTypes GetSeatType(int id) { using (var db = new CinemaDb()) { return(db.SeatTypes.FirstOrDefault(s => s.SeatTypeId == id)); } }
public void Register(string username, string email, string password) { using (var db = new CinemaDb()) { var existingUser = db.Users.FirstOrDefault(u => u.Username.ToLower() == username.ToLower()); if (existingUser != null) { throw new LogicException("That username is already in use!"); } existingUser = db.Users.FirstOrDefault(u => u.Email.ToLower() == email.ToLower()); if (existingUser != null) { throw new LogicException("That e-mail is already in use!"); } if (!password.IsPasswordOk()) { throw new LogicException("Password should be at least 6 symbols!"); } db.Users.Add(new Users() { Email = email, Password = password, Username = username, }); db.SaveChanges(); } }
public Movies BookAMovie(int id) { using (var db = new CinemaDb()) { var movie = db.Movies.FirstOrDefault(m => m.Id == id); if (movie != null) { db.Bookings.Add(new Bookings() { MovieId = movie.Id, Title = movie.Title, Pic = movie.Pic, Description = movie.Description, SelectedTime = movie.AvailableTime, Auditorium = movie.AuditoriumId, }); db.SaveChanges(); return(movie); } } return(null); }
public Movies GetAMovie(int id) { using (var db = new CinemaDb()) { return(db.Movies.FirstOrDefault(c => c.Id == id)); } }
public List <Categories> GetCategories() { using (var db = new CinemaDb()) { return(db.Categories.OrderBy(c => c.Title).ToList()); } }
public List <Categories> GetAllCategories() { //returns Topics, ordered by Title ASC using (var db = new CinemaDb()) { // SELECT * FROM Topics ORDER BY Title return(db.Categories.OrderBy(c => c.Title).ToList()); } }
//to delete a category public void Delete(int id) { using (var db = new CinemaDb()) { var category = db.Categories.FirstOrDefault(c => c.Id == id); db.Categories.Remove(category); db.SaveChanges(); } }
public void Delete(int id) { using (var db = new CinemaDb()) { var movie = db.Movies.FirstOrDefault(m => m.Id == id); db.Movies.Remove(movie); db.SaveChanges(); } }
public List <Movies> GetMovByCategory(int catId) { using (var db = new CinemaDb()) { return(db.Movies .Where(m => m.MovieId == catId) .OrderByDescending(m => m.AvailableTime) .ToList()); } }
public void Update(int curUserId, int bookingId) { using (var db = new CinemaDb()) { var bookingData = db.Bookings.FirstOrDefault(b => b.Id == bookingId); bookingData.UserId = curUserId; db.SaveChanges(); } }
//getting movies that are playing this month public List <Movies> GetMoviesPlayingThisMonth() { using (var db = new CinemaDb()) { DateTime today = DateTime.Today; var thisMonthStart = today.AddDays(1 - today.Day); var thisMonthEnd = thisMonthStart.AddMonths(1).AddSeconds(-1); return(db.Movies.Where(m => m.PlayingTime >= thisMonthStart && m.PlayingTime <= thisMonthEnd) .OrderBy(m => m.PlayingTime).ToList()); } }
public List <Movies> GetMoviesPlayingThisWeek() { using (var db = new CinemaDb()) { DateTime today = DateTime.Today; var thisWeekStart = today.AddDays(-(int)today.DayOfWeek); var thisWeekEnd = today.AddDays(7).AddSeconds(-1); return(db.Movies.Where(m => m.PlayingTime >= thisWeekStart && m.PlayingTime <= thisWeekEnd) .OrderBy(m => m.PlayingTime).ToList()); } }
//getting movies that are coming soon public List <Movies> GetComingSoonMovies() { using (var db = new CinemaDb()) { DateTime today = DateTime.Today; var nextMonthStart = today.AddMonths(1).AddSeconds(1); var nextMonthEnd = nextMonthStart.AddMonths(1).AddSeconds(-1); return(db.Movies.Where(m => m.PlayingTime > nextMonthStart) .OrderBy(m => m.PlayingTime) .ToList()); } }
public string CreateNew(string title) { using (var db = new CinemaDb()) { db.Categories.Add(new Categories() { Title = title, }); db.SaveChanges(); return(null); } }
public Bookings CancelBooking(int id) { using (var db = new CinemaDb()) { var currentBooking = db.Bookings.FirstOrDefault(b => b.Id == id); if (currentBooking != null) { db.Bookings.Remove(currentBooking); db.SaveChanges(); return(currentBooking); } } return(null); }
public Movies CancelUserBookings(int movieId) { //returns a movie(movies) that was canceled by a client using (var db = new CinemaDb()) { var cancelBooking = db.Bookings.FirstOrDefault(m => m.MovieId == movieId); if (cancelBooking != null) { db.Bookings.Remove(cancelBooking); var cancelation = db.Movies.FirstOrDefault(m => m.Id == movieId); var returnedseat = db.Theaters.FirstOrDefault(t => t.Id == cancelation.AuditoriumId); returnedseat.TotalSeats++; db.SaveChanges(); return(cancelation); } } return(null); }
public string CreateNewMovie(string title, string director, string description, int categoryId, int price, int?auditorium, int?length) { using (var db = new CinemaDb()) { db.Movies.Add(new Movies() { Title = title, Director = director, PlayingTime = DateTime.Now, TextAbout = description, Category = categoryId, PriceId = price, AuditoriumId = auditorium, Length = length, Image = "", }); db.SaveChanges(); return(null); } }
//Movies chosen by title //gets a list of all movies chosen by the user public List <Movies> GetUserBookings(int movieId) { //returns a movie that a client chose using (var db = new CinemaDb()) { var movie = db.Movies.FirstOrDefault(m => m.Id == movieId); var theater = db.Theaters.FirstOrDefault(t => t.Id == movie.AuditoriumId); if (movie != null && theater.TotalSeats > 0) { //need to count down the number of seats available at the auditorium theater.TotalSeats--; db.Bookings.Add(new Bookings() { MovieId = movie.Id, WatchingTime = movie.PlayingTime }); db.SaveChanges(); return(db.Movies.OrderBy(c => c.Id).ToList()); } } return(null); }