Ejemplo n.º 1
0
        private void CreateDataAboutFilm(int id)
        {
            //Информация о выбранном дне сохраняется в HttpContext.Items["CurrentDay"]
            //По умолчанию равен дате сегодня
            var timeNow    = DateTime.Now;
            var currentDay = timeNow.Date; //new DateTime(timeNow.Year,timeNow.Month, timeNow.Day);

            if (Request.Query.ContainsKey("schedule_date"))
            {
                currentDay = DateTime.ParseExact(
                    Request.Query["schedule_date"],
                    "dd.MM.yyyy", CultureInfo.InvariantCulture);
            }
            HttpContext.Items["CurrentDay"] = currentDay;

            var film = FilmViewModelDAO.GetFilms($"WHERE id = {id}", false).FirstOrDefault();

            FilmViewModel = film;

            FilmViewModel.Actors    = FilmViewModelDAO.GetActorsByFilmId(FilmViewModel.Id);
            FilmViewModel.Producers = FilmViewModelDAO.GetProducersByFilmId(FilmViewModel.Id);
            FilmViewModel.Country   = FilmViewModelDAO.GetCounrtyById(FilmViewModel.CountryId);
            FilmViewModel.Reviews   = FilmViewModelDAO.GetReviewByFilmId(FilmViewModel.Id);
            FilmViewModel.Schedule  = ScheduleDAO.GetSchedule($"id_movie={id} AND date::DATE = '{currentDay:yyyy-MM-dd}'");
        }
Ejemplo n.º 2
0
        private void CreateFilmsList(int page, string genre_filter, string search, string sortby)
        {
            var whereStatement = new StringBuilder("WHERE is_rent = 1");
            var parameters     = new List <NpgsqlParameter>();

            if (!string.IsNullOrWhiteSpace(search))
            {
                whereStatement.Append(" AND LOWER(title) LIKE '%' || @title || '%'");
                parameters.Add(new NpgsqlParameter("title", search.ToLower()));
            }

            if (!string.IsNullOrWhiteSpace(sortby))
            {
                whereStatement.Append(" ORDER BY");
                switch (sortby)
                {
                case "date": whereStatement.Append(" release_year");
                    break;

                case "rating": whereStatement.Append(" raiting");
                    break;
                }

                whereStatement.Append(" DESC");
            }

            var films = FilmViewModelDAO.GetFilms(whereStatement.ToString(), false, parameters.ToArray());

            if (!string.IsNullOrWhiteSpace(genre_filter))
            {
                var genres = genre_filter.Split(',')
                             .Select(genre => genre.Trim().ToLower())
                             .ToHashSet();

                films = films
                        .Where(film => film.Genres
                               .Any(genre => genres.Contains(genre)))
                        .ToList();
            }

            var filmsPerPage = 10;
            var totalPages   = films.Count / filmsPerPage + (films.Count % filmsPerPage > 0 ? 1 : 0);

            FilmsViewModel = new FilmsViewModel(
                films.Skip(filmsPerPage * (page - 1)).Take(filmsPerPage),
                page,
                totalPages);
        }
Ejemplo n.º 3
0
        private void CreateDataMainModel()
        {
            MainModel = new MainViewModel
            {
                //В TopFilms Берем N лучших по рейтингу фильмов
                TopFilms = FilmViewModelDAO.GetFilms("WHERE is_rent = 1 ORDER BY raiting DESC LIMIT 6", true),
                //В TodayFilms берем фильмы, у которых есть хотя бы 1 сеанс сегодня
                TodayFilms = FilmViewModelDAO.GetFilms("WHERE is_rent = 1 AND EXISTS (SELECT 1 FROM schedule WHERE id_movie = id " +
                                                       "AND(date::DATE = CURRENT_TIMESTAMP::DATE))", false)
            };

            var schedule = DAOFactory.GetIdFilmWithSchedule(DateTime.Now);

            foreach (var film in MainModel.TodayFilms)
            {
                film.Schedule = schedule[film.Id];
            }
            ;
        }
Ejemplo n.º 4
0
 public IActionResult OnGet(int id)
 {
     UserViewModel          = UserDAO.GetUserById(id);
     UserViewModel.Bookings = BookingDAO.GetBookingsByUserId(id);
     foreach (var booking in UserViewModel.Bookings)
     {
         booking.Schedule      = ScheduleDAO.GetSchedule($"id_schedule = {booking.ScheduleId}").FirstOrDefault();
         booking.Schedule.Hall = ScheduleDAO.GetHallByScheduleId(booking.Schedule.Id);
         booking.Schedule.Film = FilmViewModelDAO.GetFilms($"WHERE id = {booking.Schedule.FilmId}", false).FirstOrDefault();
         if (booking.Row == 0)
         {
             booking.Schedule.PricePerSeat /= 2;
         }
         else if (booking.Row == booking.Schedule.Hall.SeatsRowCount.Length - 1)
         {
             booking.Schedule.PricePerSeat = Math.Round(booking.Schedule.PricePerSeat * (decimal)1.2);
         }
     }
     return(Page());
 }
Ejemplo n.º 5
0
        private void CreateListFilmsByDate()
        {
            //Тоже самое что и на странице фильмов с расписанием
            var dateNow = DateTime.Now;
            var date    = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day);

            if (Request.Query.ContainsKey("schedule_date"))
            {
                date = DateTime.ParseExact(
                    Request.Query["schedule_date"],
                    "dd.MM.yyyy", CultureInfo.InvariantCulture);
            }
            HttpContext.Items["CurrentDay"] = date;

            var scheduleCurrent = DAOFactory.GetIdFilmWithSchedule(date);

            //Передаем во View только те фильмы, которые имеют хотя бы один сеанс на выбранную дату date
            Films = FilmViewModelDAO.GetFilms(
                string.Format("WHERE id IN (SELECT id_movie FROM schedule WHERE date::DATE = '{0}')", date.ToString("yyyy-MM-dd")), false);
            foreach (var film in Films)
            {
                film.Schedule = scheduleCurrent[film.Id];
            }
        }