コード例 #1
0
        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);
                    }
                }*/
            }
        }
コード例 #2
0
        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);
                    }
                }
            }
        }
コード例 #3
0
        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);
                    }
                }*/
            }
        }
コード例 #4
0
        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);
                    }
                }*/
            }
        }
コード例 #5
0
        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);
                    }
                }*/
            }
        }
コード例 #6
0
        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");
                }
            }
        }
コード例 #7
0
        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");
                }
            }
        }
コード例 #8
0
        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");
            }
        }
コード例 #9
0
        public void DeleteCourse(int courseId)
        {
            Contract.Requires<ArgumentOutOfRangeException>(courseId > 0, "The courseId must be > 0!");

            using (var context = new SchoolContext())
            {
                var courseToBeDeleted = new Course()
                {
                    CourseId = courseId
                };

                try
                {
                    context.Courses.Attach(courseToBeDeleted);
                    context.Courses.Remove(courseToBeDeleted);

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

                        if (Logger.IsLoggingEnabled())
                        {
                            Logger.Write("The course " + courseToBeDeleted + " 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 course with the id=" + courseToBeDeleted.CourseId + " does not exist in the database",
                            "Important", 1, 1, TraceEventType.Error);
                    }*/

                    throw new NoSuchEntityException("The course with the id=" + courseToBeDeleted.CourseId +
                                                    " does not exist in the database");
                }
            }
        }
コード例 #10
0
        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);
                }*/
            }
        }
コード例 #11
0
        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);
                }*/
            }
        }
コード例 #12
0
        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;
                }

            }
        }
コード例 #13
0
 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);
             }
         }*/
     }
 }
コード例 #14
0
        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);
                    }
                }*/
            }
        }
コード例 #15
0
        public bool IsSemesterInserted(int semesterId)
        {
            Contract.Requires<ArgumentOutOfRangeException>(semesterId > 0, "Semester id must be greater than zero");

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

                if (res != null)
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The semester with id: " + semesterId + "exists!", "General", 2, 2,
                            TraceEventType.Information);
                    }*/

                    return true;
                }

                /*

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

                return false;
            }
        }
コード例 #16
0
        public Semester GetSemesterById(int semesterId)
        {
            Contract.Requires<ArgumentOutOfRangeException>(semesterId > 0, "The semesterId must be > 0");

            using (var context = new SchoolContext())
            {
                var res = (from semester in context.Semesters
                           where semester.SemesterId == semesterId
                           select semester).SingleOrDefault();

                if (res != null)
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The semester was returned by id: " + res);
                    }*/
                }/*
                else
                {
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The semester with id: " + semesterId + " doesn't exist!");
                    }
                }*/

                return res;
            }
        }
コード例 #17
0
        public int GetNumberOfCoursesForSemester(int semesterId)
        {
            Contract.Requires<ArgumentOutOfRangeException>(semesterId > 0, "Semester id must be greater than 0");
            using (var context = new SchoolContext())
            {
                var singleOrDefault = context.Semesters.SingleOrDefault(s => s.SemesterId == semesterId);
                if (singleOrDefault != null)
                    return singleOrDefault.Courses.Count();

                throw new NoSuchEntityException("The semester with the specified id is not in the database");
            }
        }
コード例 #18
0
        public IList<Semester> GetAllSemesters()
        {
            using (var context = new SchoolContext())
            {
                var semesters = (from semester in context.Semesters
                    select semester).ToList();

                if (semesters.Count != 0)
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("There were successfully returned: " + semesters.Count + " semesters!", "General",
                            2, 2, TraceEventType.Information);
                    }*/
                }/*
                else
                {
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("There are no semesters in the database", "Important", 1, 1, TraceEventType.Warning);
                    }
                }*/

                return semesters;
            }
        }
コード例 #19
0
        public IList<Address> GetAllAddresss()
        {
            using (var context = new SchoolContext())
            {
                var addresses = (from address in context.Addresses
                                 select address).ToList();

                if (addresses.Count != 0)
                {
                    Logger.Write("There were successfully returned: " + addresses.Count + " addresses!", "General", 2, 2, TraceEventType.Information);
                }/*
                else
                {
                    Logger.Write("There are no addresses in the database", "Important", 1, 1, TraceEventType.Warning);
                }*/

                return addresses;
            }
        }
コード例 #20
0
        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;
            }
        }
コード例 #21
0
        public DomainModel.Email GetEmailById(int emailId)
        {
            using (var context = new SchoolContext())
            {
                var res = context.Emails.Where(e => e.EmailId == emailId).Include("Student").SingleOrDefault();

                if (res != null)
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The email was returned by id " + res, "General", 2, 2, TraceEventType.Information);
                    }*/
                }/*
                else
                {
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The email with id=" + emailId + " does not exist!", "Important", 1, 1,
                          TraceEventType.Error);
                    }
                }*/
                return res;
            }
        }
コード例 #22
0
        public IList<DomainModel.Email> GetAllEmails()
        {
            using (var context = new SchoolContext())
            {
                var emails = (from email in context.Emails
                                 select email).ToList();

                if (emails.Count != 0)
                {
                    /*
                    if (!Logger.IsLoggingEnabled())
                    {
                        Logger.Write("There were successfully returned: " + emails.Count + " emails!", "General", 2, 2, TraceEventType.Information);
                    }         */
                }/*
                else
                {
                    if (!Logger.IsLoggingEnabled())
                    {
                        Logger.Write("There are no emails in the database", "Important", 1, 1, TraceEventType.Warning);
                    }
                }*/

                return emails;
            }
        }
コード例 #23
0
        public IList<DomainModel.Exam> GetAllExams()
        {
            using (var context = new SchoolContext())
            {
                var exams = (from exam in context.Exams
                                 select exam).ToList();

                if (exams.Count != 0)
                {
                    /*
                    Logger.Write("There were successfully returned: " + exams.Count + " exams!", "General", 2, 2, TraceEventType.Information);
                     * */
                }/*
                else
                {
                    Logger.Write("There are no exams in the database", "Important", 1, 1, TraceEventType.Warning);
                }*/

                return exams;
            }
        }
コード例 #24
0
        public bool IsAddressInserted(int addressId)
        {
            Contract.Requires<ArgumentOutOfRangeException>(addressId > 0 , "Please provide address > 0 or else!");
            using (var context = new SchoolContext())
            {
                var res = context.Addresses.SingleOrDefault(s => s.StudentId == addressId);

                if (res != null)
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The student exists: " + res, "General", 2, 2, TraceEventType.Information);
                    }
                    */
                    return true;
                }
                /*
                if (Logger.IsLoggingEnabled())
                {
                    Logger.Write("The student with id: " + addressId + " doesn't exist!", "Important", 1, 1, TraceEventType.Error);
                }
                */
                return false;
            }
        }
コード例 #25
0
        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;
            }
        }
コード例 #26
0
        public Address GetAddressById(int addressId)
        {
            using (var context = new SchoolContext())
            {
                var res = context.Addresses.Where(s => s.StudentId == addressId).Include("Student").SingleOrDefault();

                if (res != null)
                {/*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The user was returned by id " + res, "General", 2, 2, TraceEventType.Information);
                    }*/
                }/*
                else
                {
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The user with id=" + addressId + " does not exist!", "Important", 1, 1,
                          TraceEventType.Error);
                    }
                }*/
                return res;
            }
        }
コード例 #27
0
        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;
            }
        }
コード例 #28
0
        public bool IsEmailInserted(int emailId)
        {
            using (var context = new SchoolContext())
            {
                var res = context.Emails.SingleOrDefault(e => e.EmailId == emailId);

                if (res != null)
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The email exists: " + res, "General", 2, 2, TraceEventType.Information);
                    }*/

                    return true;
                }

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

                return false;
            }
        }
コード例 #29
0
        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");
                }

            }
        }
コード例 #30
0
        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;
            }
        }