Example #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; }
        }