public async Task AddInstructor_PersistsInstructor() { var instructor = new Instructor { FirstName = "John", LastName = "Doe" }; using (var context = new ApplicationDbContext(Options)) { var service = new InstructorService(context); Instructor addedInstructor = await service.AddInstructor(instructor); Assert.AreEqual(addedInstructor, instructor); Assert.AreNotEqual(0, addedInstructor.Id); } using (var context = new ApplicationDbContext(Options)) { Instructor retrievedInstructor = context.Instructors.Single(); Assert.AreEqual(instructor.FirstName, retrievedInstructor.FirstName); Assert.AreEqual(instructor.LastName, retrievedInstructor.LastName); } }
protected void btnSave_Click(object sender, EventArgs e) { var instructorID = Request.QueryString["ID"]; if (Page.IsValid && instructorID == null) { Contoso.Models.Instructor instructor = new Models.Instructor(); instructor.ID = Convert.ToInt32(ddlID.SelectedValue); instructor.HireDate = Convert.ToDateTime(txtHireDate.Text); InstructorService instructorService = new InstructorService(); instructorService.AddInstructor(instructor); } if (Page.IsValid && instructorID != null) { Contoso.Models.Instructor instructor = new Models.Instructor(); instructor.ID = Convert.ToInt32(ddlID.SelectedValue); instructor.HireDate = Convert.ToDateTime(txtHireDate.Text); InstructorService instructorService = new InstructorService(); instructorService.UpdateInstructor(instructor); } }
public async Task <ActionResult> AddInstructor([FromBody] Instructor instructor) { await _instructorService.AddInstructor(instructor); return(Ok()); }