// GET: Dashboard public ActionResult Index() { int role = Convert.ToInt32(Session["UserPosition"]); int userId = Convert.ToInt32(Session["UserID"]); using (AuaDbContext db = new AuaDbContext()) { var userClases = db.UserClasses.Where(item => item.fk_User == userId).ToList(); List <Class> Class = new List <Class>(); foreach (var item in userClases) { var b = db.Classes.Where(a => a.Id == item.fk_Class).FirstOrDefault(); Class.Add(b); } ViewBag.Class = Class; } if (role == 0) { return(View("Class")); } else if (role == 1) { return(View("TeacherClass")); } else { return(View("Error")); } }
public ActionResult Login(LoginDetails objUser) { if (ModelState.IsValid) { using (AuaDbContext db = new AuaDbContext()) { var obj = db.LoginDetails.Where(a => a.UserName.Equals(objUser.UserName) && a.Password.Equals(objUser.Password)).FirstOrDefault(); if (obj != null) { Session["UserID"] = obj.UserId.ToString(); Session["UserPosition"] = obj.UserPosition.ToString(); return(RedirectToAction("Index", "Classes")); } } } return(View("Index")); }
public static List <Class> GetClass(int userId) { List <Class> Class = new List <Class>(); using (AuaDbContext db = new AuaDbContext()) { var userClases = db.UserClasses.Where(item => item.fk_User == userId).ToList(); foreach (var item in userClases) { var b = db.Classes.Where(a => a.Id == item.fk_Class).FirstOrDefault(); if (b != null) { Class.Add(b); } } } return(Class); }
public static List <Students> GetStudents(int classId) { List <Students> students = new List <Students>(); using (AuaDbContext db = new AuaDbContext()) { var userClases = db.UserClasses.Where(item => item.fk_Class == classId).ToList(); foreach (var item in userClases) { var b = db.Students.Where(a => a.Id == item.fk_User).FirstOrDefault(); if (b != null) { students.Add(b); } } } return(students); }