public IActionResult Add_View_People(PeopleViewModel objModel) { CreatePersonViewModel createPersonModelView = new CreatePersonViewModel(); if (objModel.AddPerson != null) { if (ModelState.IsValid) { createPersonModelView = objModel.AddPerson; peopleViewModel = null; ps.Add(createPersonModelView); } else { peopleViewModel.ModelErr = "Required fields are missing"; } } if (objModel.Search != null) { peopleViewModel = ps.FindBy(objModel); } //return View("Add_View_People", peopleViewModel); return(RedirectToAction(nameof(Add_View_People))); }
public IActionResult AddPeople(CreatePersonViewModel objModel) { CreatePersonViewModel createPersonModelView = new CreatePersonViewModel(); createPersonModelView = objModel; PeopleService ps = new PeopleService(); ps.Add(createPersonModelView); return(RedirectToAction(nameof(ViewPeople))); }
public async Task Should_return_the_student_that_was_persisted() { var suppliedContext = AsyncDatabaseContextMockingHelper.GetMockedStudentDatabaseContext(); IPeopleService service = new PeopleService(suppliedContext.Object); var suppliedStudent = new Person { FirstName = "John", LastName = "Doe" }; var actualModel = await service.Add(suppliedStudent); // Note: We could use reflection to ensure all properties are mapped. Assert.AreEqual(actualModel.FirstName, suppliedStudent.FirstName); Assert.AreEqual(actualModel.LastName, suppliedStudent.LastName); }
public async Task Add_IdZero_IdAssigned() { var connection = await GetOpenSqliteConnectionAsync(); try { var options = new DbContextOptionsBuilder <PeopleContext>() .UseSqlite(connection) .Options; using (var context = new PeopleContext(options)) { context.Database.OpenConnection(); context.Database.EnsureCreated(); var service = new PeopleService(context); service.Add(new Person { Id = 0, FirstName = "Andrew", LastName = "Skoraro", PhoneNumber = "(759) 548-2082" }); await service.SaveAsync(); var people = await service.ListAsync(); people.Should().NotBeNullOrEmpty(); people.Should().HaveCount(1); people.First().Id.Should().BeGreaterThan(0); } } finally { connection.Close(); } }
public async Task Add_NoFirstName_Failure() { var connection = await GetOpenSqliteConnectionAsync(); try { var options = new DbContextOptionsBuilder <PeopleContext>() .UseSqlite(connection) .Options; using (var context = new PeopleContext(options)) { context.Database.OpenConnection(); context.Database.EnsureCreated(); var service = new PeopleService(context); service.Add(new Person { Id = 0, LastName = "Smith", PhoneNumber = "(555) 555-5555" }); var people = await service.ListAsync(); Func <Task> func = () => service.SaveAsync(); func.Should().Throw <DbUpdateException>(); } } finally { connection.Close(); } }
public void Create([FromBody] People person) { _peopleService.Add(person); }