public void SaveTest(UserTestsDTO test) { var testModel = mapper.MapTo <UserTests>(test); testModel.CreatedOn = dateTime.GetDateTimeNow(); userTests.Add(testModel); saver.SaveChanges(); }
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(); }
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(); }
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(); }
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."); } }
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(); }
public int RemoveCollection(string collectionId) { if (collectionId.IsNullOrWhitespace()) { throw new InvalidCollectionIdException(); } var collectionToDelete = GetCollectionById(collectionId); collections.Delete(collectionToDelete); return(saver.SaveChanges()); }