public void CreateTest(TestViewModel test)
        {
            TestType       TestTypes = context.TestTypes.FirstOrDefault(t => t.Name == test.TestType);
            TestTypeMapper TestType  = new TestTypeMapper();
            Test           Tests     = new Test();

            Tests.Date = test.Date;
            context.Tests.Add(Tests);

            TestType.TestID     = Tests.ID;
            TestType.TestTypeID = TestTypes.ID;
            context.TestTypeMappers.Add(TestType);
        }
예제 #2
0
        public void ShouldResolvePropertySetByBaseResolver()
        {
            var destType    = typeof(ClassW4Properties);
            var testBuilder = new TestTypeBuilder <ClassW2Properties, ClassW4Properties>();

            testBuilder.PropertyToResolve = destType.GetProperty("Prop3");
            testBuilder.ProertyValue      = 3;

            var mapper = new TestTypeMapper <ClassW2Properties, ClassW4Properties>(() => testBuilder);
            var source = new ClassW2Properties();
            var dest   = mapper.Map(source);

            Assert.IsNotNull(dest);
            Assert.AreEqual(3, dest.Prop3);
        }
예제 #3
0
        public void ShouldUserPriorBuilder()
        {
            var destType    = typeof(ClassW4Properties);
            var testBuilder = new TestTypeBuilder <ClassW2Properties, ClassW4Properties>();

            testBuilder.PropertyToResolve = destType.GetProperty("Prop2");
            testBuilder.ProertyValue      = 3;

            var mapper = new TestTypeMapper <ClassW2Properties, ClassW4Properties>(() => testBuilder);
            var source = new ClassW2Properties {
                Prop2 = 2
            };
            var dest = mapper.Map(source);

            Assert.IsNotNull(dest);
            Assert.AreEqual(2, dest.Prop2);
        }
예제 #4
0
        public async Task <IActionResult> CreateTestAsync([FromForm] TestViewModel test)
        {
            TestType TestTypes = await _context.TestTypes.FirstOrDefaultAsync(t => t.Name == test.TestType);

            TestTypeMapper TestType = new TestTypeMapper();
            Test           Tests    = new Test();

            if (ModelState.IsValid)
            {
                Tests.Date = test.Date;
                _context.Tests.Add(Tests);
                TestType.TestID     = Tests.ID;
                TestType.TestTypeID = TestTypes.ID;
                _context.TestTypeMappers.Add(TestType);
                await _context.SaveChangesAsync();
            }
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> CreateTestAsync([FromBody] TestViewModel test)
        {
            TestType TestTypes = await context.TestTypes.FirstOrDefaultAsync(t => t.Name == test.TestType);

            TestTypeMapper TestType = new TestTypeMapper();
            Test           Tests    = new Test();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Tests.Date = test.Date;
            context.Tests.Add(Tests);
            TestType.TestID     = Tests.ID;
            TestType.TestTypeID = TestTypes.ID;
            context.TestTypeMappers.Add(TestType);
            await context.SaveChangesAsync();

            return(Ok(test));
        }
예제 #6
0
        public async Task <IActionResult> CreateTestAsync([FromBody] CreateTestViewModel model)
        {
            TestType testType = await context.TestTypes.FirstOrDefaultAsync(t => t.Name == model.TestType);

            TestTypeMapper testTypeMapper = new TestTypeMapper();
            Test           test           = new Test();

            if (ModelState.IsValid)
            {
                test.Date = model.Date;
                context.Tests.Add(test);

                testTypeMapper.TestID     = test.ID;
                testTypeMapper.TestTypeID = testType.ID;
                context.TestTypeMappers.Add(testTypeMapper);

                await context.SaveChangesAsync();

                return(Ok(model));
            }
            return(BadRequest(ModelState));
        }
예제 #7
0
 // GET: api/TestTypes
 /// <summary>
 /// Controller Constructor
 /// </summary>
 /// <param name="bll"></param>
 public TestTypesController(IAppBLL bll)
 {
     _bll    = bll;
     _mapper = new TestTypeMapper();
 }