Esempio n. 1
0
 static bool createStudent(Student student)
 {
     //Adds student to db
     using (var contxt = new SchoolDBEntities())
     {
         contxt.Students.Add(student);
         contxt.SaveChanges();
     }
     return true;
 }
Esempio n. 2
0
 static bool createTeacher(Teacher teach)
 {
     //Add teacher to db
     using (var contxt = new SchoolDBEntities())
     {
         contxt.Teachers.Add(teach);
         contxt.SaveChanges();
     }
     return true;
 }
Esempio n. 3
0
 static bool createStandard(Standard stndrd)
 {
     //Add standard to db
     using (var contxt = new SchoolDBEntities())
     {
         contxt.Standards.Add(stndrd);
         contxt.SaveChanges();
     }
     return true;
 }
Esempio n. 4
0
        static bool deleteStudentAddr(String studentName)
        {
            //Removes a particular students address
            Student toDel;
            var contxt = new SchoolDBEntities();

            toDel = contxt.Students.Where(st => st.StudentName == studentName).FirstOrDefault<Student>();
            contxt.Entry(toDel.StudentAddress).State = System.Data.Entity.EntityState.Deleted;
            contxt.SaveChanges();
            return true;
        }
Esempio n. 5
0
        static bool updateTeachIDDisconnect(Teacher toChange, Teacher changeTo)
        {
            //Change standard description based on what is passed in
            //Disconnected mode
            Teacher toUpdate;
            Teacher change;
            using (var contxt = new SchoolDBEntities())
            {
                toUpdate = contxt.Teachers.Where(st => st.TeacherName == toChange.TeacherName).FirstOrDefault<Teacher>();
                change = contxt.Teachers.Where(st => st.TeacherName == changeTo.TeacherName).FirstOrDefault<Teacher>();
            }

            if (toUpdate != null && change != null)
            {
                toUpdate.StandardId = change.StandardId;
            }
            else
            {
                return false;
            }

            using (var contxt1 = new SchoolDBEntities())
            {
                contxt1.Entry(toUpdate).State = System.Data.Entity.EntityState.Modified;
                contxt1.SaveChanges();
            }
            return true;
        }
Esempio n. 6
0
        static bool updateTeachID(Teacher toChange, Teacher changeTo)
        {
            //Change standard description based on what is passed in
            var contxt = new SchoolDBEntities();
            Teacher toUpdate;
            Teacher change;

            toUpdate = contxt.Teachers.Where(st => st.TeacherName== toChange.TeacherName).FirstOrDefault<Teacher>();
            change = contxt.Teachers.Where(st => st.TeacherName == changeTo.TeacherName).FirstOrDefault<Teacher>();

            if (toUpdate != null)
            {
                toUpdate.StandardId = change.StandardId;
            }
            else
            {
                return false;
            }
            contxt.Entry(toUpdate).State = System.Data.Entity.EntityState.Modified;
            contxt.SaveChanges();

            return true;
        }
Esempio n. 7
0
 static bool updateStudentDisconnect(String studentName, String newAddr)
 {
     Student toUpdate;
     //Update student address in disconnected mode
     using (var contxt = new SchoolDBEntities())
     {
         toUpdate = contxt.Students.Where(st => st.StudentName == studentName).FirstOrDefault<Student>();
     }
     if (toUpdate != null)
     {
         toUpdate.StudentAddress.Address1 = newAddr;
     }
     else
     {
         return false;
     }
     using (var contxt1 = new SchoolDBEntities())
     {
         contxt1.Entry(toUpdate).State = System.Data.Entity.EntityState.Modified;
         contxt1.SaveChanges();
     }
     return true;
 }
Esempio n. 8
0
        static bool updateStudent(String studentName, String newAddr)
        {
            //Updates a student based on whats passed in to the function
            var contxt = new SchoolDBEntities();
            Student toUpdate;

            toUpdate = contxt.Students.Where(st => st.StudentName == studentName).FirstOrDefault<Student>();

            if(toUpdate != null)
            {
                toUpdate.StudentAddress.Address1 = newAddr;
            }
            else
            {
                return false;
            }
            contxt.Entry(toUpdate).State = System.Data.Entity.EntityState.Modified;
            contxt.SaveChanges();

            return true;
        }
Esempio n. 9
0
        static bool updateStandard(String standardName, String newDescription)
        {
            //Change standard description based on what is passed in
            var contxt = new SchoolDBEntities();
            Standard toUpdate;

            toUpdate = contxt.Standards.Where(st => st.StandardName == standardName).FirstOrDefault<Standard>();

            if (toUpdate != null)
            {
                toUpdate.Description = newDescription;
            }
            else
            {
                return false;
            }
            contxt.Entry(toUpdate).State = System.Data.Entity.EntityState.Modified;
            contxt.SaveChanges();

            return true;
        }
Esempio n. 10
0
        static String readTeachers(String teacherName, int byName)
        {
            var contxt = new SchoolDBEntities();
            string teachers = "";
            //Return all teachers in db
            if (teacherName.Trim().Equals("*"))
            {
                var retTeach = from tch in contxt.Teachers
                               select tch;

                foreach (Teacher teacher in retTeach)
                {
                    if (teacher.TeacherName != null && teacher.TeacherName != null)
                    {
                        teachers += "\n\n\nName     : " + teacher.TeacherName
                                    + "\nDescription: " + teacher.Standard.Description
                                    +"\nID: " + teacher.Standard.StandardId;
                    }
                    else
                    {
                        teachers += null;
                    }
                }
            }
            //Explicit teacher name
            else
            {
                var retTeacher = contxt.Teachers.Where(tch => tch.TeacherName == teacherName).FirstOrDefault<Teacher>();
                if (retTeacher.TeacherName != null && retTeacher.TeacherName != null)
                {
                    teachers += "\n\n\nName     : " + retTeacher.TeacherName
                                + "\nDescription: " + retTeacher.Standard.Description
                                + "\nID: " + retTeacher.Standard.StandardId;
                }
                else
                {
                    teachers += null;
                }
            }
            return teachers;
        }
Esempio n. 11
0
        static String readStudents(String studentName)
        {
            var contxt = new SchoolDBEntities();
            string students = "";

            //Return all students in db
            if (studentName.Trim().Equals("*"))
            {
                var retStudent = from st in contxt.Students
                                 select st;

                foreach (Student student in retStudent)
                {
                    if (student.StudentName != null && student.StudentAddress != null && student.StudentAddress.Address1 != null && student.StudentAddress.Address2 != null)
                    {
                        students += "\n\n\nName     : " + student.StudentName
                                    + "\nAddress 1: " + student.StudentAddress.Address1
                                    + "\nAddress 2: " + student.StudentAddress.Address2
                                    + "\n " + student.StudentAddress.City + " " + student.StudentAddress.State;
                    }
                    else
                    {
                        students += "\n\n\nName     : " + student.StudentName
                                    + "\nAddress 1: null"
                                    + "\nAddress 2: null";
                    }
                }
            }
            else
            {
                var retStudent = contxt.Students.Where(st => st.StudentName == studentName).FirstOrDefault<Student>();
                if (retStudent.StudentName != null && retStudent.StudentAddress != null && retStudent.StudentAddress.Address1 != null && retStudent.StudentAddress.Address2 != null)
                {
                    students += "\n\n\nName     : " + retStudent.StudentName
                                + "\nAddress 1: " + retStudent.StudentAddress.Address1
                                + "\nAddress 2: " + retStudent.StudentAddress.Address2
                                + "\n " + retStudent.StudentAddress.City + " " + retStudent.StudentAddress.State;
                }
                else
                {
                    students += "\n\n\nName     : " + retStudent.StudentName
                                    + "\nAddress 1: null"
                                    + "\nAddress 2: null";
                }
            }
            return students;
        }
Esempio n. 12
0
        static String readStandards(String standardName)
        {
            var contxt = new SchoolDBEntities();
            string standards = "";

            //Return all standards in db
            if (standardName.Trim().Equals("*"))
            {

                var retStandards = from st in contxt.Standards
                                 select st;

                foreach (Standard standard in retStandards)
                {
                    if (standard.Description != null && standard.StandardName != null )
                    {
                        standards += "\n\n\nName     : " + standard.StandardName
                                    + "\nDescription: " + standard.Description;
                    }
                    else
                    {
                        standards += null;
                    }
                }
            }
            else
            {
                var retStandard = contxt.Standards.Where(st => st.StandardName == standardName).FirstOrDefault<Standard>();
                if (retStandard.Description != null && retStandard.StandardName != null)
                {
                    standards += "\n\n\nName     : " + retStandard.StandardName
                                 + "\nDescription: " + retStandard.Description;
                }
                else
                {
                    standards += null;
                }

            }

            return standards;
        }