public DestinationDTO(Destination pDestination) { this.DestinationID = pDestination.DestinationID; this.Type = pDestination.Type; this.Name = pDestination.Name; this.Address = pDestination.Address; this.DayID = pDestination.Day.DayID; }
public IHttpActionResult PutDestination(int id, Destination destination) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != destination.DestinationID) { return BadRequest(); } db.Entry(destination).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DestinationExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
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); }