public IHttpActionResult PutModel(int id, ModelDTO model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != model.ModelId) { return BadRequest(); } Model updateModel = new Model(); updateModel.ModelId = model.ModelId; updateModel.Name = model.ModelName; updateModel.ManufacturerCode = model.ManufacturerCode; updateModel.CategoryId = Int32.Parse(model.CategoryId); updateModel.Description = model.Description; updateModel.StatusId = Int32.Parse(model.StatusId); updateModel.ManufacturerId = Int32.Parse(model.ManufacturerId); updateModel.ListPrice = model.ListPrice; db.Models.Attach(updateModel); db.Entry(updateModel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ModelExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostModel(ModelDTO model) { Model updateModel = new Model(); updateModel.Name = model.ModelName; updateModel.ManufacturerCode = model.ManufacturerCode; updateModel.CategoryId = Int32.Parse(model.CategoryId); updateModel.Description = model.Description; updateModel.StatusId = Int32.Parse(model.StatusId); updateModel.ManufacturerId = Int32.Parse(model.ManufacturerId); updateModel.ListPrice = model.ListPrice; db.Models.Add(updateModel); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = updateModel.ModelId }, updateModel); }