Пример #1
0
 public static int AddNewParent(Parent newParent)
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         if (!Util.IsValidEmail(newParent.user.Email))
             throw new ArgumentException("Email string is not a valid email!");
         context.Parents.Add(newParent);
         context.SaveChanges();
         return newParent.ParentID;
     }
 }
Пример #2
0
        private void btnAddNewParent_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtLastName.Text.Length == 0 || txtFirstName.Text.Length == 0 || txtPatronymic.Text.Length == 0)
                    throw new ArgumentException("FIO fields can't be null!");
                if (txtEmail.Text.Length == 0)
                    throw new ArgumentException("Email is required!");
                if (txtPassword.Text.Length == 0)
                    throw new ArgumentException("Password is required!");
                if (!Util.IsValidEmail(txtEmail.Text))
                    throw new ArgumentException("Email is not valid!");
                User basicUserInfo = new User
                {
                    LastName = txtLastName.Text,
                    FirstName = txtFirstName.Text,
                    Patronymic = txtPatronymic.Text,
                    DateOfBirth = dateTimePickerBirth.Value.Year == 9998 ? null : new DateTime?(dateTimePickerBirth.Value),
                    Email = txtEmail.Text,
                    Password = txtPassword.Text,
                    Phone = txtPhone.Text
                };

                Parent p = new Parent
                {
                    user = basicUserInfo,
                    Job = txtJob.Text
                };

                ParentDAL.AddNewParent(p);
                StudentDAL.AddParent(this.StudentID, p.ParentID);
                MessageBox.Show("Parent successfully added!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
 public ParentInfo(Parent p)
     : base(p.user)
 {
     Job = p.Job;
 }