Пример #1
0
        public IActionResult Index()
        {
            var userId = "001122";

            ViewBag.Title = "Rentals";
            var model = _base_repository_rental.GetAll(x => x.Include(y => y.MovieRentals).ThenInclude(y => y.Movie).Where(x => x.UserId == userId));

            return(View(model));
        }
Пример #2
0
        // public async Task<IEnumerable<RentalFormViewModel>> GetAll()
        // {
        //     var listRentals = new List<RentalFormViewModel>();
        //     var resultRentals = await _base_repository_rental.GetAll();
        //     if (resultRentals.Any())
        //     {
        //         foreach (var item in resultRentals)
        //         {
        //             listRentals.Add(
        //                 new RentalFormViewModel()
        //                 {
        //                     Id = item.Id,
        //                     DateRental = item.DateRental,
        //                     UserId = item.UserId
        //                 }
        //             );
        //         }
        //     }

        //     return listRentals;
        // }

        // public async Task<IEnumerable<RentalFormViewModel>> GetAllByUserId()
        // {
        //     var userId = "001122";

        //     var listRentals = new List<RentalFormViewModel>();
        //     var resultRentals = await _base_repository_rental.GetAll();
        //     var retalUser = resultRentals.Where(x => x.UserId == userId);
        //     if (resultRentals.Any())
        //     {
        //         foreach (var item in resultRentals)
        //         {
        //             listRentals.Add(
        //                 new RentalFormViewModel()
        //                 {
        //                     Id = item.Id,
        //                     DateRental = item.DateRental,
        //                     UserId = item.UserId
        //                 }
        //             );
        //         }
        //     }

        //     return listRentals;
        // }
        public async Task <RentalFormViewModel> GetRentalForm(Rental obj)
        {
            var result = new RentalFormViewModel();

            if (obj != null)
            {
                result.Id         = obj.Id;
                result.DateRental = obj.DateRental;
                result.UserId     = obj.UserId;
            }

            var resultMoviesAll = await _base_repository_movie.GetAll();

            var listMovies = new List <RentalFormMovieViewModel>();

            foreach (var item in resultMoviesAll)
            {
                listMovies.Add(new RentalFormMovieViewModel()
                {
                    Id          = item.Id,
                    Name        = item.Name,
                    DateCreated = item.DateCreated,
                    Active      = item.Active,
                    GenreId     = item.GenreId,
                    // Caso o filme pertença a esse Rental, ele vem setado como True
                    Rental = obj == null ? false : obj.MovieRentals.Where(x => x.MovieId == item.Id).Any()
                });
            }
            result.MovieRentals = listMovies;

            return(result);
        }
Пример #3
0
        public async Task <IActionResult> Index()
        {
            ViewBag.Title = "Genres";
            var model = await _base_repository.GetAll();

            return(View(model.OrderBy(x => x.Name)));
        }
Пример #4
0
        public async Task <IActionResult> Form(int?id)
        {
            var genres = await _base_repository_genre.GetAll();

            ViewBag.GenreList = genres.OrderBy(x => x.Name).Select(
                t => new SelectListItem
            {
                Value = t.Id.ToString(),
                Text  = t.Name + (t.Active ? "" : " - Inactive")
            });

            if (id != null)
            {
                var model = await _base_repository.GetById(id ?? 0);

                if (model != null)
                {
                    ViewBag.Title = "Edit movie";
                    return(View(model));
                }
            }

            ViewBag.Title = "Create movie";
            return(View());
        }
        public async Task <ActionResult <IEnumerable <EventUser> > > GetAll()
        {
            try
            {
                var result = await _eventUserRepository.GetAll();

                if (result.Any())
                {
                    return(result.ToList());
                }
                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"{LocalLog}[GetAll]");
                throw ex;
            }
        }
Пример #6
0
        public async Task <ActionResult <Event> > GetIncludeUsers(int id)
        {
            try
            {
                var result = await _eventRepository.GetAll(e =>
                                                           e.Include(e => e.EventUsers)
                                                           .ThenInclude(eu => eu.User)
                                                           .Where(e => e.Id == id)
                                                           );

                if (result.Any())
                {
                    return(result.FirstOrDefault());
                }
                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"{LocalLog}[GetIncludeUsers]");
                throw ex;
            }
        }
Пример #7
0
        public async Task <bool> IsValid(User user)
        {
            var result = await _userRepositoy.GetAll(f => f.Where(x => x.Email.Equals(user.Email) && x.Password.Equals(user.Password)));

            return(result.Any());
        }