public IHttpActionResult Create(AirCraftModel aircraft) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var newAircraft = new AirCraft { Model = aircraft.Model }; this.data.Aircrafts.Add(newAircraft); this.data.SaveChanges(); aircraft.Id = newAircraft.Id; //this.aircrafts.Save return Ok(aircraft); }
public IHttpActionResult Update(int id, AirCraftModel airCraft) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var existAirCraft = this.data.Aircrafts.All().FirstOrDefault(a => a.Id == id); if (existAirCraft == null) { return BadRequest("Such aircraft does not exist!"); } existAirCraft.Model = airCraft.Model; airCraft.Id = existAirCraft.Id; this.data.SaveChanges(); return Ok(airCraft); }