public async Task<IHttpActionResult> PutVoceListaSpesa(long id, VoceListaSpesa voceListaSpesa) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != voceListaSpesa.IdVoceListaSpesa) { return BadRequest(); } db.Entry(voceListaSpesa).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VoceListaSpesaExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostVoceListaSpesa(VoceListaSpesa voceListaSpesa) { if (!ModelState.IsValid) { return BadRequest(ModelState); } voceListaSpesa.Voce = await db.Voce.FindAsync(voceListaSpesa.Voce.IdVoce); voceListaSpesa.ListaSpesa = await db.ListaSpesa.FindAsync(voceListaSpesa.ListaSpesa.IdListaSpesa); db.VoceListaSpesa.Add(voceListaSpesa); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = voceListaSpesa.IdVoceListaSpesa }, voceListaSpesa); }