Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
 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;
             }
         }
     }
 }
Esempio n. 3
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);
     }
 }
Esempio n. 4
0
 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);
     }
 }
Esempio n. 5
0
 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);
     }
 }
Esempio n. 6
0
 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);
     }
 }
Esempio n. 7
0
 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();
     }
 }
Esempio n. 8
0
 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);
     }
 }
Esempio n. 9
0
 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();
     }
 }
Esempio n. 10
0
 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();
     }
 }
Esempio n. 11
0
 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();
     }
 }
Esempio n. 12
0
 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();
     }
 }
Esempio n. 13
0
 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();
     }
 }
Esempio n. 14
0
 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();
     }
 }
Esempio n. 15
0
 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);
     }
 }
Esempio n. 16
0
 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);
     }
 }
Esempio n. 17
0
 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);
     }
 }
Esempio n. 18
0
 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);
     }
 }
Esempio n. 19
0
 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);
     }
 }
Esempio n. 20
0
 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
         {
         }
     }
 }
Esempio n. 21
0
        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);
        }
Esempio n. 22
0
 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);
     }
 }
Esempio n. 23
0
 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);
     }
 }
Esempio n. 24
0
 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);
     }
 }
Esempio n. 25
0
 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);
         }
     }
 }
Esempio n. 26
0
 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);
     }
 }
Esempio n. 27
0
 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);
     }
 }
Esempio n. 28
0
 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);
     }
 }
Esempio n. 29
0
 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);
     }
 }
Esempio n. 30
0
        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);
            }
        }