Beispiel #1
0
        public int AddTeacher(string Teacher)
        {
            TeacherJson teacher = JsonConvert.DeserializeObject <TeacherJson>(Teacher);

            db.Faculties.ToArray();
            db.Departments.ToArray();
            db.Groups.ToArray();
            var     d    = db.Departments.Where(p => p.Name == teacher.Department).ToArray();
            Teacher NewT = new Teacher
            {
                Login        = teacher.Login,
                Password     = teacher.Password,
                Surname      = teacher.Surname,
                Name         = teacher.Name,
                Patronymic   = teacher.Patronymic,
                Department   = d[0],
                DepartmentId = d[0].Id
            };

            if (db.Teachers.FirstOrDefault(p => p.Login == NewT.Login) == null)
            {
                db.Teachers.Add(NewT);
                d[0].Teachers.Add(NewT);
                db.SaveChanges();
                return(1);
            }
            else
            {
                return(-1);
            }
        }
Beispiel #2
0
        private async void RegBTN_Click(object sender, EventArgs e)
        {
            if (PasswordTB.Text != CPasswordTB.Text)
            {
                MessageBox.Show("Не совпадают введенные пароли!", "Ошибка регистрации.");
                return;
            }

            if ((LoginTB.Text == "") || (PasswordTB.Text == "") || (CPasswordTB.Text == "") || (SurnameTB.Text == "") || (NameTB.Text == "") || (PatronymicTB.Text == ""))
            {
                MessageBox.Show("Все поля должны быть заполнены.", "Ошибка регистрации.");
                return;
            }
            TeacherJson Teacher = new TeacherJson();

            Teacher.Login      = LoginTB.Text;
            Teacher.Password   = PasswordTB.Text;
            Teacher.Surname    = SurnameTB.Text;
            Teacher.Name       = NameTB.Text;
            Teacher.Patronymic = PatronymicTB.Text;
            Teacher.Department = DepartmentCB.SelectedItem.ToString();
            string s      = JsonConvert.SerializeObject(Teacher);
            string answer = null;

            try
            {
                answer = await Server.GetResponseAsync("http://localhost:57755/Account/AddTeacher?Teacher=" + s);
            }
            catch (System.Net.WebException)
            {
                MessageBox.Show("Удаленный сервер не отвечает. Регистрация временно невозможна.", "Ошибка регистрации.");
            }

            if (Convert.ToInt32(answer) == -1)
            {
                MessageBox.Show("Пользователь с таким логином уже существует.", "Ошибка регистрации.");
                return;
            }
            else
            {
                ClearFields();
                MessageBox.Show("     Поздравляем! Регистрация прошла успешно!     ", "Регистрация.");
            }
        }