Exemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            User user = await _userManager.FindByIdAsync(_userId);

            if (user.isDeleted == false && (await _userManager.GetRolesAsync(user))[0] == "Moderator")
            {
                CourseUserVM courseVM = new CourseUserVM
                {
                    Course = _db.Courses.Where(p => p.Id == user.CourseID),
                    User   = user,
                    Role   = (await _userManager.GetRolesAsync(user))[0]
                };
                return(View(courseVM));
            }
            return(View(new CourseUserVM {
                Course = _db.Courses.OrderByDescending(p => p.Id),
                User = user,
                Role = (await _userManager.GetRolesAsync(user))[0]
            }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Search(string key)
        {
            if (key == null)
            {
                key = "";
            }
            var model = _db.Courses.OrderByDescending(p => p.Id).ToList();

            if (key.Length > 0 || key == "")
            {
                model = _db.Courses.Where(c => c.Name.Contains(key)).OrderByDescending(p => p.Id).ToList();
            }
            CourseUserVM userVM = new CourseUserVM
            {
                Course = model,
                User   = await _userManager.FindByIdAsync(_userId),
                Role   = (await _userManager.GetRolesAsync(await _userManager.FindByIdAsync(_userId)))[0]
            };

            return(PartialView("_CourseSearch", userVM));
        }