public IHttpActionResult Update([FromBody] SwitchUpdateModel switchToUpdate) { if (ModelState.IsValid) { _switchService = new SwitchService(); _switchService.UpdateSwitchGame(switchToUpdate); return(Ok()); } return(BadRequest("Cannot find game to update, please try again.")); }
public void UpdateSwitchGame(SwitchUpdateModel switchToUpdate) { using (var ctx = new ApplicationDbContext()) { SwitchGame switchWeWantToUpdate = ctx.SwitchGames.Find(switchToUpdate.Name); if (switchToUpdate != null) { switchWeWantToUpdate.Name = switchToUpdate.Name; switchWeWantToUpdate.Price = switchToUpdate.Price; switchWeWantToUpdate.Rating = switchToUpdate.Rating; ctx.SaveChanges(); } } }