public ActionResult Create(TeacherUser user) { if (ModelState.IsValid) { using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString)) { string cmd = "Insert into TeacherRegister(TeacherNumber, TeacherName, Password, Gender, ProfessionalTitle, Email, QQ, Telephone) Values(@TeacherNumber, @TeacherName, @Password, @Gender, @ProfessionalTitle, @Email, @QQ, @Telephone)"; int i = con.Execute(cmd, user); if (i > 0) { ViewBag.msg = "Finish !!"; } else { ViewBag.msg = "Error !!"; ViewBag.flag = false; } } return(View("Create")); } else { ModelState.AddModelError("", "The infomation not fund"); return(View("Create")); } }
private void resetWindow() { _slpUser = null; _managerUser = null; _teacherUser = null; _currentStudents = null; btnLogin.Content = "Log in"; txtUsername.Visibility = Visibility.Visible; pwdPassword.Visibility = Visibility.Visible; cbxUserType.Visibility = Visibility.Visible; txtUsername.Text = "Email Address"; pwdPassword.Password = "******"; Message.Content = "Welcome"; Alert.Content = "You must log in to view students"; cbxUserType.SelectedItem = "Show All"; txtUsername.Focus(); txtUsername.SelectAll(); tabStudents.Visibility = Visibility.Collapsed; tabMyStudents.Visibility = Visibility.Collapsed; tabManageStudents.Visibility = Visibility.Collapsed; dgStudents.Visibility = Visibility.Collapsed; dgManageStudents.Visibility = Visibility.Collapsed; dgTeachersStudents.Visibility = Visibility.Collapsed; hideTabs(); btnFilter.Visibility = Visibility.Hidden; cbxSchool.Visibility = Visibility.Hidden; lblSchoolName.Visibility = Visibility.Hidden; }
public bool CreateNewStudent(Students student, SLPUser slp, TeacherUser teacher) { bool result = false; var cmdText1 = @"sp_insert_student"; var cmdText2 = @"sp_insert_new_iep"; int newStudentId; try { using (TransactionScope scope = new TransactionScope()) { using (SqlConnection conn = DBConnection.GetConnection()) { conn.Open(); SqlCommand cmd1 = new SqlCommand(cmdText1, conn); cmd1.CommandType = CommandType.StoredProcedure; cmd1.Parameters.AddWithValue("@FirstName", student.FirstName); cmd1.Parameters.AddWithValue("@LastName", student.LastName); cmd1.Parameters.AddWithValue("@Birthday", student.Birthday); cmd1.Parameters.AddWithValue("@TeacherID", student.TeacherID); cmd1.Parameters.AddWithValue("@Grade", student.Grade); cmd1.Parameters.AddWithValue("@Address", student.Address); cmd1.Parameters.AddWithValue("@City", student.City); cmd1.Parameters.AddWithValue("@State", student.State); cmd1.Parameters.AddWithValue("@ZipCode", student.ZipCode); cmd1.Parameters.AddWithValue("@NCESID", student.NCESId); var temp = cmd1.ExecuteScalar(); newStudentId = Convert.ToInt32(temp); SqlCommand cmd2 = new SqlCommand(cmdText2, conn); cmd2.CommandType = CommandType.StoredProcedure; cmd2.Parameters.Add("@IEPDate", SqlDbType.Date); cmd2.Parameters.AddWithValue("@StudentID", newStudentId); cmd2.Parameters.AddWithValue("@SLPID", slp.SLPID); cmd2.Parameters.AddWithValue("@IEPType", student.IEPType); cmd2.Parameters["@IEPDate"].Value = student.IEPdate; cmd2.Parameters.AddWithValue("@IEPLeaderFirstName", student.IEPLeaderFirstName); cmd2.Parameters.AddWithValue("@IEPLeaderLastName", student.IEPLeaderLastName); cmd2.Parameters.AddWithValue("@GoalType", student.GoalType); cmd2.Parameters.AddWithValue("@IEPNotes", student.IEPNotes); cmd2.Parameters.AddWithValue("@Active", student.Active); int returnValue = cmd2.ExecuteNonQuery(); } scope.Complete(); } } catch (Exception ex) { throw ex; } return(result); }
public void OnActionExecuting(ActionExecutingContext filterContext) { try { string cookiename = FormsAuthentication.FormsCookieName + "Teacher"; var v = filterContext.HttpContext.Request.Cookies[cookiename].Value; FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(v);//解密 string userno = authTicket.UserData; TeacherID = userno; ProjectView.Models.ProjectReviewDBEntities PRDB = new Models.ProjectReviewDBEntities(); StudentUser su = PRDB.StudentUsers.SingleOrDefault(stu => stu.StuNoUserName == userno); if (su == null) { int tid = int.Parse(userno); TeacherUser tu = PRDB.TeacherUsers.SingleOrDefault(teu => teu.TeacherID == tid); if (su == null && tu == null) { filterContext.HttpContext.Response.Redirect("~/Student/Login"); } } } catch { filterContext.HttpContext.Response.Redirect("~/Student/Login"); } }
public async Task <ActionResult> RegisterTeacher ( [Required][FromForm][EmailAddress] string email, [Required][FromForm] string full_name ) { TeacherUser newUser = new TeacherUser() { UserName = email, Email = email, FullName = full_name }; string password = new Random().Next(10000000, 99999999).ToString(); var creatingResult = await _userManager.CreateAsync(newUser, password); if (!creatingResult.Succeeded) { return(StatusCode( (int)HttpStatusCode.BadRequest, new MultipleErrorsViewModel( creatingResult.Errors.Select(e => e.Description).ToList() ) )); } await Email.SendLoginAndPassword(email, full_name, password); return(new OkResult()); }
/// <summary> /// Update teacher /// </summary> /// <param name="teacherUpdate"></param> /// <returns></returns> public async Task <TeacherDto> UpdateTeacher(TeacherUpdateDto teacherUpdate) { TeacherUser user = db.TeachersRepository.Get(a => a.Id == teacherUpdate.Id).FirstOrDefault(); if (user == null) { // 404, Not found. // No reason for an exception I think return(null); } TeachersConverter.UpdateTeachersPersonalData(user, teacherUpdate); var result = await db.AuthRepository.UpdateUser(user); if (!result.Succeeded) { var ex = new UserUpdateException(result.Errors.ToArray()); ex.Data.Add("IdentityResultErrors", result.Errors.ToArray()); throw ex; } var updatedUser = db.TeachersRepository.Get(a => a.Id == teacherUpdate.Id).FirstOrDefault(); return(TeachersConverter.TeacherToTeacherDto(updatedUser)); }
public TeacherUser AuthenticateTeacher(string username, string password) { TeacherUser teacherUser = null; password = HashSHA256(password); try { if (1 == _userAccess.VerifyUsernamePasswordTeacher(username, password)) { teacherUser = _userAccess.GetTeacherByEmail(username); if (password == HashSHA256("newuser")) { teacherUser.TeacherUsers.Add("New User"); } } else { throw new ApplicationException("The Teacher you requested was not found."); } } catch (Exception ex) { throw new ApplicationException("User not validated.", ex); } return(teacherUser); }
/* * -for the following: * -when user presses back button the database retrieves information based on if IsTeacherUser or IsStudentUser is true * -the database returns the value of the game mode score and stores it temp user * -then a waittime function is called to give time for the database to send and recieve before the app continues on * -if both IsTeacherUser and IsStudentUser is false then user is a guest, then no database call is made and the scene changes */ public void BackToMenu() { if (Login_Scene_Script.IsTeacherUser == true) { User1.TeacherID_3 = Login_Scene_Script.LoginId; RestClient.Get <TeacherUser>("https://blocks-b1047.firebaseio.com/" + User1.TeacherID_3 + ".json").Then(response => { T_User = response; }); } else if (Login_Scene_Script.IsStudentUser == true) { User2.StudentID_3 = Login_Scene_Script.LoginId; RestClient.Get <StudentUser>("https://blocks-b1047.firebaseio.com/" + User2.StudentID_3 + ".json").Then(response => { S_User = response; }); StartCoroutine(WaitTime()); } else { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 2); Score.scoreValue = 0; Score2.scoreValue2 = 0; Score3.scoreValue3 = 0; I_B10_Score = 0; } }
public ActionResult Create(Students student, SLPUser slp, TeacherUser teacher) { if (ModelState.IsValid) { try { // TODO: Add insert logic here if (_studentManager.CreateNewStudent(student, slp, teacher)) { return(RedirectToAction("Index")); } } catch { ViewBag.States = _states; ViewBag.SchoolName = _schoolName; ViewBag.Grade = _grade; ViewBag.IEPType = _iepType; ViewBag.GoalType = _goalType; return(View()); } } ViewBag.States = _states; ViewBag.SchoolName = _schoolName; ViewBag.Grade = _grade; ViewBag.IEPType = _iepType; ViewBag.GoalType = _goalType; return(View(student)); }
public void Update() { /* * -the following determines what kind of account is using the app: student, teacher, or guest * -if either IsTeacherUser or IsStudentUser == true then database is accessed and users id is displayed * -if both IsTeacherUser or IsStudentUSer == false then "Guest" is displayed */ if (Login_Scene_Script.IsTeacherUser == true) { User1.TeacherID_3 = Login_Scene_Script.LoginId; RestClient.Get <TeacherUser>("https://blocks-b1047.firebaseio.com/" + User1.TeacherID_3 + ".json").Then(response => { T_User = response; }); ID_Text_Script.ID_text.text = T_User.TeacherID_3; //displays to text field } else if (Login_Scene_Script.IsStudentUser == true) { User2.StudentID_3 = Login_Scene_Script.LoginId; RestClient.Get <StudentUser>("https://blocks-b1047.firebaseio.com/" + User2.StudentID_3 + ".json").Then(response => { S_User = response; }); ID_Text_Script.ID_text.text = "Hello " + S_User.StudentID_3; //displays to text field } else { ID_Text_Script.ID_text.text = "Hello Guest"; } }
public void BackToMenu() { if (Login_Scene_Script.IsTeacherUser == true) { User1.TeacherID_3 = Login_Scene_Script.LoginId; Debug.Log("User1:" + User1.TeacherID_3); RestClient.Get <TeacherUser>("https://blocks-b1047.firebaseio.com/" + User1.TeacherID_3 + ".json").Then(response => { T_User = response; Debug.Log("T_User:"******"User2:" + User2.StudentID_3); RestClient.Get <StudentUser>("https://blocks-b1047.firebaseio.com/" + User2.StudentID_3 + ".json").Then(response => { S_User = response; Debug.Log("S_User:" + S_User.StudentID_3); }); StartCoroutine(WaitTime()); } else { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 6); AddScore5_25.scoreValue = 0; AddScore5_5.scoreValue2 = 0; AddScore5_1.scoreValue3 = 0; A_B5_Score = 0; } }
public ActionResult Edit(int ID, TeacherUser reg) { if (ModelState.IsValid) { using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString)) { string cmd = $"Update dbo.TeacherRegister SET TeacherNumber = @TeacherNumber, TeacherName = @TeacherName, Password = @Password, Gender = @Gender, ProfessionalTitle = @ProfessionalTitle, Email = @Email, QQ = @QQ, Telephone = @Telephone Where (ID = {ID})"; int i = con.Execute(cmd, reg); if (i > 0) { ViewBag.msg = "Finish !!"; } else { ViewBag.msg = "Error !!"; ViewBag.flag = false; } } return(View("Edit")); } else { ModelState.AddModelError("", "The infomation not fund"); return(View("Edit")); } }
public void Login() //when login button is pressed { LoginId = LoginIdField.text; //takes the user input and puts it in the necessary values LoginPassword = LoginPasswordField.text; user.TeacherID_3 = LoginId; user.TeacherPassword_3 = LoginPassword; user2.StudentID_3 = LoginId; user2.StudentPassword_3 = LoginPassword; //the following takes the inputed login id and searches the database for a match //the response is then saved into a temperorary user if (LoginId != "" && LoginPassword != "") // checks to make sure input fields are filled { RestClient.Get <TeacherUser>("https://blocks-b1047.firebaseio.com/" + user.TeacherID_3 + ".json").Then(response => { T_user = response; }); RestClient.Get <StudentUser>("https://blocks-b1047.firebaseio.com/" + user2.StudentID_3 + ".json").Then(response => { S_user = response; }); StartCoroutine(WaitTime()); //calls a wait function } else //output error message to error_txt_message script { Error_txt_message.ErrorTxt.text = "Input Fields Are Empty"; } }
public TeacherUser GetTeacherByEmail(string email) { TeacherUser teacherUser = null; var conn = DBConnection.GetConnection(); string cmdText = "sp_get_teacher_username_by_email"; var cmd = new SqlCommand(cmdText, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 250); cmd.Parameters["@Email"].Value = email; try { string firstName = null; string lastName = null; string teacherID = null; string ncesID = null; List <string> users = new List <string>(); conn.Open(); SqlDataReader reader1 = cmd.ExecuteReader(); if (reader1.HasRows) { while (reader1.Read()) { teacherID = reader1.GetString(0); ncesID = reader1.GetString(1); firstName = reader1.GetString(2); lastName = reader1.GetString(3); } } else { throw new ApplicationException("This Teacher was not not found."); } reader1.Close(); teacherUser = new TeacherUser(teacherID, ncesID, firstName, lastName, users); } catch (Exception) { throw; } finally { conn.Close(); } return(teacherUser); }
/// <summary> /// Remove teacher from course /// NOTE better use DELETE to courses/{courseId}/teachers/{teachersId} /// it is more RESTful /// NOTE this is the old method /// </summary> /// <param name="courseId"></param> /// <param name="teacherId"></param> /// <returns></returns> public Teaching RemoveTeacherFromCourse(int courseId, int teacherId) { // 4 errors: // 1) courseId not found // 2) teacherId not found // 3) teaching not found // 4) cannot remove association because it is in use Course course = db.CoursesRepository.GetByID(courseId); if (course == null) { logger.Error("Course {@courseId} not found", courseId); var ex = new CourseNotFoundException(String.Format("Course {0} not found", courseId)); ex.Data.Add("courseId", courseId); throw ex; } TeacherUser teacher = db.TeachersRepository.Get(t => t.Id == teacherId).FirstOrDefault(); if (teacher == null) { logger.Error("Teacher {@teacherId} not found", teacherId); var ex = new TeacherNotFoundException(String.Format("Teacher {0} not found", courseId)); ex.Data.Add("teacherId", teacherId); throw ex; } // Maybe we don't need to check Course and Teacher at all? Teaching teaching = db.TeachingAssignmentsRepository.Get(ta => ta.CourseId == courseId && ta.TeacherId == teacherId).FirstOrDefault(); if (teaching == null) { logger.Error("Teaching assignment for teacher {@teacherId} and course {@courseId} not found", teacherId, courseId); var ex = new TeachingNotFoundException(String.Format("Teaching assignment for teacher {0} and course {1} not found", teacherId, courseId)); ex.Data.Add("teacherId", teacherId); ex.Data.Add("courseId", courseId); throw ex; } try { // Probably another method in service? db.TeachingAssignmentsRepository.Delete(teaching); db.Save(); } catch (Exception ex) { logger.Error(ex, "Removal of teaching assignment failed for teacher {@teacherId} and course {@courseId}", teacherId, courseId); throw; } return(null); }
public frmUpdatePassword(SLPUser slpUser, userManager userManager, TeacherUser teacherUser, ManagerUser managerUser, bool newUser = false) { this._managerUser = managerUser; this._userManager = userManager; this._teacherUser = teacherUser; this._slpUser = slpUser; this._newUser = newUser; InitializeComponent(); }
public bool CreateNewStudent(Students student, SLPUser slp, TeacherUser teacher) { bool result = false; _students.Add(student); if (_students.Contains(student)) { result = true; } return(result); }
/// <summary> /// Update full entity from dto before sending to the storage /// </summary> /// <param name="user"></param> /// <param name="dto"></param> public static void UpdateTeachersPersonalData(TeacherUser user, TeacherUpdateDto dto) { user.UserName = dto.UserName; user.FirstName = dto.FirstName; user.LastName = dto.LastName; user.Gender = dto.Gender; user.Email = dto.Email; user.PhoneNumber = dto.PhoneNumber; user.Title = dto.Title; user.Degree = dto.Degree; }
public TeacherUser GetTeacherByEmail(string email) { TeacherUser teacher = new TeacherUser(); teacher = _teacher.Find(x => x.Email == email); if (teacher == null) { throw new ArgumentException("Teacher not found."); } return(teacher); }
public IActionResult TeaLogin() { TeacherUser user = new TeacherUser() { Id = Guid.NewGuid(), Name = "丁老师", TeacherNo = "T2201432" }; TeacherUser.Login(user); return(View()); }
/// <summary> /// Convert a teacher model to an extended data structure /// With a list of classrooms and courses /// and a list of courses and classrooms /// EXTRA and with a list of students nested inside... /// </summary> /// <param name="teacher"></param> /// <returns></returns> public static TeacherExtendedEvenMoreDto TeacherToTeacherEvenMoreExtendedDto(TeacherUser teacher) { TeacherExtendedEvenMoreDto teacherData = new TeacherExtendedEvenMoreDto() { TeacherId = teacher.Id, FirstName = teacher.FirstName, LastName = teacher.LastName, ClassRooms = teacher.Teachings .SelectMany(t => t.Programs).GroupBy(p => p.ClassRoom) .Select(g => new TeacherExtendedEvenMoreDto.ClassRoomCoursesDto() { ClassRoomId = g.Key.Id, ClassRoomName = g.Key.Name, Grade = g.Key.ClassGrade, Courses = g.Select(prog => new TeacherExtendedEvenMoreDto.ClassRoomCoursesDto.InnerCourseDto() { CourseId = prog.Course.Id, CourseName = prog.Course.Name, WeeklyHours = prog.WeeklyHours, Students = prog.TakingStudents.Select(s => new TeacherExtendedEvenMoreDto.ClassRoomCoursesDto.InnerCourseDto.StudentDto() { // This was not throwing because I used the include, duh! StudentId = s.Student.Id, FirstName = s.Student.FirstName, LastName = s.Student.LastName }) }).ToList() }).ToList(), // No groupings or selectmanys?? and still working... Courses = teacher.Teachings .Select(g => new TeacherExtendedEvenMoreDto.CourseClassRoomDto() { CourseId = g.Course.Id, CourseName = g.Course.Name, ClassRooms = g.Programs.Select(p => new TeacherExtendedEvenMoreDto.CourseClassRoomDto.InnerClassRoomDto() { ClassRoomId = p.ClassRoom.Id, ClassRoomName = p.ClassRoom.Name, Grade = p.ClassRoom.ClassGrade, WeeklyHours = p.WeeklyHours, Students = p.TakingStudents.Select(s => new TeacherExtendedEvenMoreDto.CourseClassRoomDto.InnerClassRoomDto.StudentDto() { StudentId = s.Student.Id, FirstName = s.Student.FirstName, LastName = s.Student.LastName }) }).ToList() }).ToList() }; return(teacherData); }
/// <summary> /// Get a teacher by Id /// </summary> /// <param name="teacherId"></param> /// <returns></returns> public TeacherUser GetTeacherById(int teacherId) { TeacherUser teacher = db.TeachersRepository.Get(t => t.Id == teacherId).FirstOrDefault(); if (teacher == null) { logger.Info("Teacher {@teacherId} not found", teacherId); var ex = new TeacherNotFoundException(string.Format("Teacher {0} not found", teacherId)); ex.Data.Add("teacherId", teacherId); throw ex; } return(teacher); }
/// <summary> /// Register a teacher user /// </summary> /// <param name="teacher"></param> /// <param name="password"></param> /// <returns></returns> public async Task <IdentityResult> RegisterTeacherUser(TeacherUser teacher, string password) { logger.Trace("Register Teacher {@userName}", teacher.UserName); var result = await _userManager.CreateAsync(teacher, password); if (!result.Succeeded) { return(result); } _userManager.AddToRole(teacher.Id, "teachers"); return(result); }
public TeacherUser RetrieveTeacherByEmail(string email) { TeacherUser teacher = null; var conn = DBConnection.GetConnection(); string cmdText = @"sp_retrieve_all_teacher_emails"; var cmd = new SqlCommand(cmdText, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("Email", email); try { string teacherID = null; string firstName = null; string lastName = null; conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { teacherID = reader.GetString(0); firstName = reader.GetString(1); lastName = reader.GetString(2); } } else { throw new ApplicationException("User not found."); } teacher = new TeacherUser(teacherID, firstName, lastName); } catch (Exception) { throw; } finally { conn.Close(); } return(teacher); }
public static TeacherReportDto TeacherToTeacherReportDto(TeacherUser teacher) { TeacherReportDto report = new TeacherReportDto() { TeacherId = teacher.Id, FirstName = teacher.FirstName, LastName = teacher.LastName, ClassRooms = teacher.Teachings .SelectMany(t => t.Programs).GroupBy(p => p.ClassRoom) .Select(g => ClassRoomProgramGroupingToTeacherReportClassRoom(g)), Courses = teacher.Teachings.Select(t => TeachingToTeacherReportCourse(t)) }; return(report); }
/// <summary> /// Convert a teacher model to teacher dto /// </summary> /// <param name="teacher">A teacher (full) model</param> /// <returns>Teacher Dto object, ready for Json serialization</returns> public static TeacherDto TeacherToTeacherDto(TeacherUser teacher) { return(new TeacherDto() { TeacherId = teacher.Id, UserName = teacher.UserName, FirstName = teacher.FirstName, LastName = teacher.LastName, Gender = teacher.Gender, Email = teacher.Email, Phone = teacher.PhoneNumber, Degree = teacher.Degree, Title = teacher.Title }); }
/// <summary> /// Create classRoom program item. /// Every classRoom has a program consisting of courses taught by one teacher per course. /// </summary> /// <param name="program"></param> public void CreateClassRoomProgram(ClassRoomProgramDto program) { logger.Trace("Service received request for classroom program creation {programData}", program); // I see. Manual setup. ClassRoom classRoom = db.ClassRoomsRepository.Get(c => c.Id == program.ClassRoomId).FirstOrDefault(); if (classRoom == null) { // I can throw an exception and process it in the handler at the api level return; } Course course = db.CoursesRepository.Get(c => c.Id == program.CourseId).FirstOrDefault(); if (course == null) { return; } TeacherUser teacher = db.TeachersRepository.Get(t => t.Id == program.TeacherId).FirstOrDefault(); if (teacher == null) { return; } Teaching teaching = db.TeachingAssignmentsRepository.Get(ta => ta.CourseId == program.CourseId && ta.TeacherId == program.TeacherId).FirstOrDefault(); if (teaching == null) { // this is the special case // every id is ok but the teacher does not teach the course // if we went directly, we would not know if the problem is with one of the id's or their combo... return; } Program newProgram = new Program() { Course = course, ClassRoom = classRoom, Teaching = teaching, WeeklyHours = program.WeeklyHours }; db.ProgramsRepository.Insert(newProgram); db.Save(); }
public async Task <ActionResult <User> > Update([FromBody] User user) { string usermane = User.Identity.Name; User userOld = GetUser(usermane); if (user == null) { return(StatusCode(400)); } if (userOld.Role == Roles.Student) { StudentUser student = await _context.StudentUsers.FirstOrDefaultAsync(a => a.Id.Equals(userOld.Id)); student.Firstname = user.Firstname; student.Secondname = user.Secondname; student.Email = user.Email; student.DateBirth = user.DateBirth; _context.StudentUsers.Update(student); } if (userOld.Role == Roles.SuperUser) { SuperUser super = _context.SuperUsers.FirstOrDefault(a => a.Id.Equals(userOld.Id)); super.Firstname = user.Firstname; super.Secondname = user.Secondname; super.Email = user.Email; super.DateBirth = user.DateBirth; _context.SuperUsers.Update(super); } if (userOld.Role == Roles.Teacher) { TeacherUser teacher = _context.TeacherUsers.FirstOrDefault(a => a.Id.Equals(userOld.Id)); teacher.Firstname = user.Firstname; teacher.Secondname = user.Secondname; teacher.Email = user.Email; teacher.DateBirth = user.DateBirth; _context.TeacherUsers.Update(teacher); } _context.SaveChanges(); return(Ok(userOld)); }
public TeacherExtendedDto GetExtendedDataForTeacher(int teacherId) { TeacherUser teacher = db.TeachersRepository.Get(t => t.Id == teacherId).FirstOrDefault(); if (teacher == null) { return(null); } TeacherExtendedDto teacherData = new TeacherExtendedDto() { TeacherId = teacher.Id, FirstName = teacher.FirstName, LastName = teacher.LastName, ClassRooms = teacher.Teachings .SelectMany(t => t.Programs).GroupBy(p => p.ClassRoom) .Select(g => new TeacherExtendedDto.ClassRoomCoursesDto() { ClassRoomId = g.Key.Id, ClassRoomName = g.Key.Name, Grade = g.Key.ClassGrade, Courses = g.Select(prog => new TeacherExtendedDto.ClassRoomCoursesDto.InnerCourseDto() { CourseId = prog.Course.Id, CourseName = prog.Course.Name, WeeklyHours = prog.WeeklyHours }).ToList() }).ToList(), // No groupings or selectmanys?? and still working... Courses = teacher.Teachings .Select(g => new TeacherExtendedDto.CourseClassRoomDto() { CourseId = g.Course.Id, CourseName = g.Course.Name, ClassRooms = g.Programs.Select(p => new TeacherExtendedDto.CourseClassRoomDto.InnerClassRoomDto() { ClassRoomId = p.ClassRoom.Id, ClassRoomName = p.ClassRoom.Name, Grade = p.ClassRoom.ClassGrade, WeeklyHours = p.WeeklyHours }).ToList() }).ToList() }; return(teacherData); }
/// <summary> /// 添加教师用户 /// </summary> /// <param name="tum"></param> /// <returns></returns> public bool AddTeacher(TeacherUserModel tum) { try { var tu = new TeacherUser(); tu.UserName = tum.UserName; tu.Password = tum.Password; tu.TeacherID = tum.TeacherID; PRDB.TeacherUsers.Add(tu); PRDB.SaveChanges(); return(true); } catch { return(false); } }
public ActionResult SaveTeacherUser(TeacherUser teach) { teach.Id = SessionDataHelper.UserId; teach.ScheduleId = teach.Schedule.Id = _teacherUserService.GetById(SessionDataHelper.UserId).ScheduleId; _scheduleService.Update(teach.Schedule); _teacherUserService.Update(teach); return Json(new { Result = "OK" }); }