public IList<PerformanceModelDTO> GetPerformances(Guid theaterId)
        {
            IList<PerformanceModelDTO> performancesList = new List<PerformanceModelDTO>();

                            using (var context = new CinemaEntities())
                            {
                                var performances = (from performance in context.Perfomances.Include("Room")
                                                                        where performance.TheaterID == theaterId
                                                                        select performance).ToList();

                                foreach (var perform in performances)
                                {
                                    var performanceRow = new PerformanceModelDTO();
                                    performanceRow.PerformanceID = perform.PerfomanceID;
                                    string date = perform.Date.ToString("yyyy'/'MM'/'dd");
                                    performanceRow.Date = date;//(DateTime)perform.Date;
                                    TimeSpan time = (TimeSpan)perform.StartingTime;
                                    performanceRow.StartingTime = string.Format("{0:hh\\:mm}", time);// (TimeSpan)perform.StartingTime;
                                    performanceRow.Title = perform.Movie.Title;
                                    performanceRow.Price = perform.Price;
                                    performanceRow.RoomNumber = perform.Room.RoomNumber;
                                    performanceRow.Duration = perform.Duration; ;
                                    performancesList.Add(performanceRow);

                                }
                            }
                                return performancesList;
        }
Esempio n. 2
0
        public List<MovieModelDTO> GetAllGenres()
        {
            using (var context = new CinemaEntities())
            {
                var allGenre = (from genre in context.Genres
                                select new
                                {

                                    GenreName = genre.Name

                                }).ToList();

                List<MovieModelDTO> allGenresToReturn = new List<MovieModelDTO>();

                if (allGenre != null)
                {

                    foreach (var item in allGenre)
                    {
                        MovieModelDTO genreRow = new MovieModelDTO()
                        {
                            GenreName = item.GenreName
                        };
                        allGenresToReturn.Add(genreRow);
                    }

                    return allGenresToReturn;
                }
                else
                {
                    return null;
                }

            }
        }
Esempio n. 3
0
        //Method that gets all Comments of specific user
        public IList<UserCommentDTO> GetAllUserComments(System.Guid userID)
        {
            IList<UserCommentDTO> ListOfComments = new List<UserCommentDTO>();

            using (var context = new CinemaEntities())
            {
                var results = (from com in context.Comments.Include("Movie")
                               where com.UserID == userID
                               select com);

                if (results!=null)
                {
                    foreach (var item in results)
                    {
                        UserCommentDTO row = new UserCommentDTO();
                        row.userID = userID.ToString();
                        row.commentID = item.CommentID;
                        row.movieID = item.MovieID;
                        row.Content = item.Content;
                        row.MovieTitle = item.Movie.Title;
                        ListOfComments.Add(row);
                    }
                }
            }

            return ListOfComments;
        }
Esempio n. 4
0
        public List<MovieModelDTO> GetAllMovies()
        {
            using (var context = new CinemaEntities())
            {
                var allMovies = (from movie in context.Movies
                                 select new
                                 {
                                     MovieId = movie.MovieID,
                                     Title = movie.Title

                                 }).ToList();
                List<MovieModelDTO> allMoviesToReturn = new List<MovieModelDTO>();
                if (allMovies != null)
                {

                    foreach (var item in allMovies)
                    {
                        MovieModelDTO movieRow = new MovieModelDTO()
                        {
                            MovieID = item.MovieId,
                            Tilte = item.Title
                        };
                        allMoviesToReturn.Add(movieRow);
                    }

                    return allMoviesToReturn;
                }
                else
                {
                    return null;
                }

            }
        }
Esempio n. 5
0
        //Method that gets all Ratings for specific user
        public IList<UserRatingDTO> GetAllUserRatings(Guid userID)
        {
            IList<UserRatingDTO> ListOfRatings = new List<UserRatingDTO>();

            using (var context = new CinemaEntities())
            {
                var results = (from rt in context.Ratings.Include("Movie")
                               where rt.UserID == userID
                               select rt);

                if (results != null)
                {
                    foreach (var item in results)
                    {
                        UserRatingDTO row = new UserRatingDTO();
                        row.ratingID = item.RatingID;
                        row.userID = userID.ToString();
                        row.movieID = item.MovieID;
                        row.MovieTitle = item.Movie.Title;
                        row.rate = item.Rate;
                        ListOfRatings.Add(row);
                    }
                }
            }

            return ListOfRatings;
        }
 // Method gets movie Id and type of movie person ("Actor", "Director" etc..) and return list of people
 public List<MoviePersonDTO> GetMoviePeopleByMovieId(int movieId, string personType)
 {
     using (var context = new CinemaEntities())
     {
         var moviePeople = (from moviePerson in context.PersonMovies
                          //  where moviePerson.MovieID == movieId && moviePerson.Person.PersonType.Description.Contains("actor")
                            where moviePerson.MovieID == movieId && moviePerson.Person.PersonType.Description == personType
                            select moviePerson).ToList();
         if (moviePeople.Count() > 0)
         {
             List<MoviePersonDTO> moviePeopleToReturn = new List<MoviePersonDTO>();
             foreach (var item in moviePeople)
             {
                 MoviePersonDTO moviePeopleRow = new MoviePersonDTO()
                 {
                     FirstName = item.Person.FirstName,
                     LastName = item.Person.LastName,
                     BirthDate = (DateTime)item.Person.BirthDate,
                     BirthPlace = item.Person.BirthPlace
                 };
                 moviePeopleToReturn.Add(moviePeopleRow);
             }
             return moviePeopleToReturn;
         }
         else
         {
             return null;
         }
     }
 }
        //get list of actors for ddlActorMovie MainMovie.aspx
        public List<MoviePersonDTO> GetActors()
        {
            using (var context = new CinemaEntities())
            {
                string cast = "actor";

                var listmoviePeople = (from moviePerson in context.PersonMovies
                                       where moviePerson.Person.PersonType.Description == cast
                                       select moviePerson).ToList();

                if (listmoviePeople.Count() > 0)
                {
                    List<MoviePersonDTO> moviePeopleToReturn = new List<MoviePersonDTO>();
                    foreach (var item in listmoviePeople)
                    {
                        MoviePersonDTO moviePeopleRow = new MoviePersonDTO()
                        {

                            FirstName = item.Person.FirstName + " " + item.Person.LastName, //Fiction for getting a person full name into a drop
                            LastName = item.Person.LastName,                              // down list (Marat)
                        };
                        moviePeopleToReturn.Add(moviePeopleRow);
                    }
                    return moviePeopleToReturn;
                }
                else
                {
                    return null;
                }
            }
        }
Esempio n. 8
0
        public List<MovieModelDTO> GetAllMovies()
        {
            using (var context = new CinemaEntities())
            {
                var allMovies = (from movie in context.Movies
                                 select new
                                 {
                                    MovieID = movie.MovieID,
                                     Title = movie.Title,
                                     Photo=movie.Photo,//added by Elena for RepeaterMovie MovieMain.aspx
                                    Description=movie.Description//

                                 }).ToList();

                List<MovieModelDTO> allMoviesToReturn = new List<MovieModelDTO>();
                if (allMovies != null)
                {

                    foreach (var item in allMovies)
                    {
                        MovieModelDTO movieRow = new MovieModelDTO()
                        {

                            MovieID = item.MovieID,
                            Title = item.Title,
                            //Photo=item.Photo,
                            Description=item.Description,
                            Photo = (byte[])item.Photo

                        };

                        allMoviesToReturn.Add(movieRow);
                    }

                    return allMoviesToReturn;
                }
                else
                {
                    return null;
                }

                //byte[] buffer = binary.ToArray();
                //MemoryStream stream = new MemoryStream(buffer);
                //BitmapImage image = new BitmapImage();
                //image.BeginInit();
                //image.StreamSource = stream;
                //image.EndInit();
                //return image;

            }
        }
        // Method gets movie Id and type of movie person ("Actor", "Director" etc..) and return list of people
        public List<MoviePersonDTO> GetMoviePeopleByMovieId(int movieId, string personType)
        {
            using (var context = new CinemaEntities())
            {
                var moviePeople = (from moviePerson in context.PersonMovies
                                   //  where moviePerson.MovieID == movieId && moviePerson.Person.PersonType.Description.Contains("actor")
                                   where moviePerson.MovieID == movieId && moviePerson.Person.PersonType.Description == personType
                                   select moviePerson).ToList();
                if (moviePeople.Count() > 0)
                {
                    List<MoviePersonDTO> moviePeopleToReturn = new List<MoviePersonDTO>();
                    foreach (var item in moviePeople)
                    {
                        MoviePersonDTO moviePeopleRow = new MoviePersonDTO();

                        moviePeopleRow.FirstName = item.Person.FirstName;
                        moviePeopleRow.LastName = item.Person.LastName;
                        if (item.Person.BirthDate == null)
                        {
                            DateTime unavailableDateOfBirth = DateTime.ParseExact("01/01/9999", "d/MM/yyyy", null);
                            moviePeopleRow.BirthDate = unavailableDateOfBirth;
                        }

                        else
                        {
                            moviePeopleRow.BirthDate = (DateTime)item.Person.BirthDate;
                        }
                        //  moviePeopleRow.BirthDate = (DateTime)item.Person.BirthDate;

                        if (item.Person.BirthPlace == null)
                        {
                            moviePeopleRow.BirthPlace = "Unknown";
                        }
                        else
                        {
                            moviePeopleRow.BirthPlace = item.Person.BirthPlace;
                        }

                        moviePeopleToReturn.Add(moviePeopleRow);
                    }
                    return moviePeopleToReturn;
                }
                else
                {
                    return null;
                }
            }
        }
Esempio n. 10
0
 public IList<String> GetCities()
 {
     IList<String> citiesList = new List<String>();
     using (var context = new CinemaEntities())
     {
         var cities = (from ct in context.Addresses
                                     select new { City = ct.City }).Distinct();
         foreach (var item in cities)
         {
             String cityRow = null;
             cityRow = item.City;
             citiesList.Add(cityRow);
         }
     }
     return citiesList;
 }
Esempio n. 11
0
        public IList<PerformanceModelDTO> GetPerformances(Guid theaterId)
        {
            IList<PerformanceModelDTO> performancesList = new List<PerformanceModelDTO>();
            IList<RoomModelDTO>roomsList=new List<RoomModelDTO>();

            using (var context1 = new CinemaEntities())
            {
                var rooms = (from room in context1.Rooms
                                         where room.TheaterID == theaterId
                                         select room).ToList();

                if (rooms.Count > 0)
                {
                    foreach (var room in rooms)
                    {
                        var roomRow = new RoomModelDTO();
                        roomRow.RoomNumber = room.RoomID;
                        roomRow.RoomNumber = room.RoomNumber;
                        roomsList.Add(roomRow);

                        if (roomsList != null)
                        {
                            using (var context = new CinemaEntities())
                            {
                                var performances = (from performance in context.Perfomances
                                                                        where performance.TheaterID == theaterId
                                                                        select performance).ToList();

                                foreach (var perform in performances)
                                {
                                    var performanceRow = new PerformanceModelDTO();
                                    performanceRow.PerformanceID = perform.PerfomanceID;
                                    performanceRow.Tilte = perform.Movie.Title;
                                    performanceRow.Price = perform.Price;
                                    //performanceRow.Room.RoomNumber = perform.Room.RoomNumber;
                                    performanceRow.Duration = perform.Duration; ;
                                    performancesList.Add(performanceRow);

                                }
                            }
                        }

                    }

                }
            } return performancesList;
        }
Esempio n. 12
0
        public TheaterModelDTO GetTheater(Guid theaterId)
        {
            Theater spesificTheater = new Theater();

            using (var context = new CinemaEntities())
            {
                spesificTheater = (from theater in context.Theaters
                                                     where theater.TheaterID == theaterId
                                                     select theater).FirstOrDefault();
            }

            TheaterModelDTO theaterToReturn = new TheaterModelDTO();
            theaterToReturn.TheaterID = spesificTheater.TheaterID;
            theaterToReturn.Name = spesificTheater.Name;

            return theaterToReturn;
        }
Esempio n. 13
0
        public String GetTheater(Guid theaterId)
        {
            String TheaterName = null;

            using (var context = new CinemaEntities())
            {
                var results = (from theater in context.Theaters
                                                     where theater.TheaterID == theaterId
                                                     select theater);
                foreach (var item in results)
                {
                    TheaterName = item.Name;
                }
            }

            return TheaterName;
        }
Esempio n. 14
0
        public IList<TheaterModelDTO> GetTheaters(string city)
        {
            IList<TheaterModelDTO> theaterList = new List<TheaterModelDTO>();
            IList<Addresses.AddressModelDTO> addressList = new List<Addresses.AddressModelDTO>();
            using (var context = new CinemaEntities())
            {
                var adddresses = (from address in context.Addresses
                                                    where address.City == city
                                                    select address).ToList();
                if (adddresses.Count > 0)
                {
                    foreach (var address in adddresses)
                    {
                        var addressRow = new Addresses.AddressModelDTO();
                        addressRow.AddressID = address.AddressID;
                        addressRow.ObjectID = address.ObjectID;
                        addressList.Add(addressRow);

                        Guid currentTheater = addressRow.ObjectID;
                        if (addressList != null)
                        {
                            using (var context1 = new CinemaEntities())
                            {
                                var theaters = (from theater in context1.Theaters
                                                                where theater.TheaterID == currentTheater
                                                                select theater).ToList();

                                if (theaters.Count>0)
                                {
                                    foreach (var theater in theaters)
                                    {
                                        var theaterRow = new TheaterModelDTO();
                                        theaterRow.Name = theater.Name;
                                        theaterRow.TheaterID = theater.TheaterID;
                                        theaterList.Add(theaterRow);

                                    }
                                }
                            }
                        }
                    }
                }
            }
            return theaterList;
        }
Esempio n. 15
0
        //public IList<String> GetCities()
        //{
        //  List<String> citiesList = new List<String>();
        //  using (var context = new CinemaEntities())
        //  {
        //    var cities = (from city in context.Addresses
        //                  where city.ObjectType.Description == "Theater"
        //                  select city).ToList();
        //    if (cities.Count > 0)
        //    {
        //      foreach (var city in cities)
        //      {
        //        AddressModelDTO cityRow = new AddressModelDTO();
        //        cityRow.City = city.City;
        //        citiesList.Add(cityRow);
        //      }
        //    }
        //    return citiesList;
        //  }
        //}
        public IList<AddressModelDTO> GetCities()
        {
            IList<AddressModelDTO> citiesList = new List<AddressModelDTO>();
            using (var context = new CinemaEntities())
            {
                var cities = (from city in context.Addresses
                                            where city.ObjectType.Description == "Theater"
                                            select city).ToList();
                if (cities.Count > 0)
                {
                    foreach (var city in cities)
                    {
                        var cityRow = new AddressModelDTO();
                        cityRow.City = city.City;
                        citiesList.Add(cityRow);
                        List<AddressModelDTO> newCitiesList = new List<AddressModelDTO>();

                        foreach (var item in citiesList)
                        {
                            if (!newCitiesList.Contains(item))
                            { newCitiesList.Add(item);}

                        }

                        //if (citiesList != null)
                        //{
                        //  foreach (var cit in citiesList)
                        //  {
                        //    if (cit.City != cityRow.City)
                        //    { citiesList.Add(cityRow); }

                        //  //if (cityRow.City != city.City)
                        //  //{
                        //  //  citiesList.Add(cityRow);
                        //  //}
                        //    else
                        //    {
                        //      return citiesList;
                        //    }
                    }
                }
            }
            return citiesList;
        }
Esempio n. 16
0
        //Method that gets all Favorite movies of a specific user
        public IList<UserFavoriteMovieDTO> GetFavoriteMoviesByUser(Guid userID)
        {
            IList<UserFavoriteMovieDTO> ListOfMovies = new List<UserFavoriteMovieDTO>();

            using (var context = new CinemaEntities())
            {
                var results = (from fv in context.Favorites.Include("Movie")
                               where fv.UserID == userID
                               select fv);

                foreach (var item in results)
                {
                    UserFavoriteMovieDTO row = new UserFavoriteMovieDTO();
                    row.userID = userID.ToString();
                    row.movieID = item.MovieID;
                    row.MovieTitle = item.Movie.Title;
                    ListOfMovies.Add(row);
                }
            }

            return ListOfMovies;
        }
Esempio n. 17
0
        public AddressModelDTO GetAddress(Guid objectId)
        {
            Address spesificAddress = new Address();

            using (var context = new CinemaEntities())
            {
                spesificAddress = (from address in context.Addresses
                                                     where address.ObjectID == objectId
                                                     select address).FirstOrDefault();
            }

            AddressModelDTO addressToReturn = new AddressModelDTO();
            addressToReturn.AddressID = spesificAddress.AddressID;
            addressToReturn.AddressLine1 = spesificAddress.AddressLine1;
            addressToReturn.City = spesificAddress.City;
            addressToReturn.PostalCode = spesificAddress.PostalCode;
            addressToReturn.Province = spesificAddress.Province;
            addressToReturn.Country = spesificAddress.Country;
            addressToReturn.Phone = spesificAddress.Phone;
            addressToReturn.Email = spesificAddress.Email;

            return addressToReturn;
        }
Esempio n. 18
0
        public MovieModelDTO GetMovieByID(int movieID)
        {
            MovieModelDTO SelectedMovie = new MovieModelDTO();

            using (var context = new CinemaEntities())
            {
                var results = (from mv in context.Movies.Include("Genre")
                               where mv.MovieID == movieID
                               select mv);

                if (results != null)
                {
                    foreach (var item in results)
                    {
                        SelectedMovie.MovieID = item.MovieID;
                        SelectedMovie.Title = item.Title;
                        SelectedMovie.GenreName = item.Genre.Name;
                        SelectedMovie.Description = item.Description;
                        SelectedMovie.Year = item.Year;
                    }
                }
            }

            return SelectedMovie;
        }
Esempio n. 19
0
        //Method that gets Movie description
        public String GetMovieDescriptionByMovieID(int movieID)
        {
            String Description = null;
            using (var context = new CinemaEntities())
            {
                var results = (from mv in context.Movies
                               where mv.MovieID == movieID
                               select mv);
                if (results != null)
                {
                    foreach (var item in results)
                    {
                        Description = item.Description;
                    }
                }

            }
            return Description;
        }
Esempio n. 20
0
        //Method that gets list of movies to which the specific user commented
        public IList<String> GetMoviesToWhichTheUserCommented(Guid userID)
        {
            IList<String> ListOfMovies = new List<String>();

            using (var context = new CinemaEntities())
            {
                var results = (from cm in context.Comments
                               where cm.UserID == userID
                               select new
                               {
                                   MovieName = cm.Movie.Title
                               });
                if (results != null)
                {
                    results = results.Distinct();
                    foreach (var item in results)
                    {
                        String row = item.MovieName;
                        ListOfMovies.Add(row);

                    }
                }
            }

            return ListOfMovies;
        }
Esempio n. 21
0
        //Method that gets Performance info by its ID
        public UserPerformanceDTO GetPerformanceByID(int performanceID)
        {
            UserPerformanceDTO CurrentPerformance = new UserPerformanceDTO();

            using (var context = new CinemaEntities())
            {
                var results = (from pr in context.Perfomances.Include("Theater").Include("Movie").Include("Room")
                               where pr.PerfomanceID == performanceID
                               join ad in context.Addresses
                               on pr.TheaterID equals ad.ObjectID
                               where ad.ObjectType.Description == "Theater"
                               select new
                               {
                                   PerformanceOut = pr,
                                   AddressOut = ad
                               });
                if (results != null)
                {
                    foreach (var item in results)
                    {
                        CurrentPerformance = new UserPerformanceDTO();
                        CurrentPerformance.performanceID = performanceID;
                        CurrentPerformance.TheaterName = item.PerformanceOut.Theater.Name;
                        CurrentPerformance.Date = item.PerformanceOut.Date.ToString("yyy/MM/dd");
                        CurrentPerformance.Duration = item.PerformanceOut.Duration;
                        string hour = item.PerformanceOut.StartingTime.Hours.ToString();
                        if (hour.Length < 2)
                        {
                            hour = string.Format("{0}{1}", "0", hour);
                        }
                        string minutes = item.PerformanceOut.StartingTime.Minutes.ToString();
                        CurrentPerformance.StartingTime = string.Format("{0}:{1}", hour, minutes);
                        CurrentPerformance.price = item.PerformanceOut.Price;
                        CurrentPerformance.MovieTitle = item.PerformanceOut.Movie.Title;
                        CurrentPerformance.roomNumber = item.PerformanceOut.Room.RoomNumber;
                        string street = item.AddressOut.AddressLine1;
                        if (item.AddressOut.AddressLine2 != null)
                        {
                            street = string.Format("{0}, {1}", item.AddressOut.AddressLine1, item.AddressOut.AddressLine2);
                        }
                        string phone = item.AddressOut.Phone;
                        CurrentPerformance.TheaterAddress = string.Format("{0}, Phone: {1}", street, phone);

                    }
                }
            }

            return CurrentPerformance;
        }
Esempio n. 22
0
        //Method that gets the theaters by City
        public IList<UserTheaterDTO> GetTheatersByCity(String City, int movieID)
        {
            IList<UserTheaterDTO> ListOfTheaters = new List<UserTheaterDTO>();
            using (var context = new CinemaEntities())
            {
                var results = (from pr in context.Perfomances.Include("Theater")
                               join ad in context.Addresses.Include("ObjectType")
                               on pr.TheaterID equals ad.ObjectID
                               where pr.MovieID == movieID
                               where ad.City == City
                               where ad.ObjectType.Description == "Theater"
                               select new
                               {
                                   TheaterID = pr.TheaterID,
                                   TheaterName = pr.Theater.Name,
                                   AddressTh = ad
                               });
                if (results != null)
                {
                    foreach (var item in results)
                    {
                        UserTheaterDTO row = new UserTheaterDTO();
                        row.TheaterID = item.TheaterID;
                        row.TheaterName = item.TheaterName;
                        row.TheaterAddress = String.Format("str. {0}, {1}, phone number: {2}.", item.AddressTh.AddressLine1, item.AddressTh.City, item.AddressTh.Phone);
                        ListOfTheaters.Add(row);
                    }
                }

            }
            return ListOfTheaters;
        }
Esempio n. 23
0
 //Method that gets Performances by Theater
 public IList<UserPerformanceDTO> GetPerformancesByTheaterIDandMovieID(Guid TheaterID, int movieID)
 {
     IList<UserPerformanceDTO> ListOfPerformances = new List<UserPerformanceDTO>();
     using (var context = new CinemaEntities())
     {
         var results = (from pr in context.Perfomances.Include("Movie").Include("Theater")
                        where pr.TheaterID == TheaterID && pr.MovieID == movieID
                        select pr);
         if (results != null)
         {
             foreach (var item in results)
             {
                 UserPerformanceDTO row = new UserPerformanceDTO();
                 row.performanceID = item.PerfomanceID;
                 row.MovieTitle = item.Movie.Title;
                 row.roomNumber = item.Room.RoomNumber;
                 row.Date = item.Date.ToString("yyyy/MM/dd");
                 string hours = item.StartingTime.Hours.ToString();
                 if (hours.Length < 2)
                 {
                     hours = string.Format("{0}{1}", "0", hours);
                 }
                 string minutes = item.StartingTime.Minutes.ToString();
                 row.StartingTime = string.Format("{0}:{1}", hours, minutes);
                 row.Duration = item.Duration;
                 row.price = item.Price;
                 ListOfPerformances.Add(row);
             }
         }
     }
     return ListOfPerformances;
 }
Esempio n. 24
0
        //Method that get user type by description
        public int GetUserType(String Description)
        {
            int type = 0;
            using (var context = new CinemaEntities())
            {
                var results = (from pt in context.PersonTypes
                               where pt.Description == Description
                               select pt);
                if (results != null)
                {
                    foreach (var item in results)
                    {
                        type = item.PersonType1;

                    }
                }
            }
            return type;
        }
Esempio n. 25
0
        //Method that gets UserID during the login
        public Guid GetUserID(String UserName)
        {
            Guid UserID = new Guid();

            using (var context = new CinemaEntities())
            {
                var results = (from usr in context.aspnet_Users
                               where usr.UserName == UserName
                               select usr);
                if (results != null)
                {
                    foreach (var item in results)
                    {
                        UserID = item.UserId;
                    }

                }
                return UserID;

            }
        }
Esempio n. 26
0
        //Method that deletes movie from favorite list
        public bool RemoveMovieFromFavoriteList(Guid UserID, string movieTitle)
        {
            bool check;
            using (TransactionScope Trans = new TransactionScope())
            {
                try
                {
                    using (var context = new CinemaEntities())
                    {
                        var results = (from fv in context.Favorites.Include("Movie")
                                       where fv.Movie.Title == movieTitle &&
                                       fv.UserID == UserID
                                       select fv);
                        if (results != null)
                        {
                            Favorite LineToDelete = (Favorite)results.First();
                            context.Favorites.DeleteObject(LineToDelete);
                            context.SaveChanges();
                        }
                    }
                }
                catch
                {
                    check = false;
                    Trans.Dispose();
                    return check;
                }

                check = true;
                Trans.Complete();
                return check;
            }
        }
Esempio n. 27
0
 //---Method that extracts movie photo
 public Byte[] GetPhoto(int movieId)
 {
     byte[] photo = null;
     using (var context = new CinemaEntities())
     {
         var result = (from image in context.Movies
                       where image.MovieID == movieId
                       select image).SingleOrDefault();
         if (result == null)
         {
             return null;
         }
         photo = result.Photo;
         //foreach (var item in result)
         //{
         //photo = item.Photo;
         //}
     }
     return photo;
 }
Esempio n. 28
0
        //Method that updates comment
        public bool UpdateComment(UserCommentDTO UpdatedComment)
        {
            bool check = false;
            using (TransactionScope Trans = new TransactionScope())
            {
                try
                {
                    using (var context = new CinemaEntities())
                    {
                        var results = (from cm in context.Comments
                                       where cm.CommentID == UpdatedComment.commentID
                                       select cm);
                        if (results != null)
                        {
                            Comment CommentToUpdate = new Comment();
                            CommentToUpdate = (Comment)results.First();
                            CommentToUpdate.Content = UpdatedComment.Content;
                            context.ObjectStateManager.ChangeObjectState(CommentToUpdate, System.Data.EntityState.Modified);
                            context.SaveChanges();
                        }
                    }

                }
                catch
                {
                    check = false;
                    Trans.Dispose();
                    return check;
                }

                check = true;
                Trans.Complete();
                return check;
            }
        }
Esempio n. 29
0
        //Method that submits the order
        public UserOrderDTO CreateOrder(UserOrderDTO NewOrder)
        {
            UserOrderDTO OrderOut = new UserOrderDTO();
            Order OrderIn = new Order();

            using (TransactionScope Trans = new TransactionScope())
            {
                try
                {
                    using (var context = new CinemaEntities())
                    {
                        OrderIn.NumberOfSeatsReserved = NewOrder.NumberOfSeats;
                        OrderIn.TotalPrice = NewOrder.TotalPrice;
                        OrderIn.UserID = NewOrder.UserID;
                        OrderIn.PerfomanceID = NewOrder.PerformanceID;

                        if (OrderIn.EntityState == EntityState.Detached)
                        {
                            context.Orders.AddObject(OrderIn);
                        }
                        context.SaveChanges();

                        OrderOut.OrderID = OrderIn.OrderID;
                    }
                }
                catch
                {
                    OrderOut.isValid = false;
                    Trans.Dispose();
                    return OrderOut;
                }
                OrderOut.isValid = true;
                Trans.Complete();
                return OrderOut;
            }
        }
Esempio n. 30
0
        public List<MovieModelDTO> GetAllYears()
        {
            using (var context = new CinemaEntities())
            {
                var allYears = (from movie in context.Movies
                                orderby movie.Year ascending
                                select new
                                {
                                    MovieId = movie.MovieID,
                                    Year = movie.Year

                                }).ToList();

                List<MovieModelDTO> allYearsToReturn = new List<MovieModelDTO>();

                if (allYears != null)
                {

                    foreach (var item in allYears)
                    {
                        MovieModelDTO yearRow = new MovieModelDTO()
                        {
                            MovieID = item.MovieId,
                            Year = item.Year
                        };

                        allYearsToReturn.Add(yearRow);
                    }

                    return allYearsToReturn;
                }
                else
                {
                    return null;
                }

            }
        }