예제 #1
0
파일: Student.cs 프로젝트: zdietzen/Quack
 public void Update(StudentModel student)
 {
     FirstName = student.FirstName;
     LastName = student.LastName;
     Email = student.Email;
     Approved = student.Approved;
 }
예제 #2
0
        public IHttpActionResult PostStudent(StudentModel student)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            var dbStudent = new Student();

            dbStudent.Update(student);
            db.Students.Add(dbStudent);
            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                throw new Exception("Unable to add the student to the database.");
            }
            student.StudentId = dbStudent.StudentId;

            return CreatedAtRoute("DefaultApi", new { id = student.StudentId }, student);
        }
예제 #3
0
        public IHttpActionResult PutStudent(int id, StudentModel student)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != student.StudentId)
            {
                return BadRequest();
            }
            var dbStudent = db.Students.Find(id);

            dbStudent.Update(student);

            db.Entry(student).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw new Exception("Unable to update student in the database.");
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }