public async Task <IActionResult> PutTimesheet(int id, int versionId, TimesheetViewModel timesheetViewModel) { await _timesheetRepository.Update(new Timesheet(timesheetViewModel)); //delete existing rows and then add, dont update var tsRows = (await _timesheetRowRepository.GetAll()).Where(t => t.TimesheetId == id && t.TimesheetVersionNumber == versionId); foreach (TimesheetRow item in tsRows) { await _timesheetRowRepository.Delete(item); } foreach (TimesheetRowViewModel item in timesheetViewModel.TimesheetRows) { await _timesheetRowRepository.Add(new TimesheetRow(item)); } return(Ok(timesheetViewModel)); }