示例#1
0
        public IHttpActionResult PostStudentDB(StudentDB studentDB)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.StudentDB.Add(studentDB);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (StudentDBExists(studentDB.Student_ID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = studentDB.Student_ID }, studentDB));
        }
示例#2
0
        public IHttpActionResult PutStudentDB(int id, StudentDB studentDB)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != studentDB.Student_ID)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentDBExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#3
0
        public IHttpActionResult GetStudentDB(int id)
        {
            StudentDB studentDB = db.StudentDB.Find(id);

            if (studentDB == null)
            {
                return(NotFound());
            }

            return(Ok(studentDB));
        }
示例#4
0
        public IHttpActionResult DeleteStudentDB(int id)
        {
            StudentDB studentDB = db.StudentDB.Find(id);

            if (studentDB == null)
            {
                return(NotFound());
            }

            db.StudentDB.Remove(studentDB);
            db.SaveChanges();

            return(Ok(studentDB));
        }