Beispiel #1
0
        public void UpdateStudent(StudentDetails studentDetails)
        {
            StudentContext studentContext = this.studentContext;

            Student student = studentContext.Students.Where(stu => stu.Id == studentDetails.Id).Single();

            student.FirstName = studentDetails.FirstName;
            student.LastName  = studentDetails.LastName;

            studentContext.SaveChanges();

            List <StudentEmail> studentEmailList = studentContext.StudentEmails.Where(stuEmail => stuEmail.StudentId == studentDetails.Id).ToList();

            foreach (string strStudentEmail in studentDetails.studentEmails)
            {
                if (!(string.IsNullOrEmpty(strStudentEmail)))
                {
                    int          stuEmailId   = studentEmailList.First().Id;
                    StudentEmail studentEmail = studentContext.StudentEmails.Where(stuEmail => stuEmail.Id == stuEmailId).Single();
                    studentEmail.Email = strStudentEmail;

                    studentEmailList.Remove(studentEmailList.First());
                }
            }

            if (studentEmailList.Count != 0)
            {
                foreach (StudentEmail studentEmail in studentEmailList)
                {
                    studentContext.StudentEmails.Remove(studentEmail);
                }
            }

            studentContext.SaveChanges();
        }
Beispiel #2
0
        public void AddStudentEmail(StudentDetails studentDetails)
        {
            StudentContext studentContext = this.studentContext;

            StudentEmail studentEmail = studentContext.StudentEmails.Create();

            studentEmail.StudentId = studentDetails.Id;
            studentEmail.Email     = studentDetails.studentEmails.Last();
            studentContext.StudentEmails.Add(studentEmail);
            studentContext.SaveChanges();
        }