public async Task <IActionResult> GetActiveCallsList(int linkId) { var link = await _departmentLinksService.GetLinkByIdAsync(linkId); List <CallListJson> callsJson = new List <CallListJson>(); if (link.DepartmentId != DepartmentId && link.LinkedDepartmentId != DepartmentId) { Unauthorized(); } if (link.LinkEnabled && link.DepartmentShareCalls) { var calls = (await _callsService.GetActiveCallsByDepartmentAsync(link.DepartmentId)).OrderByDescending(x => x.LoggedOn); var department = await _departmentsService.GetDepartmentByIdAsync(link.DepartmentId, false); foreach (var call in calls) { var callJson = new CallListJson(); callJson.CallId = call.CallId; callJson.Number = call.Number; callJson.Name = call.Name; callJson.State = _callsService.CallStateToString((CallStates)call.State); callJson.StateColor = _callsService.CallStateToColor((CallStates)call.State); callJson.Timestamp = call.LoggedOn.TimeConverterToString(department); callJson.Priority = await _callsService.CallPriorityToStringAsync(call.Priority, link.DepartmentId); callJson.Color = await _callsService.CallPriorityToColorAsync(call.Priority, link.DepartmentId); if (ClaimsAuthorizationHelper.IsUserDepartmentAdmin() || call.ReportingUserId == UserId) { callJson.CanDeleteCall = true; } else { callJson.CanDeleteCall = false; } callsJson.Add(callJson); } } return(Json(callsJson)); }