/// <summary>
 /// Create a new tblTutor object.
 /// </summary>
 /// <param name="tutorId">Initial value of the TutorId property.</param>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="email">Initial value of the Email property.</param>
 /// <param name="password">Initial value of the Password property.</param>
 public static tblTutor CreatetblTutor(global::System.Int32 tutorId, global::System.String id, global::System.String name, global::System.String email, global::System.String password)
 {
     tblTutor tblTutor = new tblTutor();
     tblTutor.TutorId = tutorId;
     tblTutor.Id = id;
     tblTutor.Name = name;
     tblTutor.Email = email;
     tblTutor.Password = password;
     return tblTutor;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the tblTutors EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTotblTutors(tblTutor tblTutor)
 {
     base.AddObject("tblTutors", tblTutor);
 }
    protected void btnRegister_Click(object sender, EventArgs ev)
    {
        if (checkValidation())
        {
            using (ModelTutor obj = new ModelTutor())
            {

                string email = txtEmail.Text.Trim();

                var result = (from e in obj.tblTutors
                              where e.Email == email
                              select e).Count();

                if (result < 1)
                {
                    tblTutor newTutor = new tblTutor { Id = txtStudentId.Text.Trim(), Name = txtName.Text.Trim(), Email = txtEmail.Text.Trim(), Password = txtPassword.Text.Trim(), Active = true };
                    obj.AddTotblTutors(newTutor);

                    #region AddCourses

                    if (cbCourse1.SelectedValue != "0")
                    {

                        obj.AddTotblTutorCourses(new tblTutorCourse { TutorId = newTutor.TutorId, CourseId = Convert.ToInt32(cbCourse1.SelectedValue), Grade = txtGrade1.Text.Trim(), Active = false });
                    }
                    if (cbCourse2.SelectedValue != "0")
                    {

                        obj.AddTotblTutorCourses(new tblTutorCourse { TutorId = newTutor.TutorId, CourseId = Convert.ToInt32(cbCourse2.SelectedValue), Grade = txtGrade2.Text.Trim(), Active = false });
                    }
                    if (cbCourse3.SelectedValue != "0")
                    {

                        obj.AddTotblTutorCourses(new tblTutorCourse { TutorId = newTutor.TutorId, CourseId = Convert.ToInt32(cbCourse3.SelectedValue), Grade = txtGrade3.Text.Trim(), Active = false });
                    }
                    if (cbCourse4.SelectedValue != "0")
                    {

                        obj.AddTotblTutorCourses(new tblTutorCourse { TutorId = newTutor.TutorId, CourseId = Convert.ToInt32(cbCourse4.SelectedValue), Grade = txtGrade4.Text.Trim(), Active = false });
                    }

                    #endregion

                    #region Schedule

                    string mon = cbMonStart.SelectedValue + "to" + cbMonEnd.SelectedValue;
                    string tue = cbTueStart.SelectedValue + "to" + cbTueEnd.SelectedValue;
                    string wed = cbWedStart.SelectedValue + "to" + cbWedEnd.SelectedValue;
                    string thur = cbThurStart.SelectedValue + "to" + cbThurEnd.SelectedValue;
                    string fri = cbFriStart.SelectedValue + "to" + cbFriEnd.SelectedValue;

                    obj.AddTotblSchedules(new tblSchedule { TutorId = newTutor.TutorId, Mo = mon, Tu = tue, We = wed, Th = thur, Fr = fri });

                    #endregion

                    try
                    {
                        obj.SaveChanges();

                        Email m = new Email();

                        try
                        {
                            string body = "Hello " + txtName.Text.Trim() + ",\n" + "You are registered for Tutoring.";

                            m.sendEmail(email, body);
                        }
                        catch (Exception)
                        {

                        }

                        Response.Redirect("~/Sucess.aspx?m=Your account has been sucessfuly registered. Login to book tutor.");
                    }
                    catch (Exception)
                    {

                    }
                }
                else
                {
                    Label1.Text = "Email already exist";
                }

            }
        }
    }