コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }