private void UpdateStudentSemester(SZPNUWContext context, int studentId, int oldSemesterId, int newSemesterId, ref string errorMessage) { if (CheckStudSem(context, studentId, newSemesterId, ref errorMessage)) { Studentsemester studSem = context.Studentsemester.Where(x => x.Studentid == studentId && x.Semesterid == oldSemesterId).FirstOrDefault(); Studentsemester newStudSem = new Studentsemester { Semesterid = newSemesterId, Studentid = studentId }; if (studSem != null && newStudSem != null) { context.Studentsemester.Add(newStudSem); context.Studentsemester.Remove(studSem); context.SaveChanges(); } else { Students student = context.Students.FirstOrDefault(s => s.Id == studentId); if (student != null) { errorMessage += PortalMessages.StudentSemesterCanNotChange.WithFormatExtesion(new string[] { student.User.Firstname, student.User.Lastname }); } else { errorMessage += PortalMessages.NoSuchElement; } } } }
private void RewriteStudentSemester(SZPNUWContext context, int studentId, int semesterId, ref string errorMessage) { if (CheckStudSem(context, studentId, semesterId, ref errorMessage)) { Studentsemester studSem = new Studentsemester { Semesterid = semesterId, Studentid = studentId }; context.Studentsemester.Add(studSem); context.SaveChanges(); } }
private bool DeleteStudentSemester(SZPNUWContext context, int studentId, int semesterId, ref string errorMessage) { Students student = context.Students.Include(x => x.Studentsemester).Where(s => s.Id == studentId).FirstOrDefault(); if (student != null) { if (student.Studentsemester.Count <= 1) { errorMessage += PortalMessages.StudentSemesterCanNotDelete.WithFormatExtesion(new string[] { student.User.Firstname, student.User.Lastname }); return(false); } Studentsemester studSem = context.Studentsemester.Where(x => x.Studentid == studentId && x.Semesterid == semesterId).FirstOrDefault(); context.Studentsemester.Remove(studSem); context.SaveChanges(); return(true); } errorMessage += PortalMessages.NoSuchElement; return(false); }