public ActionResult <Result <bool> > CreateTest([FromBody] AnalysisCreateRQ body) { if (string.IsNullOrEmpty(body.Name)) { return(Result <bool> .Fail("Name cannot be empty.")); } if (body.SynthesisTestId <= 0 || body.StudentId == Guid.Empty) { return(Result <bool> .Fail("A synthesis test must be selected.")); } var testExists = _analysisRepo.TestExists(body.Name); if (testExists) { return(Result <bool> .Fail($"Test '{body.Name}' already exists.")); } var success = _analysisRepo.Create(body, UserId); if (success) { return(Result <bool> .Success(true)); } else { return(Result <bool> .Fail("Failed to save changes.")); } throw new NotImplementedException(); }
public bool Create(AnalysisCreateRQ request, Guid userId) { var analysisTestEntity = new AnalysisTestEntity() //AutoMapper { Name = request.Name, STS_StudentId = request.StudentId, STS_SynthesisTestId = request.SynthesisTestId, Status = TestStatus.Scheduled, DateCreated = DateTime.UtcNow, CreatedBy = userId, }; _context.AnalysisTests.Add(analysisTestEntity); return(_context.SaveChanges() == 1); }