Пример #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));
        }