public IHttpActionResult GetDestination(int id) { Destination destination = db.Destinations.Find(id); if (destination == null) { return NotFound(); } //found DestinationDTO destDTO = new DestinationDTO(destination); return Ok(destDTO); }
public IHttpActionResult PostDestination(DestinationDTO destinationDTO) { Destination newDestination = new Destination(); newDestination.Address = destinationDTO.Address; newDestination.Name = destinationDTO.Name; newDestination.Type = destinationDTO.Type; Day associatedDay = db.Days.Where(d => d.DayID == destinationDTO.DayID).First(); newDestination.Day = associatedDay; if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Destinations.Add(newDestination); db.SaveChanges(); destinationDTO.DestinationID = newDestination.DestinationID; return CreatedAtRoute("DefaultApi", new { id = newDestination.DestinationID }, destinationDTO); }