Esempio n. 1
0
 public virtual T GetbyId(int id)
 {
     using (MovieAppContext _context = new MovieAppContext())
     {
         return(_context.Set <T>().Find(id));
     }
 }
Esempio n. 2
0
 public MovieListService(
     IMapper mapper,
     MovieAppContext context)
 {
     _mapper  = mapper;
     _context = context;
 }
Esempio n. 3
0
 public UnitOfWork()
 {
     context = new MovieAppContext();
     context.Database.EnsureCreated();
     MovieRepository  = new MovieRepositoryEFMemory(context);
     RentalRepository = new RentalRepository(context);
 }
Esempio n. 4
0
 public virtual List <T> GetAll()
 {
     using (MovieAppContext _context = new MovieAppContext())
     {
         return(_context.Set <T>().ToList());
     }
 }
Esempio n. 5
0
 public virtual void Update(T entity)
 {
     using (MovieAppContext _context = new MovieAppContext())
     {
         _context.Set <T>().AddOrUpdate(entity);
         _context.SaveChanges();
     }
 }
Esempio n. 6
0
 public MoviesController(MovieAppContext context)
 {
     _context   = context;
     client     = new AmazonDynamoDBClient(RegionEndpoint.USEast2);
     _dbContext = new DynamoDBContext(client);
     amazonS3   = new AmazonS3Client(RegionEndpoint.USEast2);
     reviewList = new List <Review>();
 }
Esempio n. 7
0
 public UserService(
     IOptions <JwtSettings> jwtSettings,
     IMapper mapper,
     MovieAppContext context)
 {
     _jwtSettings = jwtSettings;
     _mapper      = mapper;
     _context     = context;
 }
Esempio n. 8
0
 public void Initialize()
 {
     builder = new DbContextOptionsBuilder <MovieAppContext>();
     builder.UseInMemoryDatabase(databaseName: "testMovieAppDb");
     context = new MovieAppContext(builder.Options);
     //data seed
     DatabaseInitialization.InitDatabaseContext(context);
     actorService = new ActorService(context);
 }
Esempio n. 9
0
 public virtual void Delete(int id)
 {
     using (MovieAppContext _context = new MovieAppContext())
     {
         var entity = _context.Set <T>().Find(id);
         _context.Set <T>().Remove(entity);
         _context.SaveChanges();
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Adds a new customer in the database.
 /// </summary>
 /// <param name="phoneNumber"></param>
 /// <param name="firstName"></param>
 /// <param name="lastName"></param>
 public void AddCustomer(string phoneNumber, string firstName, string lastName)
 {
     using (var movieContext = new MovieAppContext())
     {
         movieContext.Customers.Add(new Customer {
             FirstName = firstName, LastName = lastName, PhoneNumber = phoneNumber
         });
         movieContext.SaveChanges();
     }
 }
Esempio n. 11
0
 public override void Add(Director entity)
 {
     using (MovieAppContext _context = new MovieAppContext())
     {
         entity.Name    = entity.Name.ToUpper().Trim();
         entity.SurName = entity.SurName.ToUpper().Trim();
         _context.Directors.Add(entity);
         _context.SaveChanges();
     }
 }
Esempio n. 12
0
        /// <summary>
        /// Gets the movietitle as string
        /// </summary>
        /// <param name="bookingId"></param>
        /// <returns></returns>
        public string MovieTitleFromBookingId(int bookingId)
        {
            using (var movieContext = new MovieAppContext())
            {
                var movieId = movieContext.Tickets.First(ticket => ticket.BookingId == bookingId).RoomId;

                var title = movieContext.Movies.First(movie => movie.Id == movieId).Title;

                return(title);
            }
        }
Esempio n. 13
0
 public void AddActors(List <Actor> actors, int id)
 {
     using (MovieAppContext _context = new MovieAppContext())
     {
         var entity = _context.Movies.Find(id);
         foreach (var actor in actors)
         {
             entity.Actors.Add(actor);
         }
         _context.SaveChanges();
     }
 }
Esempio n. 14
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MovieAppContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MovieAppContext> >()))
            {
                // Look for any movies.
                if (context.Movie.Any())
                {
                    return;   // DB has been seeded
                }

                context.Movie.AddRange(
                    new Movie
                {
                    Title       = "When Harry Met Sally",
                    ReleaseDate = DateTime.Parse("1989-2-12"),
                    Genre       = "Romantic Comedy",
                    Rating      = "R",
                    Price       = 7.99M
                },

                    new Movie
                {
                    Title       = "Ghostbusters ",
                    ReleaseDate = DateTime.Parse("1984-3-13"),
                    Genre       = "Comedy",
                    Rating      = "R",
                    Price       = 8.99M
                },

                    new Movie
                {
                    Title       = "Ghostbusters 2",
                    ReleaseDate = DateTime.Parse("1986-2-23"),
                    Genre       = "Comedy",
                    Rating      = "R",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Rio Bravo",
                    ReleaseDate = DateTime.Parse("1959-4-15"),
                    Genre       = "Western",
                    Rating      = "R",
                    Price       = 3.99M
                }
                    );
                context.SaveChanges();
            }
        }
Esempio n. 15
0
 /// <summary>
 /// Returns a customer
 /// </summary>
 /// <param name="phoneNumber"></param>
 /// <returns></returns>
 public Customer GetCustomer(string phoneNumber)
 {
     try
     {
         using (var movieContext = new MovieAppContext())
         {
             var customer = movieContext.Customers.Single(customer => customer.PhoneNumber == phoneNumber);
             return(customer);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 16
0
 /// <summary>
 /// Gets movieId from movietitle.
 /// </summary>
 /// <param name="movieTitle"></param>
 /// <returns></returns>
 public int GetMovieId(string movieTitle)
 {
     try
     {
         using (var movieContext = new MovieAppContext())
         {
             var movieId = movieContext.Movies.First(movie => movie.Title == movieTitle).Id;
             return(movieId);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 17
0
 /// <summary>
 /// Checks if the customer exists in the database
 /// </summary>
 /// <param name="phoneNumber"></param>
 /// <returns></returns>
 public bool CustomerExists(string phoneNumber)
 {
     using (var movieContext = new MovieAppContext())
     {
         try
         {
             var customer = movieContext.Customers.Single(customer => customer.PhoneNumber == phoneNumber);
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Esempio n. 18
0
        /// <summary>
        /// Gets the filepath for the correct image on a certain movie.
        /// </summary>
        /// <param name="movieId"></param>
        /// <returns></returns>
        public string GetMovieImagePath(int movieId)
        {
            using (var movieContext = new MovieAppContext())
            {
                try
                {
                    var moviePath = movieContext.Movies.First(movie => movie.Id == movieId).FilePath;

                    return(moviePath);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Function that returns a list of all tickets for one movie in one show time
        /// </summary>
        /// <param name="roomId"></param>
        /// <param name="showId"></param>
        /// <returns></returns>
        public List <Ticket> ListTickets(int roomId, int showId)
        {
            using (var movieContext = new MovieAppContext())
            {
                try
                {
                    var listOfTickets = movieContext.Tickets.Where(ticket => ticket.RoomId == roomId)
                                        .Where(ticket => ticket.ShowTimeId == showId).ToList();

                    return(listOfTickets);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Function that count the amount of seats for one booking.
        /// </summary>
        /// <param name="bookingId"></param>
        /// <returns></returns>
        public int AmountOfTicketOneBooking(int bookingId)
        {
            using (var movieContext = new MovieAppContext())
            {
                try
                {
                    var listOfTickets = movieContext.Tickets.Where(ticket => ticket.BookingId == bookingId).ToList();

                    int counting = listOfTickets.Count();

                    return(counting);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Returns a list of all bookings for one customer
        /// </summary>
        /// <param name="phoneNumber"></param>
        /// <returns></returns>
        public List <Booking> ListOfCustomerBookings(string phoneNumber)
        {
            using (var movieContext = new MovieAppContext())
            {
                try
                {
                    var getCustomerID = movieContext.Customers.Single(customer => customer.PhoneNumber == phoneNumber).Id;

                    var listOfBookings = movieContext.Bookings.Where(booking => booking.CustomerId == getCustomerID).ToList();

                    return(listOfBookings);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Function that returns the id for showtime
        /// </summary>
        /// <param name="bookingId"></param>
        /// <returns></returns>
        public int DisplayShowTimeId(int bookingId)
        {
            using (var movieContext = new MovieAppContext())
            {
                try
                {
                    var showTimeId = movieContext.Tickets.First(ticket => ticket.BookingId == bookingId).ShowTimeId;

                    var showTime = movieContext.ShowTimes.Single(time => time.Id == showTimeId).Id;

                    return(showTime);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Depending on which show time id, the correct show time is returned as string
        /// </summary>
        /// <param name="showNumber"></param>
        /// <returns></returns>
        public string GetShowTime(int showNumber)
        {
            try
            {
                string showTime = "";

                using (var movieContext = new MovieAppContext())
                {
                    showTime = movieContext.ShowTimes.Single(showTime => showTime.Id == showNumber)
                               .Time;
                }

                return(showTime);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Deletes customer if the customer doesn't have any bookings.
        /// </summary>
        /// <param name="phoneNumber"></param>
        public void DeleteCustomer(string phoneNumber)
        {
            using (var movieContext = new MovieAppContext())
            {
                try
                {
                    var customerList = movieContext.Customers.Where(customer => customer.PhoneNumber == phoneNumber).ToList();

                    foreach (var customer in customerList)
                    {
                        movieContext.Customers.Remove(customer);
                    }
                    movieContext.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Gets the description of the movie
        /// </summary>
        /// <param name="movieID"></param>
        /// <returns></returns>
        public string GetMovieDescr(int movieID)
        {
            try
            {
                string movieDescr = "";
                using (var movieContext = new MovieAppContext())
                {
                    var movieList = movieContext.Movies.Where(movie => movie.Id == movieID).ToList();

                    foreach (var movie in movieList)
                    {
                        movieDescr = movie.Description;
                    }
                }
                return(movieDescr);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Gets movietitle from movieId
        /// </summary>
        /// <param name="movieId"></param>
        /// <returns></returns>
        public string GetMovieTitle(int movieId)
        {
            try
            {
                string movieTitle = "";
                using (var movieContext = new MovieAppContext())
                {
                    var movieList = movieContext.Movies.Where(movie => movie.Id == movieId).ToList();

                    foreach (var movie in movieList)
                    {
                        movieTitle = movie.Title;
                    }
                }
                return(movieTitle);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 27
0
        /// <summary>
        /// Returns customer name
        /// </summary>
        /// <param name="bookingId"></param>
        /// <returns></returns>
        public string GetCustomerName(int bookingId)
        {
            try
            {
                using (var movieContext = new MovieAppContext())
                {
                    var customerId = movieContext.Bookings.First(booking => booking.Id == bookingId).CustomerId;

                    var firstName = movieContext.Customers.First(customer => customer.Id == customerId).FirstName;
                    var lastName  = movieContext.Customers.First(customer => customer.Id == customerId).LastName;

                    var name = firstName + " " + lastName;

                    return(name);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Function that returns a list of ticket seat numbers for one booking.
        /// </summary>
        /// <param name="bookingId"></param>
        /// <returns></returns>
        public List <int> ListOfTicketsOneBooking(int bookingId)
        {
            var listToReturn = new List <int>();

            using (var movieContext = new MovieAppContext())
            {
                try
                {
                    var listOfTickets = movieContext.Tickets.Where(ticket => ticket.BookingId == bookingId).ToList();

                    foreach (var ticketNumber in listOfTickets)
                    {
                        listToReturn.Add(ticketNumber.SeatNumber);
                    }

                    return(listToReturn);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Function that sets the bookingId on tickets to correct id.
        /// </summary>
        /// <param name="bookedSeats"></param>
        /// <param name="room"></param>
        /// <param name="showTime"></param>
        /// <param name="phoneNumber"></param>
        public void BookTickets(List <int> bookedSeats, int room, int showTime, string phoneNumber)
        {
            using (var movieContext = new MovieAppContext())
            {
                try
                {
                    var listOfTickets = movieContext.Tickets.Where(ticket => ticket.RoomId == room)
                                        .Where(ticket => ticket.ShowTimeId == showTime)
                                        .ToList();

                    var customer = movieContext.Customers.Single(customer => customer.PhoneNumber == phoneNumber);

                    movieContext.Bookings.Add(new Booking {
                        MovieId = room, CustomerId = customer.Id
                    });
                    movieContext.SaveChanges();

                    var booking = movieContext.Bookings.OrderByDescending(booking => booking.Id).First();

                    foreach (var seat in bookedSeats)
                    {
                        foreach (var ticket in listOfTickets)
                        {
                            if (seat == ticket.SeatNumber)
                            {
                                ticket.BookingId = booking.Id;
                            }
                            movieContext.SaveChanges();
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Deletes the booking, if the customer has chosen to delete the booking.
        /// It deletes the row in database table "Bookings" and
        /// Sets the tickets bookingId to null
        /// </summary>
        /// <param name="bookingId"></param>
        public void DeleteBooking(int bookingId)
        {
            using (var movieContext = new MovieAppContext())
            {
                try
                {
                    var customerId = movieContext.Bookings.First(booking => booking.Id == bookingId).CustomerId;

                    var phoneNumber = movieContext.Customers.First(customer => customer.Id == customerId).PhoneNumber;

                    var tickets = movieContext.Tickets.Where(ticket => ticket.BookingId == bookingId).ToList();

                    foreach (var ticket in tickets)
                    {
                        ticket.BookingId = null;
                    }
                    var bookings = movieContext.Bookings.Where(booking => booking.Id == bookingId).ToList();

                    foreach (var booking in bookings)
                    {
                        movieContext.Bookings.Remove(booking);
                    }
                    movieContext.SaveChanges();

                    if (ListOfCustomerBookings(phoneNumber).Count == 0)
                    {
                        DeleteCustomer(phoneNumber);
                    }
                    movieContext.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }