public async Task <IActionResult> Update(long id, [FromBody] Tap item) { if (item == null || id == 0) { return(BadRequest()); } var tap = _context.Tap.FirstOrDefault(t => t.id == id); if (tap == null) { return(NotFound()); } if (item.beer.id != item.beerId) { item.beer = _context.Beer .Where(b => b.id == item.beerId) .Include(b => b.style) .Include(b => b.label) .FirstOrDefault(); } foreach (PropertyInfo prop in item.GetType().GetProperties()) { if (prop.Name != "id" && prop.Name != "beer") { prop.SetValue(tap, prop.GetValue(item)); } } _context.Tap.Update(tap); _context.SaveChanges(); ReorderTapsOnAddEdit(tap); _context.SaveChanges(); await _menuHubContext.Clients.All.SendAsync("TapUpdated", item); return(Ok(new { message = "Tap is updated successfully." })); }