Пример #1
0
        public void AddTest(TestInfo info, List <QuestionInfo> questions)
        {
            if (user == null)
            {
                throw userAccessException;
            }

            if (!TestValidator.IsValid(info) ||
                !TestTitleIsAvailable(info.Title) ||
                !TestValidator.IsValidQuestions(questions))
            {
                throw wrongDataException;
            }

            Test test = new Test(info)
            {
                AddDate = DateTime.Now,
                UserId  = user.Id
            };

            test = db.Tests.Add(test);
            db.SaveChanges();

            AddQuestions(test, questions);

            return;
        }
Пример #2
0
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckAllFields())
            {
                return;
            }

            TestInfo test = Test;


            if (!TestValidator.IsValid(test))
            {
                CtrlError.ShowError(TestValidator.Error);
                return;
            }

            if (TestId != null)
            {
                manager.Channel.EditTest(test, Questions);
            }
            else
            {
                manager.Channel.AddTest(test, Questions);
            }

            manager.MenuControl.Back();
        }
Пример #3
0
        public bool EditTest(TestInfo info, List <QuestionInfo> questions)
        {
            if (user == null)
            {
                throw userAccessException;
            }

            if (!TestValidator.IsValid(info) ||
                !TestTitleIsAvailable(info.Title, info.Id) ||
                !TestValidator.IsValidQuestions(questions))
            {
                throw wrongDataException;
            }

            Test test = db.Tests.FirstOrDefault(t => t.Id == info.Id);

            if (test == null)
            {
                return(false);
            }

            if (test.UserId != user.Id)
            {
                throw userAccessException;
            }

            RemoveQuestions(test);

            test.UserId         = user.Id;
            test.Title          = info.Title;
            test.Description    = info.Description;
            test.Duration       = info.Duration;
            test.Attempts       = info.Attempts;
            test.Interval       = info.Interval;
            test.AddDate        = DateTime.Now;
            test.CategoryId     = info.Category.Key;
            test.RatingSystemId = info.RatingSystem.Key;
            test.IsPrivate      = info.IsPrivate;
            test.IsQuestionsMix = info.IsQuestionsMix;

            db.SaveChanges();

            AddQuestions(test, questions);

            return(true);
        }