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); } }
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 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 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 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 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); } }
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 bool AddSubject(SubjectModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { if (!context.Subjects.Where(x => x.Name == model.Name).AnyLazy()) { Subjects subject = new Subjects() { Name = model.Name, Description = model.Description, Leaderid = model.LeaderId.Value }; Subjectssemesters subSem = new Subjectssemesters(); using (var transaction = context.Database.BeginTransaction()) { try { context.Add(subject); context.SaveChanges(); int id = context.Subjects.Where(x => x.Name == subject.Name).Select(x => x.Id).First(); subSem.Subjectid = id; subSem.Semesterid = model.SemesterId.Value; context.Add(subSem); context.SaveChanges(); transaction.Commit(); return(true); } catch (Exception) { transaction.Rollback(); errorMessage = PortalMessages.InvalidData; } } } else { errorMessage = PortalMessages.SubjectExist; } return(false); } }
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 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 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 AddMeeting(MeetingModel model) { using (SZPNUWContext context = new SZPNUWContext()) { Meetings meeting = new Meetings { Rating = model.Rate, Dateofentry = model.Date, Studentssectionsid = model.SectionStudentId }; context.Meetings.Add(meeting); context.SaveChanges(); } }
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(); } }
public bool UpdateSection(SectionModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Sections section = context.Sections.FirstOrDefault(s => s.Id == model.Id); if (section != null) { section.Projectid = model.ProjectId; context.SaveChanges(); return(true); } errorMessage = PortalMessages.NoSuchElement; return(false); } }
public bool UpdateStudentSection(StudentSectionModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Studentssections studentSection = context.Studentssections.FirstOrDefault(x => x.Id == model.Id); if (studentSection != null) { studentSection.Rating = model.Rate; studentSection.Dateofentry = model.Date; context.SaveChanges(); return(true); } errorMessage = PortalMessages.NoSuchElement; return(false); } }
public bool UpdateMeeting(MeetingModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Meetings meeting = context.Meetings.FirstOrDefault(s => s.Id == model.Id); if (meeting != null) { meeting.Rating = model.Rate; meeting.Dateofentry = model.Date; context.SaveChanges(); return(true); } errorMessage = PortalMessages.NoSuchElement; return(false); } }
public bool UpdateSubject(SubjectModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Subjects subject = context.Subjects.FirstOrDefault(x => x.Id == model.Id); if (subject != null) { subject.Name = model.Name; subject.Description = model.Description; context.SaveChanges(); return(true); } errorMessage = PortalMessages.NoSuchElement; return(false); } }
public bool UpdateSemester(SemesterModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Semesters semester = context.Semesters.FirstOrDefault(x => x.Id == model.Id); if (semester != null) { semester.Fieldofstudy = model.Department; semester.Academicyear = model.Year; semester.Semesternumber = model.SemesterNumber; context.SaveChanges(); return(true); } errorMessage = PortalMessages.NoSuchElement; return(false); } }
public void InsertSysLog(SysLogModel model) { using (SZPNUWContext context = new SZPNUWContext()) { Syslog sysLog = new Syslog { Name = model.Name, Details = model.Details, Date = model.Date }; try { context.Syslogs.Add(sysLog); context.SaveChanges(); } catch { } } }
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); }
public bool AddSubjectSemester(SubjectSemesterModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { if (!context.Subjectssemesters.Where(x => x.Subjectid == model.SubjectId && x.Semesterid == model.SemesterId).AnyLazy()) { Subjectssemesters subSem = new Subjectssemesters(); subSem.Subjectid = model.SubjectId; subSem.Semesterid = model.SemesterId; context.Add(subSem); context.SaveChanges(); return(true); } else { errorMessage = PortalMessages.ObjectExist; } return(false); } }
public bool ChangePassword(int userId, ChangePasswordModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Users user = context.Users.FirstOrDefault(s => s.Id == userId); if (user != null) { if (user.Password == SecurityService.GetSHA256Hash(model.OldPassword)) { user.Password = SecurityService.GetSHA256Hash(model.NewPassword); context.SaveChanges(); return(true); } errorMessage = ValidationMessages.OldPasswordError; return(false); } errorMessage = PortalMessages.NoSuchElement; return(false); } }
public bool UpdateAdmin(UserModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Users user = context.Users.FirstOrDefault(p => p.Id == model.UserId); if (user != null) { user.Firstname = model.FirstName; user.Lastname = model.LastName; user.Pesel = model.PESEL; user.Address = model.Address; user.City = model.City; user.Dateofbirth = model.DateOfBirth; context.SaveChanges(); return(true); } errorMessage = PortalMessages.NoSuchElement; return(false); } }
public bool DeleteSection(int id, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Sections section = new Sections { Id = id }; try { context.Sections.Attach(section); context.Sections.Remove(section); context.SaveChanges(); return(true); } catch (Exception) { errorMessage = PortalMessages.SectionWithStudents; return(false); } } }
public bool UpdateInstructor(InstructorModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Lecturers lecturer = context.Lecturers.Include(x => x.User).FirstOrDefault(p => p.Id == model.Id); if (lecturer != null) { lecturer.User.Firstname = model.FirstName; lecturer.User.Lastname = model.LastName; lecturer.User.Pesel = model.PESEL; lecturer.User.Address = model.Address; lecturer.User.City = model.City; lecturer.Code = model.Code; lecturer.User.Dateofbirth = model.DateOfBirth; context.SaveChanges(); return(true); } errorMessage = PortalMessages.NoSuchElement; return(false); } }
public bool UpdateStudent(StudentModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Students student = context.Students.Include(x => x.User).FirstOrDefault(s => s.Id == model.Id); if (student != null) { student.User.Firstname = model.FirstName; student.User.Lastname = model.LastName; student.User.Pesel = model.PESEL; student.User.Address = model.Address; student.User.City = model.City; student.Albumnumber = model.AlbumNumber; student.User.Dateofbirth = model.DateOfBirth; context.SaveChanges(); return(true); } errorMessage = PortalMessages.NoSuchElement; return(false); } }
public bool RegisterStudent(StudentModel model, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { if (!context.Users.Where(x => x.Login == model.Login).Any()) { if (!context.Students.Where(x => x.Albumnumber == model.AlbumNumber).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.Student }; Students student = new Students { Albumnumber = model.AlbumNumber, }; user.Students = student; try { Semesters semester = context.Semesters.First(x => x.Id == model.Semester.Id); student.Studentsemester.Add(new Studentsemester { Semester = semester }); context.Add(user); context.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw new Exception(PortalMessages.InsertDBError); } } return(true); } } errorMessage = ValidationMessages.UsedLogin; return(false); } }
public bool DeleteStudentFromSection(int studentId, int sectionId, ref string errorMessage) { using (SZPNUWContext context = new SZPNUWContext()) { Studentssections section = context.Studentssections.FirstOrDefault(x => x.Sectionid == sectionId && x.Studentid == studentId); if (section != null) { try { //context.Studentssections.Attach(section); context.Studentssections.Remove(section); context.SaveChanges(); return(true); } catch (Exception) { errorMessage = PortalMessages.CanNotDeleteStudentFromSection; return(false); } } errorMessage = PortalMessages.CanNotDeleteStudentFromSection; return(false); } }
public int?AddSections(SectionsCreateModel model, ref string errorMessage) { int MAX_SECTIONS = 50; int c; int?subSemId; int notCreated = 0; using (SZPNUWContext context = new SZPNUWContext()) { subSemId = context.Subjectssemesters.Where(x => x.Subjectid == model.SubjectId && x.Semesterid == model.SemesterId).Select(x => x.Id).FirstOrDefault(); if (subSemId.HasValue) { c = context.Sections.Where(s => s.Subcjetsemesterid == subSemId).ToList().Count; int i = 0; while (i < model.Count && c < MAX_SECTIONS) { try { context.Sections.Add(new Sections { Subcjetsemesterid = subSemId.Value, Sectionnumber = c + 1 }); context.SaveChanges(); c++; } catch (Exception ex) { notCreated++; } i++; } return(model.Count - notCreated); } errorMessage = PortalMessages.NoSubjectOnSemester; return(null); } }