コード例 #1
0
        public async Task <IActionResult> SaveTest([FromBody] TestTransferModel test)
        {
            // using ( var transaction = new TransactionScope( TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted } ) )
            // {
            //     try
            //     {
            //         logger.LogWarning($"{test == null}");
            //         logger.LogWarning($"TestName: {test.Name}, TestCode: {test.Code} , TestDescription: {test.Description}");
            //         var testModel = await tests.CreateTestAsync(test.Name, test.Code, test.Description);
            //         logger.LogWarning($"TestId: {testModel.Id}");
            //         await tests.AssignTestMatricesAsync(testModel, test.Matrices);
            //         logger.LogWarning($"Test Matrices Assigned");
            //         await tests.AssignTestMethodsAsync(testModel, Mapper.Map<List<TestParameterMethodBaseModel>, List<TestParameterMethodModel>>(test.Methods));
            //         logger.LogWarning($"Test Methods Assigned");

            //         transaction.Complete();

            //         return Json( (TestParameterBaseModel) testModel );
            //     }
            //     catch(Exception ex) { throw ex; }
            // }

            var transaction = await Db.Database.BeginTransactionAsync();

            try
            {
                logger.LogWarning($"{test == null}");
                logger.LogWarning($"TestName: {test.Name}, TestCode: {test.Code} , TestDescription: {test.Description}");
                var testModel = await tests.CreateTestAsync(test.Name, test.Code, test.Description);

                logger.LogWarning($"TestId: {testModel.Id}");
                await tests.AssignTestMatricesAsync(testModel, test.Matrices);

                logger.LogWarning($"Test Matrices Assigned");
                await tests.AssignTestMethodsAsync(testModel, Mapper.Map <List <TestParameterMethodBaseModel>, List <TestParameterMethodModel> >(test.Methods));

                logger.LogWarning($"Test Methods Assigned");

                transaction.Commit();

                return(Json((TestParameterBaseModel)testModel));
            }
            catch (Exception ex) { transaction.Rollback(); throw ex; }
        }
コード例 #2
0
ファイル: TestService.cs プロジェクト: HIMSys/HIMS
        public void SaveTest(TestTransferModel testDTO)
        {
            // Validation
            if (testDTO.Name.Length > 25)
            {
                throw new ValidationException($"The length of {nameof(testDTO.Name)} must be less then 25"
                                              , nameof(testDTO.Name));
            }
            if (testDTO.Description.Length > 255)
            {
                throw new ValidationException($"The length of {nameof(testDTO.Description)} must be less then 25"
                                              , nameof(testDTO.Description));
            }

            var test = new Test
            {
                Name        = testDTO.Name,
                Description = testDTO.Description
            };

            Database.Tests.Create(test);
            Database.Save();
        }
コード例 #3
0
ファイル: TestController.cs プロジェクト: HIMSys/HIMS
 public IHttpActionResult AddTest(TestTransferModel test)
 {
     _testService.SaveTest(test);
     return(Ok());
 }