예제 #1
0
        public async Task UpdateInstructor_UpdatesExistingInstructor()
        {
            var instructor = new Instructor
            {
                FirstName = "John",
                LastName  = "Doe"
            };

            using (var context = new ApplicationDbContext(Options))
            {
                context.Instructors.Add(instructor);
                context.SaveChanges();
            }

            instructor.FirstName = "Jane";
            instructor.LastName  = "Other";
            using (var context = new ApplicationDbContext(Options))
            {
                var        service           = new InstructorService(context);
                Instructor updatedInstructor = await service.UpdateInstructor(instructor);

                Assert.AreEqual(instructor, updatedInstructor);
            }

            using (var context = new ApplicationDbContext(Options))
            {
                Instructor retrievedInstructor = context.Instructors.Single();
                Assert.AreEqual(instructor.Id, retrievedInstructor.Id);
                Assert.AreEqual(instructor.FirstName, retrievedInstructor.FirstName);
                Assert.AreEqual(instructor.LastName, retrievedInstructor.LastName);
            }
        }
        public IHttpActionResult UpdateInstructor([FromBody] InstructorEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var svc = new InstructorService();

            if (!svc.UpdateInstructor(model))
            {
                return(InternalServerError());
            }

            return(Ok("Instructor successfully updated."));
        }
예제 #3
0
        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> UpdateInstructor([FromBody] Instructor instructor)
        {
            await _instructorService.UpdateInstructor(instructor);

            return(Ok());
        }