예제 #1
0
 public List <Movies> ShowUserBookings()
 {
     using (var db = new CinemaDb())
     {
         return(db.Movies.OrderBy(m => m.Title).ToList());
     }
 }
예제 #2
0
 public Categories GetACategory(int id)
 {
     using (var db = new CinemaDb())
     {
         return(db.Categories.FirstOrDefault(c => c.Id == id));
     }
 }
예제 #3
0
 public Bookings CurrentBooking(int id)
 {
     using (var db = new CinemaDb())
     {
         return(db.Bookings.FirstOrDefault(b => b.Id == id));
     }
 }
예제 #4
0
 public List <Movies> GetMovies()
 {
     using (var db = new CinemaDb())
     {
         return(db.Movies.OrderBy(c => c.Title).ToList());
     }
 }
예제 #5
0
 //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());
     }
 }
예제 #6
0
 public Movies OneMovie(int id)
 {
     using (var db = new CinemaDb())
     {
         return(db.Movies.FirstOrDefault(m => m.Id == id));
     }
 }
예제 #7
0
 public List <Bookings> UserBookings()
 {
     using (var db = new CinemaDb())
     {
         return(db.Bookings.OrderBy(b => b.SelectedTime).ToList());
     }
 }
예제 #8
0
 public List <SeatTypes> GetSeatTypes()
 {
     using (var db = new CinemaDb())
     {
         return(db.SeatTypes.OrderBy(s => s.SeatTypeId).ToList());
     }
 }
예제 #9
0
 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));
     }
 }
예제 #10
0
 public SeatTypes GetSeatType(int id)
 {
     using (var db = new CinemaDb())
     {
         return(db.SeatTypes.FirstOrDefault(s => s.SeatTypeId == id));
     }
 }
예제 #11
0
        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();
            }
        }
예제 #12
0
        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);
        }
예제 #13
0
 public Movies GetAMovie(int id)
 {
     using (var db = new CinemaDb())
     {
         return(db.Movies.FirstOrDefault(c => c.Id == id));
     }
 }
예제 #14
0
 public List <Categories> GetCategories()
 {
     using (var db = new CinemaDb())
     {
         return(db.Categories.OrderBy(c => c.Title).ToList());
     }
 }
예제 #15
0
 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());
     }
 }
예제 #16
0
        //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();
            }
        }
예제 #17
0
        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();
            }
        }
예제 #18
0
 public List <Movies> GetMovByCategory(int catId)
 {
     using (var db = new CinemaDb())
     {
         return(db.Movies
                .Where(m => m.MovieId == catId)
                .OrderByDescending(m => m.AvailableTime)
                .ToList());
     }
 }
예제 #19
0
        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();
            }
        }
예제 #20
0
        //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());
            }
        }
예제 #21
0
        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());
            }
        }
예제 #22
0
        //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());
            }
        }
예제 #23
0
        public string CreateNew(string title)
        {
            using (var db = new CinemaDb())
            {
                db.Categories.Add(new Categories()
                {
                    Title = title,
                });

                db.SaveChanges();

                return(null);
            }
        }
예제 #24
0
        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);
        }
예제 #25
0
        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);
        }
예제 #26
0
        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);
            }
        }
예제 #27
0
        //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);
        }