public async Task LoadOrCreateTestsForAssignmentAsync(Assignment assignment, IEnumerable <string> testNames) { var assignmentTests = await _testRepository.FindByAssignmentId(assignment.Id); foreach (var testName in testNames) { if (assignmentTests.All(test => test.TestName != testName)) { var newTest = new Test { AssignmentId = assignment.Id, TestName = testName }; var savedTest = await _testRepository.AddAsync(newTest); assignmentTests.Add(savedTest); } } assignment.Tests = assignmentTests; }
public async Task <Result> Handle(CreateSiteCommand request, CancellationToken cancellationToken) { if (await _siteRepository.AnyAsync()) { return(Result <int> .Failure(0, "请不要重复创建")); } var site = new SiteInfo(request.Name, request.Domain); await _siteRepository.AddAsync(site); await _siteRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); // await _testRepository.AddAsync(new Domain.Test() { Name = "Testt" }); await _testRepository.AddAsync(new Domain.Test("Testt")); await _testRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); return(Result <int> .Success(site.Id, "创建成功")); }
public async Task CreateTest(CreateTestViewModel model) { Test test = new Test { TopicId = model.TopicId, CreatedTime = DateTime.Now, Questions = model.Questions.Select(q => new Question { Text = q.Text, CorrectAnswer = q.CorrectAnswer, Answers = q.Answers.Select(a => new Answer { AnswerLetter = a.AnswerLetter, Text = a.Text, }).ToList() }).ToList() }; await _testRepository.AddAsync(test); await _testRepository.CommitAsync(); }
public async Task <bool> CreateTestAsync(CreateTestDTO testModel) { if (string.IsNullOrEmpty(await _testRepository.GetTestNameAsync(testModel.TestName, testModel.ShortName))) { var test = _mapper.Map <Test>(testModel); var testCategory = await _categoryRepository.GetCategoryByNameAsync(testModel.CategoryName); if (testCategory != null) { test.Category = testCategory; await _testRepository.AddAsync(test); } else { return(false); } return(true); } else { return(false); } }