public IHttpActionResult Student(int id, Student student)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != student.StudentId)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 2
0
        public void deleteById(int id)
        {
            var course = _dbcontext.Courses.Where(i => i.CourseID == id).FirstOrDefault();

            if (course != null)
            {
                _dbcontext.Courses.Remove(course);
                _dbcontext.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public void deleteById(int id)
        {
            var student = _dbcontext.Students.Where(i => i.ID == id).First();

            if (student != null)
            {
                _dbcontext.Students.Remove(student);
                _dbcontext.SaveChanges();
            }
        }
Exemplo n.º 4
0
 public HttpResponseMessage Post(Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Employees.Add(employee);
         db.SaveChanges();
         var message = Request.CreateResponse(HttpStatusCode.Created, employee);
         message.Headers.Location = new Uri(Request.RequestUri + "/" + employee.Id.ToString());
         return(message);
     }
     else
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest));
     }
 }
Exemplo n.º 5
0
        public void deleteById(int id)
        {
            var enrollment = _dbcontext.Enrollments.Where(i => i.EnrollmentID == id).FirstOrDefault();

            if (enrollment != null)
            {
                _dbcontext.Enrollments.Remove(enrollment);
                _dbcontext.SaveChanges();
            }
        }