public void RewriteStudentSemester(int studentId, int semesterId, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { RewriteStudentSemester(context, studentId, semesterId, ref errorMessage); } }
public UserModel Login(LoginModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Users user = context.Users.Include(x => x.Students).Include(x => x.Lecturers).FirstOrDefault(x => x.Login == model.UserName && x.Password == SecurityService.GetSHA256Hash(model.Password)); int? pId = null; if (user != null) { if (user.Lecturers != null) { pId = user.Lecturers.Id; } else if (user.Students != null) { pId = user.Students.Id; } return(new UserModel() { PId = pId, UserId = user.Id, Login = user.Login, FirstName = user.Firstname, LastName = user.Lastname, Address = user.Address, City = user.Address, DateOfBirth = user.Dateofbirth, PESEL = user.Pesel, UserType = (UserTypes)user.Usertype }); } errorMessage = ValidationMessages.WrongUserNameOrPassword; return(null); } }
public float GetStudentAverageRating(int sectionId, int studentId) { using (SZPNUWContext context = new SZPNUWContext()) { List <float?> list = context.Studentssections .FirstOrDefault(x => x.Sectionid == sectionId && x.Studentid == studentId) .Meetings .Select(x => x.Rating) .ToList(); list.RemoveAll(item => item == null); if (list.Count != 0) { float ave = 0; foreach (float val in list) { ave += val; } ave /= list.Count; return(ave); } else { return(0); } } }
public bool AddProject(ProjectModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Lecturers lecturer = context.Lecturers.FirstOrDefault(x => x.Userid == model.UserId); if (lecturer == null) { errorMessage = PortalMessages.UserDoesNotExist; return(false); } if (!context.Projects.Any(x => x.Topic == model.Topic)) { Projects project = new Projects() { Topic = model.Topic, Active = model.Active, Description = model.Description, Lecturerid = lecturer.Id, Subjectid = model.SubjectId, }; context.Projects.Add(project); context.SaveChanges(); return(true); } errorMessage = PortalMessages.TopicIsUsed; return(false); } }
public void UpdateStudentsSemester(SemestersIdModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) using (IDbContextTransaction transaction = context.Database.BeginTransaction()) { try { List <int> studentsId = context.Studentsemester.Where(x => x.Semesterid == model.SemesterId).Select(x => x.Studentid).ToList(); if (studentsId.AnyLazy()) { foreach (int studentId in studentsId) { UpdateStudentSemester(context, studentId, model.SemesterId.Value, model.NewSemesterId.Value, ref errorMessage); } transaction.Commit(); } else { errorMessage = PortalMessages.NoStudentsOnSemester; } } catch (Exception e) { transaction.Rollback(); errorMessage = e.Message; } } }
public bool UpdateProject(ProjectModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Lecturers lecturer = context.Lecturers.FirstOrDefault(x => x.Userid == model.UserId); if (lecturer == null) { errorMessage = PortalMessages.UserDoesNotExist; return(false); } if (!context.Projects.Any(x => x.Topic == model.Topic && x.Id != model.Id)) { Projects project = context.Projects.FirstOrDefault(x => x.Id == model.Id); if (project != null) { project.Topic = model.Topic; project.Active = model.Active; project.Description = model.Description; project.Lecturerid = lecturer.Id; project.Subjectid = model.SubjectId; context.SaveChanges(); return(true); } errorMessage = PortalMessages.NoSuchElement; return(false); } errorMessage = PortalMessages.TopicIsUsed; return(false); } }
public bool RegisterAdmin(UserModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { if (!context.Users.Where(x => x.Login == model.Login).Any()) { using (var transaction = context.Database.BeginTransaction()) { Users user = new Users { Login = model.Login, Password = SecurityService.GetSHA256Hash(model.Password), Firstname = model.FirstName, Lastname = model.LastName, Pesel = model.PESEL, City = model.City, Address = model.Address, Dateofbirth = model.DateOfBirth, Usertype = (int)UserTypes.Admin }; try { context.Add(user); context.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); errorMessage = PortalMessages.InsertDBError; } } return(true); } errorMessage = ValidationMessages.UsedLogin; return(false); } }
public List <StudentModel> GetStudentBySemesterId(int semesterId) { using (SZPNUWContext context = new SZPNUWContext()) { List <Students> students = context.Studentsemester.Where(x => x.Semesterid == semesterId).Select(x => x.Student).Include(x => x.User).ToList(); Semesters semester = context.Semesters.FirstOrDefault(x => x.Id == semesterId); List <StudentModel> model = new List <StudentModel>(); students.ForEach(x => model.Add(new StudentModel { Id = x.Id, Login = x.User.Login, FirstName = x.User.Firstname, LastName = x.User.Lastname, PESEL = x.User.Pesel, Address = x.User.Address, City = x.User.City, AlbumNumber = x.Albumnumber, DateOfBirth = x.User.Dateofbirth, UserId = x.Userid, UserType = (UserTypes)x.User.Usertype, Semester = new SemesterModel { Id = semester.Id, Department = semester.Fieldofstudy, SemesterNumber = semester.Semesternumber, Year = semester.Academicyear } })); return(model); } }
public List <string> GetDepartments() { using (SZPNUWContext context = new SZPNUWContext()) { return(context.Semesters.GroupBy(x => x.Fieldofstudy).Select(x => x.Key).ToList()); } }
public bool DeleteSubjectSemester(int id, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Subjectssemesters subSem = context.Subjectssemesters.FirstOrDefault(x => x.Id == id); if (subSem == null) { errorMessage = PortalMessages.NoSuchElement; return(false); } if (context.Subjectssemesters.Where(x => x.Subjectid == subSem.Subjectid).ToList().Count <= 1) { errorMessage = PortalMessages.LastEntryForTheItem; return(false); } if (context.Sections.Where(x => x.Subcjetsemesterid == id).AnyLazy()) { errorMessage = PortalMessages.SemesterDependence; return(false); } context.Subjectssemesters.Attach(subSem); context.Subjectssemesters.Remove(subSem); context.SaveChanges(); return(true); } }
public int?GetSectionStudentId(int sectionId, int studentId) { using (SZPNUWContext context = new SZPNUWContext()) { return(context.Studentssections.Where(x => x.Sectionid == sectionId && x.Studentid == studentId).Select(x => x.Id).FirstOrDefault()); } }
public bool StudentInSection(int sectionId, int studentId) { using (SZPNUWContext context = new SZPNUWContext()) { return(context.Studentssections.Where(x => x.Sectionid == sectionId && x.Studentid == studentId).Any()); } }
public StudentModel GetStudentById(int id) { using (SZPNUWContext context = new SZPNUWContext()) { Students student = context.Students.Include(x => x.User).FirstOrDefault(s => s.Id == id); if (student == null) { return(null); } Semesters semester = context.Studentsemester.Include(x => x.Semester).Where(x => x.Studentid == id).OrderBy(x => x.Semester.Semesternumber).Last().Semester; StudentModel model = new StudentModel { Id = student.Id, Login = student.User.Login, FirstName = student.User.Firstname, LastName = student.User.Lastname, PESEL = student.User.Pesel, Address = student.User.Address, City = student.User.City, AlbumNumber = student.Albumnumber, DateOfBirth = student.User.Dateofbirth, UserId = student.Userid, UserType = (UserTypes)student.User.Usertype, Semester = new SemesterModel { Id = semester.Id, Department = semester.Fieldofstudy, SemesterNumber = semester.Semesternumber, Year = semester.Academicyear } }; return(model); } }
public bool AddStudentToSection(StudentSectionModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Sections section = context.Sections.Where(x => x.Id == model.SectionId).FirstOrDefault(); if (section != null) { bool result = (from ss in context.Studentssections join s in context.Sections on ss.Sectionid equals s.Id where s.Subcjetsemesterid == section.Subcjetsemesterid && ss.Studentid == model.StudentId select ss).Any(); if (!result) { Studentssections studSec = new Studentssections() { Sectionid = model.SectionId, Studentid = model.StudentId.Value }; context.Studentssections.Add(studSec); context.SaveChanges(); return(true); } } errorMessage = PortalMessages.CanNotAddStudentToSection; return(false); } }
public bool DeleteStudentSemester(int studentId, int semesterId, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { return(DeleteStudentSemester(context, studentId, semesterId, ref errorMessage)); } }
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; } } } }
public void UpdateStudentSemester(int studentId, int oldSemesterId, int newSemesterId, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { UpdateStudentSemester(context, studentId, oldSemesterId, newSemesterId, ref errorMessage); } }
public List <string> GetYears() { using (SZPNUWContext context = new SZPNUWContext()) { return(context.Semesters.GroupBy(x => x.Academicyear).Select(x => x.Key).ToList()); } }
public InstructorModel GetInstructorByUserId(int id) { using (SZPNUWContext context = new SZPNUWContext()) { Lecturers lecturer = context.Lecturers.Include(x => x.User).FirstOrDefault(s => s.User.Id == id); if (lecturer == null) { return(null); } InstructorModel model = new InstructorModel { Id = lecturer.Id, Login = lecturer.User.Login, FirstName = lecturer.User.Firstname, LastName = lecturer.User.Lastname, PESEL = lecturer.User.Pesel, Address = lecturer.User.Address, City = lecturer.User.City, Code = lecturer.Code, DateOfBirth = lecturer.User.Dateofbirth, UserId = lecturer.Userid, UserType = (UserTypes)lecturer.User.Usertype, }; return(model); } }
public List <ProjectSubjectModel> GetProjectSubjectByInstructorId(int userId) { using (SZPNUWContext context = new SZPNUWContext()) { List <ProjectSubjectModel> list = new List <ProjectSubjectModel>(); List <Projects> projects = context.Projects.Include(x => x.Subject).Include(x => x.Lecturer).Where(x => x.Lecturer.Userid == userId).ToList(); projects.ForEach(x => { ProjectModel project = new ProjectModel() { Id = x.Id, Topic = x.Topic, Active = x.Active, Description = x.Description, UserId = x.Lecturer.Userid, SubjectId = x.Subjectid }; SubjectModel subject = new SubjectModel() { Id = x.Subject.Id, Description = x.Subject.Description, LeaderId = x.Subject.Leaderid, Name = x.Subject.Name }; list.Add(new ProjectSubjectModel(project, subject)); }); return(list); } }
public List <int> GetSemestersNum() { using (SZPNUWContext context = new SZPNUWContext()) { return(context.Semesters.GroupBy(x => x.Semesternumber).Select(x => x.Key).ToList()); } }
public List <SubjectModel> GetSubjects(string department, int semesterNumber, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { List <int> subjectsId; List <Subjects> subjects = new List <Subjects>(); try { subjectsId = this.GetSubjectIdByDepartmentAndSemesterNum(context, department, semesterNumber, ref errorMessage); if (subjectsId.AnyLazy()) { subjects = context.Subjects.Where(x => subjectsId.Contains(x.Id)).ToList(); } } catch (ArgumentNullException) { errorMessage = PortalMessages.MissingSubject; return(null); } List <SubjectModel> result = subjects.Select(x => new SubjectModel { Id = x.Id, Description = x.Description, Name = x.Name, LeaderId = x.Leaderid }).ToList(); return(result); } }
public List <SysLogModel> GetSysLogs() { using (SZPNUWContext context = new SZPNUWContext()) { return(context.Syslogs.OrderBy(x => x.Date).Select(x => new SysLogModel { Id = x.Id, Name = x.Name, Details = x.Details, Date = x.Date }).ToList()); } }
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(); } }
public void DeleteMeeting(int projectId) { using (SZPNUWContext context = new SZPNUWContext()) { Meetings meeting = new Meetings { Id = projectId }; context.Meetings.Attach(meeting); context.Meetings.Remove(meeting); context.SaveChanges(); } }
public void DeleteProject(int projectId) { using (SZPNUWContext context = new SZPNUWContext()) { Projects project = new Projects { Id = projectId }; context.Projects.Attach(project); context.Projects.Remove(project); context.SaveChanges(); } }
public void DeleteReport(int id) { using (SZPNUWContext context = new SZPNUWContext()) { Reports report = new Reports { Id = id }; context.Reports.Attach(report); context.Reports.Remove(report); context.SaveChanges(); } }
public void SaveReport(FileModel model) { using (SZPNUWContext context = new SZPNUWContext()) { Reports report = new Reports() { Sectionid = model.SectionId.Value, Filename = model.FileName, Content = model.Content }; context.Reports.Add(report); context.SaveChanges(); } }
public SubjectSemesterModel GetSubjectSemester(int subjectId, int semesterId) { using (SZPNUWContext context = new SZPNUWContext()) { Subjectssemesters subsem = context.Subjectssemesters.FirstOrDefault(x => x.Subjectid == subjectId && x.Semesterid == semesterId); return(subsem == null ? null : new SubjectSemesterModel { Id = subsem.Id, SemesterId = subsem.Semesterid, SubjectId = subsem.Subjectid }); } }
public void AddSemester(SemesterModel model) { using (SZPNUWContext context = new SZPNUWContext()) { Semesters semester = new Semesters() { Fieldofstudy = model.Department, Academicyear = model.Year, Semesternumber = model.SemesterNumber }; context.Add(semester); context.SaveChanges(); } }