Ejemplo n.º 1
0
 public CourseDTO(Course pCourse)
 {
     this.Id = pCourse.CourseID;
     this.TransportName = pCourse.Transport.TransportName;
     this.TransportCompanyName = pCourse.TransportCompanyName;
     this.StartDate = pCourse.StartDate;
     this.EndDate = pCourse.EndDate;
     this.DestinationAddress = pCourse.DestinationAddress;
     this.DepartureAddress = pCourse.DepartureAddress;
 }
Ejemplo n.º 2
0
        public IHttpActionResult PutCourse(int id, CourseDTO courseDTO)
        {
            Course course = new Course();
            course.CourseID = courseDTO.Id;
            course.DepartureAddress = courseDTO.DepartureAddress;
            course.DestinationAddress = courseDTO.DestinationAddress;
            course.StartDate = courseDTO.StartDate;
            course.EndDate = courseDTO.EndDate;
            course.TransportCompanyName = courseDTO.TransportCompanyName;
            Transport transport = (Transport)db.Transports.Where(t => t.TransportName == courseDTO.TransportName).First();
            course.Travel = (Travel)db.Travels.Where(t => t.TravelId == courseDTO.TravelID).First();

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != course.CourseID)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Ejemplo n.º 3
0
        public IHttpActionResult PostCourse(CourseDTO courseDTO)
        {
            Course course = new Course();
            course.CourseID = courseDTO.Id;
            course.DepartureAddress = courseDTO.DepartureAddress;
            course.DestinationAddress = courseDTO.DestinationAddress;
            course.StartDate = courseDTO.StartDate;
            course.EndDate = courseDTO.EndDate;
            course.TransportCompanyName = courseDTO.TransportCompanyName;
            Transport transport = (Transport)db.Transports.Where(t => t.TransportName == courseDTO.TransportName).First();
            course.Transport = transport;
            course.Travel = (Travel)db.Travels.Where(t => t.TravelId == courseDTO.TravelID).First();

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Courses.Add(course);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = course.CourseID }, course);
        }