Example #1
0
        public IHttpActionResult PutProfessor(int id, Professor professor)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != professor.ProfessorID)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Example #2
0
        public IHttpActionResult PostProfessor(Professor professor)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Professors.Add(professor);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = professor.ProfessorID }, professor);
        }
Example #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);
 }