Exemplo n.º 1
0
 public PostController(PostContainer postcontainer, ReplyContainer replycontainer, ForumContainer forumcontainer, IPostUpdateContext update)
 {
     this.Container      = postcontainer;
     this.replyContainer = replycontainer;
     this.forumContainer = forumcontainer;
     this.postUpdate     = update;
 }
Exemplo n.º 2
0
        private void SaveChanges_Click(object sender, EventArgs e)
        {
            List <Control> controlsList = new List <Control>();

            controlsList.Add(new Control());
            controlsList.Add(new Control());


            foreach (Control ctrl in VisibleTheory.Controls)
            {
                if (ctrl is Scintilla)
                {
                    controlsList[0] = ctrl;
                }
                else if (ctrl is TextBox)
                {
                    controlsList[1] = ctrl;
                }
                else
                {
                    continue;
                }
            }

            if (UpdateState)
            {
                using (ForumContainer container = new ForumContainer())
                {
                    foreach (var control in controlsList)
                    {
                        if (control is Scintilla)
                        {
                            Scintilla sc = (Scintilla)control;

                            if (sc.Text.Length == 0)
                            {
                                MessageBox.Show("Вы добавили элемент \"Код\", но не ввели никаких данных.");
                                return;
                            }

                            byte[] result = Encoding.UTF8.GetBytes(sc.Text);
                            var    code   = container.CodeSet.First(x => x.CodeId == updateCodeId);

                            code.CodeFileName   = sc.Name + getIdObject();
                            code.BinaryFileData = result;
                            container.SaveChanges();

                            CodeId = code.CodeId;
                        }
                        else if (control is TextBox)
                        {
                            TextBox         tb        = (TextBox)control;
                            TheoryLessonSet lessonSet = new TheoryLessonSet()
                            {
                                CodeId     = CodeId == -1 ? 1011 : CodeId,
                                TheoryText = tb.Text
                            };

                            TheoryControl.TheoryLessonSet = lessonSet;
                            Close();
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
            else
            {
                using (ForumContainer container = new ForumContainer())
                {
                    foreach (var control in controlsList)
                    {
                        if (control is Scintilla)
                        {
                            Scintilla sc = (Scintilla)control;

                            if (sc.Text.Length == 0)
                            {
                                MessageBox.Show("Вы добавили элемент \"Код\", но не ввели никаких данных.");
                                return;
                            }

                            byte[] result = Encoding.UTF8.GetBytes(sc.Text);

                            CodeSet code = new CodeSet()
                            {
                                CodeFileName   = sc.Name + getIdObject(),
                                BinaryFileData = result
                            };

                            container.CodeSet.Add(code);
                            container.SaveChanges();
                            CodeId = code.CodeId;
                        }
                        else if (control is TextBox)
                        {
                            TextBox         tb        = (TextBox)control;
                            TheoryLessonSet lessonSet = new TheoryLessonSet()
                            {
                                CodeId     = CodeId == -1 ? 1011 : CodeId,
                                TheoryText = tb.Text
                            };

                            TheoryControl.TheoryLessonSet = lessonSet;
                            Close();
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void AddTrainingToDb_Click(object sender, EventArgs e)
        {
            SaveTraining saveTraining = new SaveTraining();

            saveTraining.ShowDialog();

            if (saveTraining.TrainingName == "")
            {
                return;
            }

            using (ForumContainer container = new ForumContainer())
            {
                TrainingSet training = new TrainingSet()
                {
                    AuthorId           = MainForm.Client.AccountId,
                    TrainingName       = saveTraining.TrainingName,
                    TrainingDescrition = saveTraining.TrainingDescription,
                    LanguageId         = Language.LanguageId
                };

                container.TrainingSet.Add(training);
                container.SaveChanges();

                foreach (var Lesson in TestTrainingPanel.Controls)
                {
                    var       CurrentLesson = (LessonControl)Lesson;
                    LessonSet lesson        = new LessonSet()
                    {
                        TrainingId = training.TrainingId,
                        Color      = ColorTranslator.ToOle(CurrentLesson.ControlColor),
                        Picture    = ImageToByteArray(CurrentLesson.Picture),
                        LessonName = CurrentLesson.LessName,
                        LessonText = "??",
                        Position   = CurrentLesson.Position,
                        Shape      = 0,
                    };
                    container.LessonSet.Add(lesson);
                    container.SaveChanges();

                    foreach (var theory in CurrentLesson.Theories)
                    {
                        TheoryLessonSet theoryLesson = new TheoryLessonSet()
                        {
                            LessonId   = lesson.LessonId,
                            Position   = theory.Position,
                            TheoryId   = theory.TheoryLessonSet.TheoryId,
                            TheoryText = theory.TheoryLessonSet.TheoryText,
                            CodeId     = theory.TheoryLessonSet.CodeId
                        };

                        container.TheoryLessonSet.Add(theoryLesson);
                        container.SaveChanges();
                    }

                    foreach (var quest in CurrentLesson.Questions)
                    {
                        QuestionListLessonSet questionListLesson = new QuestionListLessonSet()
                        {
                            LessonId   = lesson.LessonId,
                            Position   = quest.Position,
                            QuestionId = quest.QuestionSet.QuestionId
                        };

                        container.QuestionListLessonSet.Add(questionListLesson);
                        container.SaveChanges();
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void RegistrationButton_Click(object sender, EventArgs e)
        {
            if (Login.Text == string.Empty)
            {
                MessageBox.Show("Вы оставили поле Логин пустым");
                return;
            }

            if (EmailTextBox.Text == string.Empty)
            {
                MessageBox.Show("Вы оставили поле Почта пустым");
                return;
            }

            if (TelephoneNumber.Text == string.Empty)
            {
                MessageBox.Show("Вы оставили поле Телефон пустым");
                return;
            }

            if (Password.Text == string.Empty)
            {
                MessageBox.Show("Вы оставили поле Пароль пустым");
                return;
            }

            if (UserName.Text == string.Empty)
            {
                MessageBox.Show("Вы оставили поле Имя пустым");
                return;
            }

            using (ForumContainer container = new ForumContainer())
            {
                if (container.AccountSet.SingleOrDefault(x => x.Login == Login.Text) != null)
                {
                    MessageBox.Show("Данный логин уже занят. Выберите другой логин для входа на форум.");
                    return;
                }

                if (container.AccountSet.SingleOrDefault(x => x.Email == EmailTextBox.Text) != null)
                {
                    MessageBox.Show("Данный емайл уже занят. Выберите другой емайл.");
                    return;
                }

                if (container.AccountSet.SingleOrDefault(x => x.PhoneNumber == TelephoneNumber.Text) != null)
                {
                    MessageBox.Show("Данный телефонный номер уже занят. Выберите другой телефонный номер.");
                    return;
                }

                if (Password.Text.Equals(RePassword.Text))
                {
                    AccountSet newAccount = new AccountSet()
                    {
                        Login       = Login.Text,
                        PhoneNumber = TelephoneNumber.Text,
                        Email       = EmailTextBox.Text,
                        Password    = HashPassword(Password.Text),
                        Name        = UserName.Text,
                        UserName    = UserName.Text,
                        AccountType = 0,
                        CreateDate  = DateTime.Now,
                        Points      = 0,
                        Reputation  = 0
                    };

                    container.AccountSet.Add(newAccount);
                    container.SaveChanges();
                    MessageBox.Show("Аккаунт был успешно создан!");
                }
                else
                {
                    MessageBox.Show("Повторите попытку. Вы ввели не одинаковый пароль.");
                    return;
                }
            }
        }
Exemplo n.º 5
0
        public string RegistrationAccount(Dictionary <StringTypeRegistration, string> param_S)
        {
            string errorCode = "unknown";

            if (param_S[StringTypeRegistration.Login] == string.Empty)
            {
                errorCode = registrationErrorCodes[(int)StringTypeRegistration.Login];
                return(errorCode);
            }

            if (param_S[StringTypeRegistration.Email] == string.Empty)
            {
                errorCode = registrationErrorCodes[(int)StringTypeRegistration.Email];
                return(errorCode);
            }

            if (param_S[StringTypeRegistration.Telephone] == string.Empty)
            {
                errorCode = registrationErrorCodes[(int)StringTypeRegistration.Telephone];
                return(errorCode);
            }

            if (param_S[StringTypeRegistration.Password] == string.Empty)
            {
                errorCode = registrationErrorCodes[(int)StringTypeRegistration.Password];
                return(errorCode);
            }

            if (param_S[StringTypeRegistration.UserName] == string.Empty)
            {
                errorCode = registrationErrorCodes[(int)StringTypeRegistration.UserName];
                return(errorCode);
            }

            using (ForumContainer container = new ForumContainer())
            {
                string login = param_S[StringTypeRegistration.Login];
                if (container.AccountSet.SingleOrDefault(x => x.Login == login) != null)
                {
                    errorCode = registrationErrorCodes[5];
                    return(errorCode);
                }

                string email = param_S[StringTypeRegistration.Email];
                if (container.AccountSet.SingleOrDefault(x => x.Email == email) != null)
                {
                    errorCode = registrationErrorCodes[6];
                    return(errorCode);
                }

                string telephone = param_S[StringTypeRegistration.Telephone];
                if (container.AccountSet.SingleOrDefault(x => x.PhoneNumber == telephone) != null)
                {
                    errorCode = registrationErrorCodes[7];
                    return(errorCode);
                }

                // good
            }

            return("Аккаунт был успешно создан");
        }