I've got an API where I can POST an object and update the matching record in the database. That endpoint looks like this:
// POST: api/Spell
public IHttpActionResult Post([FromBody]Spell spell)
{
using (SpellContext db = new SpellContext())
{
var recordToUpdate = db.Spells.Where(x => x.id == spell.id).FirstOrDefault();
if (recordToUpdate != null)
{
recordToUpdate = spell;
db.SaveChanges();
return Ok("Spell " + spell.id + " (" + spell.name + ") Updated Successfully!");
}
else
{
return InternalServerError();
}
}
}
So basically as long as a spell with the same ID as the incoming spell exists, we save changes.
When I call it, I'm returning Ok, but nothing is updating in the database.
How come?