예제 #1
0
        public ActionResult <Result <bool> > CreateTest([FromBody] SynthesisCreateRQ body)
        {
            if (string.IsNullOrEmpty(body.Name))
            {
                return(Result <bool> .Fail("Name cannot be empty."));
            }

            if (body.TaskId <= 0)
            {
                return(Result <bool> .Fail("A task must be selected."));
            }

            var testExists = _synthesisRepo.TestExists(body.Name);

            if (testExists)
            {
                return(Result <bool> .Fail($"Test '{body.Name}' already exists."));
            }

            var success = _synthesisRepo.Create(body, UserId);

            if (success)
            {
                return(Result <bool> .Success(true));
            }
            else
            {
                return(Result <bool> .Fail("Failed to save changes."));
            }
        }
예제 #2
0
        public bool Create(SynthesisCreateRQ request, Guid userId)
        {
            var synthesisTestEntity = new SynthesisTestEntity() //AutoMapper
            {
                Name        = request.Name,
                Status      = TestStatus.Scheduled,
                TaskId      = request.TaskId,
                DateCreated = DateTime.UtcNow,
                CreatedBy   = userId,
            };

            _context.SynthesisTests.Add(synthesisTestEntity);
            return(_context.SaveChanges() == 1);
        }