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); }
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); }
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); }
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)); }
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)); }
// GET: api/TestTypes /// <summary> /// Controller Constructor /// </summary> /// <param name="bll"></param> public TestTypesController(IAppBLL bll) { _bll = bll; _mapper = new TestTypeMapper(); }