示例#1
0
        public IHttpActionResult PutStudent(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);
        }
示例#2
0
        public IHttpActionResult PostStudent(Student student)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Students.Add(student);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = student.StudentID }, student);
        }
示例#3
0
 public HttpResponseMessage ImportInfo([FromBody()]string[] importContent)
 {
     string type = importContent[0];
     int lines = int.Parse(importContent[1]);
     int info = 2;
     if (type.Equals("Estudiantes"))
     {
         StudentsController sc = new StudentsController();
         for (int i = 0; i < lines; i++)
         {
             Student student = new Student(importContent[info], importContent[info+1], importContent[info+2], importContent[info+3], importContent[info+4], importContent[info+5]);
             IHttpActionResult ac = sc.PostStudent(student);
             info += 6;
         }
         return Request.CreateResponse(HttpStatusCode.OK);
     }
     if (type.Equals("Cursos"))
     {
         CoursesController cc = new CoursesController();
         for (int i = 0; i < lines; i++)
         {
             Course course = new Course(importContent[info]);
             IHttpActionResult ac = cc.PostCourse(course);
             info += 1;
         }
         return Request.CreateResponse(HttpStatusCode.OK);
     }
     if (type.Equals("Profesores"))
     {
         ProfessorsController sd = new ProfessorsController();
         for (int i = 0; i < lines; i++)
         {
             Professor professor = new Professor(importContent[info], importContent[info + 1], importContent[info + 2], importContent[info + 3]);
             IHttpActionResult ac = sd.PostProfessor(professor);
             info += 4;
         }
         return Request.CreateResponse(HttpStatusCode.OK);
     }
     if (type.Equals("Oferta académica"))
     {
         OfferAcademicsController sd = new OfferAcademicsController();
         for (int i = 0; i < lines; i++)
         {
             OfferAcademic offer = new OfferAcademic(importContent[info], importContent[info + 1], importContent[info + 2], importContent[info + 3], importContent[info + 4]);
             IHttpActionResult ac = sd.PostOfferAcademic(offer);
             info += 5;
         }
         return Request.CreateResponse(HttpStatusCode.OK);
     }
     return Request.CreateResponse(HttpStatusCode.NotFound);
 }