public IHttpActionResult PostCurrency(CurrencyViewModel newCurrency) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Currency currency = Mapper.Map<CurrencyViewModel, Currency>(newCurrency); db.Currencies.Add(currency); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = currency.Id }, new { data = currency }); }
public IHttpActionResult PutCurrency(int id, CurrencyViewModel newCurrency) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != newCurrency.Id) { return BadRequest(); } Currency currency = Mapper.Map<CurrencyViewModel, Currency>(newCurrency); db.Entry(currency).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CurrencyExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }