public void UpdateStudentInfo(StudentWelcomeInfo studentWelcomeInfo) { using (var db = new ceit_gwa_databaseEntities1()) { string studentid; CeitStudent studentData; CeitUser userData; if (GetStudentId(HttpContext.Current.User.Identity.Name) != null) { studentid = GetStudentId(HttpContext.Current.User.Identity.Name); studentData = db.CeitStudents.FirstOrDefault(p => p.StudentID == studentid); userData = db.CeitUsers.FirstOrDefault(p => p.StudentAccount == studentid); if (studentData != null) { studentData.FirstName = studentWelcomeInfo.FirstName; studentData.MiddleName = studentWelcomeInfo.MiddleName; studentData.LastName = studentWelcomeInfo.LastName; studentData.Gender = studentWelcomeInfo.Gender; studentData.CourseId = studentWelcomeInfo.CourseId; studentData.YearLevelId = studentWelcomeInfo.YearLevelId; studentData.QuestionId = studentWelcomeInfo.QuestionId; studentData.Answer = studentWelcomeInfo.Answer; } if (userData != null) { userData.DateUpdated = DateTime.Now; } db.SaveChanges(); } } }
public ActionResult Welcome(StudentSignUpView studentSignUp) { if ((UserStatus)TempData["StudentStatus"] == UserStatus.NowAuthenticated) { using (var dbContext = new ceit_gwa_databaseEntities1()) { StudentWelcomeInfo studentWelcomeInfo = new StudentWelcomeInfo(); studentWelcomeInfo.CourseList = dbContext.CeitCourses.ToList().Select(p => new SelectListItem { Value = Convert.ToString(p.CourseId), Text = p.Text }); studentWelcomeInfo.YearLevelList = dbContext.CeitYearLevels.ToList().Select(p => new SelectListItem { Value = Convert.ToString(p.YearLevelId), Text = p.YearLevel }); studentWelcomeInfo.SecurityQuestionList = dbContext.CeitSecurityQuestions.ToList().Select(p => new SelectListItem { Value = Convert.ToString(p.QuestionsId), Text = p.SecurityQuestions }); studentWelcomeInfo.GenderList = new SelectList(Enum.GetValues(typeof(Gender))); return(View("Welcome", studentWelcomeInfo)); } } return(View()); }
public bool StudentExist(string studentNumber, string password) { using (var userContext = new ceit_gwa_databaseEntities1()) { //var user = userContext.CeitUsers.Where(u => u.LoginAccount == studentNumber && u.Password == password).FirstOrDefault(); try { var test = userContext.CeitUsers.Where(u => u.LoginAccount == studentNumber && u.Password == password).FirstOrDefault(); } catch (Exception ex) { DebugErrorMessage.CatchError(ex); } string user = null; //user = Convert.ToString(userContext.CeitUsers.Where(u => u.LoginAccount == studentNumber && u.Password == password).FirstOrDefault()); if (user != null) { return(true); } else { return(false); } } }
public override string[] GetAllRoles() { using (var userContext = new ceit_gwa_databaseEntities1()) { return(userContext.CeitUserRoles.Select(r => r.Roles).ToArray()); } }
//Get assigned role public int GetRoleId(string rolefor) { using (var db = new ceit_gwa_databaseEntities1()) { var student = db.CeitUserRoles.FirstOrDefault(a => a.RolesFor.Equals(rolefor)); return(student.RoleId); } }
//Check if student exist public bool IsStudentAvailable(string loginAccount) { using (var db = new ceit_gwa_databaseEntities1()) { return(db.CeitStudents.Any(o => o.StudentNumber.Equals(loginAccount))); //|| db.CeitUsers.Any(o => o.LoginAccount.Equals(loginAccount)) } }
public string GetAdmnId(string adminName) { using (var userContext = new ceit_gwa_databaseEntities1()) { var adminId = userContext.CeitAdministrators.FirstOrDefault(p => p.AdminName == adminName); return(adminId.AdminId.ToString()); } }
public string GetStudentId(string studentNumber) { using (var db = new ceit_gwa_databaseEntities1()) { var student = db.CeitStudents.FirstOrDefault(p => p.StudentNumber == studentNumber); if (student != null) { return(Convert.ToString(student.StudentID)); } return(null); } }
protected void Application_Start() { //Database.SetInitializer<ceit_gwa_databaseEntities1>(new CreateDatabaseIfNotExists<ceit_gwa_databaseEntities1>()); Database.SetInitializer(new DatabaseInitializer()); //Database.Initialize(true); using (var db = new ceit_gwa_databaseEntities1()) { db.Database.Initialize(force: true); } AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
public bool AdminExist(string adminId, string password) { using (var userContext = new ceit_gwa_databaseEntities1()) { var admin = userContext.CeitUsers.Where(p => p.AdminAccount == adminId && p.Password == password).FirstOrDefault(); if (admin != null) { return(true); } else { return(false); } } }
public override bool IsUserInRole(string username, string roleName) { using (var userContext = new ceit_gwa_databaseEntities1()) { var user = userContext.CeitUsers.SingleOrDefault(u => u.LoginAccount == username); var userRoles = userContext.CeitUserRoles.Select(r => r.RoleId); if (user == null) { return(false); } else { return(userRoles.Any(r => r == user.Roles)); } } }
public override string[] GetRolesForUser(string username) { using (var userContext = new ceit_gwa_databaseEntities1()) { var roles = userContext.CeitUsers.FirstOrDefault(u => u.LoginAccount == username); var userRoles = userContext.CeitUserRoles.Where(r => r.RoleId == roles.Roles); if (roles.Roles == null) { return(new string[] { }); } else { return(userRoles.Select(u => u.Roles).ToArray()); } } }
//Adding student public void AddStudent(StudentSignUpView user) { using (var db = new ceit_gwa_databaseEntities1()) { string rolefor = "Students"; string newid = Convert.ToString(Guid.NewGuid()); CeitStudent StudentData = new CeitStudent(); StudentData.StudentNumber = user.LoginAccount; StudentData.StudentID = newid; db.CeitStudents.Add(StudentData); CeitUser UserData = new CeitUser(); UserData.StudentAccount = StudentData.StudentID; UserData.LoginAccount = user.LoginAccount; UserData.Password = user.Password; UserData.Roles = GetRoleId(rolefor); UserData.DateUpdated = DateTime.Now; UserData.DateCreated = DateTime.Now; db.CeitUsers.Add(UserData); db.SaveChanges(); } }