コード例 #1
0
        public void SaveTest(UserTestsDTO test)
        {
            var testModel = mapper.MapTo <UserTests>(test);

            testModel.CreatedOn = dateTime.GetDateTimeNow();
            userTests.Add(testModel);
            saver.SaveChanges();
        }
コード例 #2
0
        public void SaveTest(UserTestsDTO test)
        {
            if (test == null)
            {
                throw new ArgumentNullException(nameof(test));
            }

            var testModel = mapper.MapTo <UserTests>(test);

            testModel.CreatedOn = dateTime.GetDateTimeNow();
            userTests.Add(testModel);
            saver.SaveChanges();
        }
コード例 #3
0
        public void Submit(UserTestDto dto)
        {
            Guard.WhenArgument(dto, "UserTestDto us null").IsNull().Throw();

            var testToUpdate = userTests.All
                               .Where(ut => ut.UserId == dto.UserId && ut.TestId == dto.TestId)
                               .FirstOrDefault() ?? throw new ArgumentNullException("UserTest Entity can not be null.");

            testToUpdate.IsPassed      = dto.IsPassed;
            testToUpdate.Points        = dto.Points;
            testToUpdate.ExecutionTime = dto.ExecutionTime;
            testToUpdate.SubmittedOn   = dto.SubmittedOn;

            userTests.Update(testToUpdate);
            saver.SaveChanges();
        }
コード例 #4
0
        public void SaveQuestionAnswers(UserTestsDTO test)
        {
            if (test == null)
            {
                throw new ArgumentNullException(nameof(test));
            }

            foreach (var qa in test.Questions)
            {
                var utaToAdd = new UserTestAnswers
                {
                    UserTestId = test.UserTestId,
                    AnswerId   = qa.SelectedAnswerId
                };

                userTestAnswers.Add(utaToAdd);
            }
            saver.SaveChanges();
        }
コード例 #5
0
ファイル: TestsService.cs プロジェクト: borschetsky/ITest-App
        public void Delete(int id)
        {
            if (id < 0)
            {
                throw new ArgumentOutOfRangeException("Invalid id provided");
            }

            var testToDelete = tests.All.Include(q => q.Questions).ThenInclude(a => a.Answers)
                               .FirstOrDefault(t => t.Id == id) ?? throw new TestNotFoundException($"No test with id {id} found!");

            var testsUser = userTests.All;

            if (testToDelete != null && !(testsUser.Any(ut => ut.TestId == testToDelete.Id)))
            {
                tests.Delete(testToDelete);

                foreach (var question in testToDelete.Questions)
                {
                    this.questions.Delete(question);
                    foreach (var answer in question.Answers)
                    {
                        this.answers.Delete(answer);
                    }
                }

                saver.SaveChanges();
            }
            else
            {
                throw new InvalidTestException("Cannot delete test it has been taked by users.");
            }
        }
コード例 #6
0
 public void SaveQuestionAnswers(UserTestsDTO test)
 {
     foreach (var qa in test.Questions)
     {
         var utaToAdd = new UserTestAnswers
         {
             UserTestId = test.UserTestId,
             AnswerId   = qa.SelectedAnswerId
         };
         userTestAnswers.Add(utaToAdd);
     }
     saver.SaveChanges();
 }
コード例 #7
0
        public int RemoveCollection(string collectionId)
        {
            if (collectionId.IsNullOrWhitespace())
            {
                throw new InvalidCollectionIdException();
            }

            var collectionToDelete = GetCollectionById(collectionId);

            collections.Delete(collectionToDelete);

            return(saver.SaveChanges());
        }