public async Task <IActionResult> roleProf(string id) { //privavljane trenutno ulogovanog korisnika var currentUser = await _context.Users .Include(x => x.Quizzes) .FirstOrDefaultAsync(x => x.Id == id); //dodavanje role korisniku, ovo je glavni deo await userManager.AddToRoleAsync(currentUser, "Profesor"); Course course = _context.Courses .Where(x => x.ID == 1) .FirstOrDefault(); onCours onCours = new onCours(); onCours.User = currentUser; onCours.Course = course; currentUser.OnCours.Add(onCours); course.Users.Add(onCours); _context.SaveChanges(); return(View("Index")); }
public async Task <List <string> > GetCourses() { onCours search = new onCours(); ApplicationUser user = await _userManager.GetUserAsync(User); search.User = user; List <String> courses = _context.Courses .Where(x => x.Users.Any(y => y.User.Id == user.Id)) .Select(x => x.Name) .ToList(); return(courses); }
[HttpPost] //tehnicki ovo bi trebalo da vrati 503 ili tako nesto ako ga zoves preko GET, tacno? public async Task <IActionResult> Subscribe(int course, string user) { ApplicationUser u = await _context.Users.FirstOrDefaultAsync(x => x.Id == user); Course crs = await _context.Courses .FirstOrDefaultAsync(m => m.ID == course); onCours sub = new onCours(); sub.User = u; sub.Course = crs; crs.Users.Add(sub); _context.SaveChanges(); int idc = course; return(RedirectToAction("Course", "Home", new { id = idc })); }
[HttpGet]//ove sve akcije nadole bi trebalo da izbrisemo public async Task <IActionResult> testRun() { Course course = await _context.Courses .Where(x => x.ID == 1) .FirstOrDefaultAsync(); string currentUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; ApplicationUser currentUser = _context.Users.Include(user => user.Quizzes).FirstOrDefault(x => x.Id == currentUserId); onCours onCours = new onCours(); onCours.User = currentUser; onCours.Course = course; currentUser.OnCours.Add(onCours); course.Users.Add(onCours); _context.SaveChanges(); return(View("Index")); }