Пример #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);
        }