Example #1
0
        public async Task <IActionResult> Info(int id)
        {
            var           movie = _db.Movies.Include(x => x.Poster).Where(x => x.Id == id).FirstOrDefault();
            InfoVIewModel info  = new InfoVIewModel();

            info.Movie = movie;
            var user = await _userManager.GetUserAsync(User);

            if (movie != null && user?.Id == movie.UserId)
            {
                movie.Poster.Path = CheckPoster(movie);
                info.CanEdit      = true;
            }
            return(View(info));
        }
        public ActionResult Index(int?coach, string name, SortState sortOrder = SortState.NameAsc)
        {
            ViewBag.Title = "Visitors info";
            //IQueryable<GymVisitor> users = db.GymVisitors.Include(p => p.CoachId);
            IQueryable <GymVisitor> users = db.GymVisitors.Where(p => p.CoachId != null);

            ViewData["NameSort"] = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc;
            users = sortOrder switch
            {
                SortState.NameDesc => users.OrderByDescending(s => s.LastName),
                SortState.CompanyAsc => users.OrderBy(s => s.LastName),
                SortState.CompanyDesc => users.OrderByDescending(s => s.LastName),
                _ => users.OrderBy(s => s.LastName),
            };

            if (coach != null && coach != 0)
            {
                users = users.Where(p => p.CoachId == coach);
            }
            if (!String.IsNullOrEmpty(name))
            {
                users = users.Where(p => p.LastName.Contains(name));
            }

            List <GymCoach> coaches = db.GymCoaches.ToList();

            // устанавливаем начальный элемент, который позволит выбрать всех
            coaches.Insert(0, new GymCoach {
                Id = 0, LastName = "All"
            });


            InfoVIewModel viewModel = new InfoVIewModel
            {
                GymVisitors = users.ToList(),
                Coaches     = new SelectList(coaches, "Id", "LastName"),
                SecondName  = name,
                GymCoaches  = coaches
            };


            return(View(viewModel));
        }