public void DeleteExam(int examId)
        {
            Contract.Requires<ArgumentOutOfRangeException>(examId > 0, "The examId must be > 0!");

            using (var context = new SchoolContext())
            {
                var examToBeDeleted = new Exam()
                {
                    ExamId = examId
                };

                try
                {
                    context.Exams.Attach(examToBeDeleted);
                    context.Exams.Remove(examToBeDeleted);

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        Logger.Write("The exam " + examToBeDeleted + " was successfully removed!", "General", 2, 2, TraceEventType.Information);
                         * */
                    }/*
                    else
                    {
                        Logger.Write("The exam " + examToBeDeleted + " was not removed!", "Important", 1, 1, TraceEventType.Error);
                    }*/
                }
                catch
                {
                    throw new NoSuchEntityException("The semester with the id=" + examToBeDeleted + " does not exist in the database");
                }
            }
        }
        public void DeleteEmail(Email email)
        {
            Contract.Requires<ArgumentNullException>(email != null, "The email must be non-null!");

            using (var context = new SchoolContext())
            {
                context.Emails.Attach(email);
                context.Emails.Remove(email);

                if (context.SaveChanges() != 0)
                {
                    /*
                    if (!Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The email " + email + " was successfully removed!", "General", 2, 2,
                            TraceEventType.Information);
                    }*/
                }/*
                {
                    if (!Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The email " + email + " was not removed!", "Important", 1, 1, TraceEventType.Error);
                    }
                }*/
            }
        }
        public void AddStudent(Student student)
        {
            Contract.Requires<ArgumentNullException>(student != null, "The student cannot be null!");

            using (var context = new SchoolContext())
            {
                context.Students.Add(student);

                if (context.SaveChanges() != 0)
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The student: " + student + " has been successfully added!", "General", 2, 2, TraceEventType.Information);
                    }*/
                }/*
                else
                {
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The student: " + student + " insertion has failed!", "Important", 1, 1, TraceEventType.Error);
                    }
                }*/
            }
        }
        public void DeleteCourse(Course course)
        {
            Contract.Requires<ArgumentNullException>(course != null, "The course must be non-null!");

            using (var context = new SchoolContext())
            {
                context.Courses.Attach(course);
                context.Courses.Remove(course);

                if (context.SaveChanges() != 0)
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The course " + course + " was successfully removed!", "General", 2, 2,
                            TraceEventType.Information);
                    }*/
                }/*
                else
                {

                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The course " + course + " was not removed!", "Important", 1, 1,
                            TraceEventType.Error);
                    }
                }*/
            }
        }
        public void AddSemester(Semester semester)
        {
            Contract.Requires<ArgumentNullException>(semester != null, "The semester must be non-null!");

            using (var context = new SchoolContext())
            {
                context.Semesters.Add(semester);

                if (context.SaveChanges() != 0)
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The semester: " + semester + " was successfully inserted!", "General", 2, 2, TraceEventType.Information);
                    } */
                }/*
                else
                {
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The semester: " + semester + " was not inserted!", "Important", 1, 1,
                            TraceEventType.Error);
                    }
                }*/
            }
        }
        public void AddCourse(Course course)
        {
            Contract.Requires<ArgumentNullException>(course != null, "The course must be non-null!");

            using (var context = new SchoolContext())
            {
                context.Courses.Add(course);

                if (context.SaveChanges() != 0)
                {

                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The course: " + course + " was successfully inserted!", "General", 2, 2,
                            TraceEventType.Information);
                    }
                }

                else
                {
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The course: " + course + " was not inserted!", "Important", 1, 1,
                            TraceEventType.Error);
                    }
                }
            }
        }
        public void DeleteAddress(Address address)
        {
            Contract.Requires<ArgumentNullException>(address != null, "The address must be non-null!");

            using (var context = new SchoolContext())
            {
                try
                {
                    context.Addresses.Attach(address);
                    context.Addresses.Remove(address);

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        Logger.Write("The address " + address + " was successfully removed!", "General", 2, 2, TraceEventType.Information);
                         */
                    }/*
                    else
                    {
                        Logger.Write("The address " + address + " was not removed!", "Important", 1, 1, TraceEventType.Error);
                    }*/
                }
                catch
                {
                    throw new NoSuchEntityException("The semester with the id=" + address + " does not exist in the database");
                }
            }
        }
        public void DeleteStudent(Student student)
        {
            Contract.Requires<ArgumentNullException>(student != null, "The student must be non-null!");

            try
            {
                using (var context = new SchoolContext())
                {
                    var studentToBeDeleted = (from us in context.Students
                                           where us.StudentId == student.StudentId
                                           select us).SingleOrDefault();
                    if (studentToBeDeleted == null)
                    {
                        /*
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The user does not exist in the database ", "General", 2, 2,
                                TraceEventType.Information);
                        }*/
                        throw new Exception();
                    }
                    else
                    {
                        context.Students.Attach(studentToBeDeleted);
                        context.Students.Remove(studentToBeDeleted);

                        if (context.SaveChanges() != 0)
                        {
                            /*
                            if (Logger.IsLoggingEnabled())
                            {
                                Logger.Write("The student " + student + " was successfully removed!", "General", 2, 2,
                                    TraceEventType.Information);
                            }*/
                        }/*
                        else
                        {
                            if (Logger.IsLoggingEnabled())
                            {
                                Logger.Write("The student " + student + " was not removed!", "Important", 1, 1,
                                    TraceEventType.Error);
                            }
                        }*/
                    }
                }
            }
            catch (Exception ex)
            {
                /*
                if (Logger.IsLoggingEnabled())
                {
                    Logger.Write("Error: " + ex.Message, "Important", 1, 1, TraceEventType.Error);
                    Logger.Write("The student with the id=" + student.StudentId + " does not exist in the database", "Important", 1, 1, TraceEventType.Error);
                }*/

                throw new NoSuchEntityException("The student with the id=" + student.StudentId + " does not exist in the database");
            }
        }
        public void AddPhone(Phone phone)
        {
            Contract.Requires<ArgumentNullException>(phone != null, "The phone must be non-null!");

            using (var context = new SchoolContext())
            {
                context.Phones.Add(phone);

                if (context.SaveChanges() != 0)
                {
                    /*
                    Logger.Write("The phone: " + phone + " was successfully inserted!", "General", 2, 2, TraceEventType.Information);
                     * */
                }/*
                else
                {
                    Logger.Write("The phone: " + phone + " was not inserted!", "Important", 1, 1, TraceEventType.Error);
                }*/
            }
        }
        public void DeleteExam(DomainModel.Exam exam)
        {
            Contract.Requires<ArgumentNullException>(exam != null, "The exam must be non-null!");

            using (var context = new SchoolContext())
            {
                context.Exams.Attach(exam);
                context.Exams.Remove(exam);

                if (context.SaveChanges() != 0)
                {
                    /*
                    Logger.Write("The exam " + exam + " was successfully removed!", "General", 2, 2, TraceEventType.Information);
                     * */
                }/*
                else
                {
                    Logger.Write("The exam " + exam + " was not removed!", "Important", 1, 1, TraceEventType.Error);
                }*/
            }
        }
        public void DeleteSemester(Semester semester)
        {
            Contract.Requires<ArgumentNullException>(semester != null, "The semester must be non-null!");

            using (var context = new SchoolContext())
            {
                try
                {
                    var semesterToBeDeleted = new Semester()
                    {
                        SemesterId = semester.SemesterId
                    };
                    context.Semesters.Attach(semesterToBeDeleted);
                    context.Semesters.Remove(semesterToBeDeleted);

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The semester " + semester + " was successfully removed!", "General", 2, 2,
                                TraceEventType.Information);
                        }*/
                    }/*
                else
                {
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The semester " + semester + " was not removed!", "Important", 1, 1,
                            TraceEventType.Error);
                    }
                }*/
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
        }
 public void AddExam(DomainModel.Exam exam)
 {
     using (var context = new SchoolContext())
     {
         context.Exams.Add(exam);
         if (context.SaveChanges() != 0)
         {
             /*
             if (Logger.IsLoggingEnabled())
             {
                 Logger.Write("The exam: " + exam + " has been successfully added!", "General", 2, 2, TraceEventType.Information);
             }*/
         } /*
         else
         {
             if (Logger.IsLoggingEnabled())
             {
                 Logger.Write("The exam: " + exam + " insertion has failed!", "Important", 1, 1, TraceEventType.Error);
             }
         }*/
     }
 }
        public void AddAddress(Address address)
        {
            using (var context = new SchoolContext())
            {
                context.Addresses.Add(address);

                if (context.SaveChanges() != 0)
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The address: " + address + " has been successfully added!", "General", 2, 2, TraceEventType.Information);
                    }*/
                }
                /*else
                {
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The address: " + address + " insertion has failed!", "Important", 1, 1, TraceEventType.Error);
                    }
                }*/
            }
        }
        public void DeleteSemester(int semesterId)
        {
            Contract.Requires<ArgumentOutOfRangeException>(semesterId > 0, "The semesterId must be > 0!");

            using (var context = new SchoolContext())
            {
                var semesterToBeDeleted = new Semester
                {
                    SemesterId = semesterId
                };

                context.Semesters.Attach(semesterToBeDeleted);
                context.Semesters.Remove(semesterToBeDeleted);

                try
                {
                    if (context.SaveChanges() != 0)
                    {
                        /*
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The semester " + semesterToBeDeleted + " was successfully removed!", "General",
                                2, 2, TraceEventType.Information);
                        }*/
                    }/*
                    else
                    {
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The semester " + semesterToBeDeleted + " was not removed!", "Important", 1, 1,
                                TraceEventType.Error);
                        }
                    }*/
                }
                catch
                {
                    throw new NoSuchEntityException("The semester with the id=" + semesterToBeDeleted + " does not exist in the database");
                }

            }
        }
        public Semester UpdateSemester(int semesterId, string name, DateTime startDate, DateTime endDate)
        {
            Contract.Requires<ArgumentOutOfRangeException>(semesterId > 0, "The semesterId must be > 0!");
            Contract.Requires<ArgumentNullException>(name != null, "The name must be non-null!");
            Contract.Requires<ArgumentNullException>(startDate != null, "The startDate must be non-null!");
            Contract.Requires<ArgumentNullException>(endDate != null, "The endDate must be non-null!");

            using (var context = new SchoolContext())
            {
                var semester = context.Semesters.SingleOrDefault(s => s.SemesterId == semesterId);

                if (semester != null)
                {
                    semester.Name = name;
                    semester.StartDate = startDate;
                    semester.EndDate = endDate;

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The semester " + semester + " was successfully updated!", "General", 2, 2,
                                TraceEventType.Information);
                        }
                         * */
                    }/*
                    else
                    {
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The semester " + semester + " was not updated!", "Important", 1, 1,
                                TraceEventType.Error);
                        }
                    }*/
                }
                else
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The semester with id: " + semesterId + " doesn't exist in the database!",
                            "Important", 1, 1, TraceEventType.Error);
                    }*/

                    throw new NoSuchEntityException("The semester with id: " + semesterId +
                                                    " doesn't exist in the database!");
                }

                return semester;
            }
        }
        public Course UpdateCourse(int courseId, string name, string description, int credits, decimal cost,
            string currency)
        {
            Contract.Requires<ArgumentOutOfRangeException>(courseId > 0, "The courseId must be > 0!");
            Contract.Requires<ArgumentNullException>(name != null, "The name must be non-null!");
            Contract.Requires<ArgumentNullException>(description != null, "The description must be non-null!");
            Contract.Requires<ArgumentOutOfRangeException>(credits > 0 && credits < 7,
                "The credits must be in the specified interval!");
            Contract.Requires<ArgumentOutOfRangeException>(cost > 0, "The cost must be > 0!");
            Contract.Requires<ArgumentNullException>(currency != null, "The currency must be non-null!");

            using (var context = new SchoolContext())
            {
                var courseToBeUpdated = context.Courses.SingleOrDefault(c => c.CourseId == courseId);

                if (courseToBeUpdated != null)
                {
                    courseToBeUpdated.Name = name;
                    courseToBeUpdated.Description = description;
                    courseToBeUpdated.Credits = credits;
                    courseToBeUpdated.Cost = cost;
                    courseToBeUpdated.Currency = currency;

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The course " + courseToBeUpdated + " was successfully updated!", "General", 2,
                                2, TraceEventType.Information);
                        }*/
                    } /*
                    else
                    {

                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The course " + courseToBeUpdated + " was not updated!", "Important", 1, 1,
                                TraceEventType.Error);
                        }
                    }*/
                }
                else
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The course with id: " + courseId + " doesn't exist in the database!", "Important",
                            1, 1, TraceEventType.Error);
                    }
                    */
                    throw new NoSuchEntityException("The course with id: " + courseId +
                                                    " doesn't exist in the database!");
                }

                return courseToBeUpdated;
            }
        }
        public void DeleteStudent(int studentId)
        {
            Contract.Requires<ArgumentOutOfRangeException>(studentId > 0, "The studentId must be > 0!");

            using (var context = new SchoolContext())
            {
                var studentToBeDeleted = new Student
                {
                    StudentId = studentId
                };

                try
                {
                    context.Students.Attach(studentToBeDeleted);
                    context.Students.Remove(studentToBeDeleted);

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The student " + studentToBeDeleted + " was successfully removed!", "General",
                                2, 2, TraceEventType.Information);
                        }*/
                    }/*
                    else
                    {
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The student " + studentToBeDeleted + " was not removed!", "Important", 1, 1,
                                TraceEventType.Error);
                        }
                    }*/
                }
                catch (Exception ex)
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("Error: " + ex.Message, "Important", 1, 1, TraceEventType.Error);
                        Logger.Write("The student with the id=" + studentToBeDeleted.StudentId + " does not exist in the database", "Important", 1, 1, TraceEventType.Error);
                    }*/

                    throw new NoSuchEntityException("The student with the id=" + studentToBeDeleted.StudentId + " does not exist in the database");
                }
            }
        }
        public DomainModel.Email UpdateEmail(int emailId, string emailAddress)
        {
            Contract.Requires<ArgumentOutOfRangeException>(emailId > 0, "The emailId must be > 0!");
            Contract.Requires<ArgumentNullException>(emailAddress != null, "The emailAddress must be non-null!");

            using (var context = new SchoolContext())
            {
                var emailToBeUpdated = context.Emails.SingleOrDefault(e => e.EmailId == emailId);

                if (emailToBeUpdated != null)
                {
                    emailToBeUpdated.EmailAddress = emailAddress;

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        if (!Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The email " + emailToBeUpdated + " was successfully updated!", "General", 2, 2,
                                TraceEventType.Information);
                        }*/
                    }/*
                    else
                    {

                        if (!Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The email " + emailToBeUpdated + " was not updated!", "Important", 1, 1,
                                TraceEventType.Error);
                        }
                    }*/
                }
                else
                {
                    if (!Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The email with id: " + emailId + " doesn't exist in the database!", "Important", 1,
                            1, TraceEventType.Error);
                    }
                    throw new NoSuchEntityException("The email with id: " + emailId +
                                                    " doesn't exist in the database!");
                }

                return emailToBeUpdated;
            }
        }
        public Student UpdateStudent(int studentId, string firstName, string lastName, string cnp, int sid, DateTime enrollmentDate)
        {
            Contract.Requires<ArgumentOutOfRangeException>(studentId > 0, "The studentId must be > 0!");
            Contract.Requires<ArgumentNullException>(firstName != null, "The name must be non-null!");
            Contract.Requires<ArgumentNullException>(lastName != null, "The name must be non-null!");
            Contract.Requires<ArgumentNullException>(cnp != null, "The cnp must be > 0!");
            Contract.Requires<ArgumentOutOfRangeException>(sid > 0, "The registrationNumber must be non-null!");
            Contract.Requires<ArgumentNullException>(enrollmentDate != null, "The enrollmentDate must be non-null!");

            using (var context = new SchoolContext())
            {
                var studentToBeUpdated = context.Students.SingleOrDefault(s => s.StudentId == studentId);

                if (studentToBeUpdated != null)
                {
                    studentToBeUpdated.FirstName = firstName;
                    studentToBeUpdated.LastName = lastName;
                    studentToBeUpdated.CNP = cnp;
                    studentToBeUpdated.SID = sid;
                    studentToBeUpdated.EnrollmentDate = enrollmentDate;

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The student " + studentToBeUpdated + " was successfully updated!", "General",
                                2, 2, TraceEventType.Information);
                        }*/
                    }/*
                    else
                    {
                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The student " + studentToBeUpdated + " was not updated!", "Important", 1, 1,
                                TraceEventType.Error);
                        }
                    }*/

                    return studentToBeUpdated;
                }

                /*
                if (Logger.IsLoggingEnabled())
                {
                    Logger.Write("The student with id: " + studentId + " doesn't exist in the database!",
                        "Important", 1, 1, TraceEventType.Error);
                }*/

                throw new NoSuchEntityException("The student with id: " + studentId +
                                                " doesn't exist in the database!");
            }
        }
        public DomainModel.Exam UpdateExam(int examId, int grade)
        {
            Contract.Requires<ArgumentOutOfRangeException>(examId > 0, "The examId must be > 0!");
            Contract.Requires<ArgumentOutOfRangeException>(grade > 0.0f, "The name must be > 0!");

            using (var context = new SchoolContext())
            {
                var examToBeUpdated = context.Exams.SingleOrDefault(e => e.ExamId == examId);

                if (examToBeUpdated != null)
                {
                    examToBeUpdated.Grade = grade;

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        Logger.Write("The exam " + examToBeUpdated + " was successfully updated!", "General", 2, 2, TraceEventType.Information);
                         * */
                    }/*
                    else
                    {
                        Logger.Write("The exam " + examToBeUpdated + " was not updated!", "Important", 1, 1, TraceEventType.Error);
                    }*/
                }
                else
                {
                    /*
                    Logger.Write("The exam with id: " + examId + " doesn't exist in the database!", "Important", 1, 1, TraceEventType.Error);
                     * */
                    throw new NoSuchEntityException("The exam with id: " + examId +
                                                    " doesn't exist in the database!");
                }

                return examToBeUpdated;
            }
        }
        public Phone UpdatePhone(int phoneId, string phoneNumber)
        {
            Contract.Requires<ArgumentOutOfRangeException>(phoneId > 0, "The phoneId must be > 0!");
            Contract.Requires<ArgumentNullException>(phoneNumber != null, "The phoneNumber must be non-null!");

            using (var context = new SchoolContext())
            {
                var phoneToBeUpdated = context.Phones.SingleOrDefault(p => p.PhoneId == phoneId);

                if (phoneToBeUpdated != null)
                {
                    phoneToBeUpdated.PhoneNumber = phoneToBeUpdated.PhoneNumber;

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        Logger.Write("The phone " + phoneToBeUpdated + " was successfully updated!", "General", 2, 2, TraceEventType.Information);
                         * */
                    }/*
                    else
                    {
                        Logger.Write("The phone " + phoneToBeUpdated + " was not updated!", "Important", 1, 1, TraceEventType.Error);
                    }*/
                }
                else
                {
                    /*
                    Logger.Write("The phone with id: " + phoneId + " doesn't exist in the database!", "Important", 1, 1, TraceEventType.Error);
                     * */
                    throw new NoSuchEntityException("The phone with id: " + phoneId +
                                                    " doesn't exist in the database!");
                }

                return phoneToBeUpdated;
            }
        }
        public Address UpdateAddress(int studentId, string street, string city, string state, string country, string postalCode)
        {
            Contract.Requires<ArgumentOutOfRangeException>(studentId > 0, "The studentId must be > 0!");
            Contract.Requires<ArgumentNullException>(street != null, "The street must be non-null!");
            Contract.Requires<ArgumentNullException>(city != null, "The city must be non-null!");
            Contract.Requires<ArgumentNullException>(state != null, "The state must be non-null!");
            Contract.Requires<ArgumentNullException>(state != null, "The country must be non-null!");
            Contract.Requires<ArgumentNullException>(postalCode != null, "The postal code must be non-null!");

            using (var context = new SchoolContext())
            {

                    var addressToBeUpdated = (context.Addresses.Where(a => a.StudentId == studentId)).SingleOrDefault();

                    if (addressToBeUpdated != null)
                    {
                        addressToBeUpdated.Street = street;
                        addressToBeUpdated.City = city;
                        addressToBeUpdated.State = state;
                        addressToBeUpdated.Country = country;
                        addressToBeUpdated.PostalCode = postalCode;

                        if (context.SaveChanges() != 0)
                        {
                            /*
                            Logger.Write("The address " + addressToBeUpdated + " was successfully updated!", "General", 2, 2, TraceEventType.Information);
                             */
                        }/*
                        else
                        {
                            Logger.Write("The address " + addressToBeUpdated + " was not updated!", "Important", 1, 1, TraceEventType.Error);
                        }*/
                    }
                    else
                    {
                        Logger.Write("The address with id: " + studentId + " doesn't exist in the database!", "Important", 1, 1, TraceEventType.Error);
                        throw new NoSuchEntityException("The address with id: " + studentId +
                                                        " doesn't exist in the database!");
                    }

                    return addressToBeUpdated;
            }
        }