public async Task <Employee> SaveStatusAndAddTimelineEntry( Employee employee, EmployeeStatusEnum newStatus ) { var newStatusCode = newStatus.Code; var oldStatusCode = employee.CurrentEmployeeStatusCode; // Update employee status. employee.CurrentEmployeeStatusCode = newStatusCode; // Create a new timeline entry. employee.TimelineEntries.Add(new EmployeeTimelineEntry { EmployeeActionCode = EmployeeActionEnum.UpdateByTask.Code, EmployeeStatusCode = newStatusCode, Comment = $"Status updated by script: " + $"{oldStatusCode} → {newStatusCode}." }); context.Entry(employee).State = EntityState.Modified; // Update in CallWeb. await callWeb.UpdateSurvey(employee); // Save. await context.SaveChangesAsync(); return(employee); }
public async Task <ActionResult <AdminSetting> > PatchAdminSetting(int id, AdminSettingPatchDto adminSetting) { var existingAdminSetting = await FindById(id); existingAdminSetting.Value = adminSetting.Value; context.Entry(existingAdminSetting).State = EntityState.Modified; try { await context.SaveChangesAsync(); return(Ok(existingAdminSetting)); } catch (DbUpdateConcurrencyException) { if (!AdminSettingExists(id)) { return(NotFound()); } else { throw; } } }
public async Task <IActionResult> PatchEmployee(int id, EmployeePatchDto employeePatchDto) { var existingEmployee = await FindById(id); var updatedEmployee = employeePatchDto .ApplyPatch(existingEmployee); context.Entry(updatedEmployee).State = EntityState.Modified; try { await context.SaveChangesAsync(); // Patch the row in CallWeb. await callWebService.UpdateSurvey(updatedEmployee); return(Ok(updatedEmployee)); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(id)) { return(NotFound()); } else { throw; } } }