C# で MVC4 を使用して API を作成しました。コマンドのいくつかに問題があります。「'API.Controllers.EmployeesController.GetDepartment(int)' のオーバーロードされた最適な一致には、無効な引数があります。」というエラーが表示され続けます。以下は私のコードです。同様の関数を呼び出す 3 つの異なる行でエラーが発生します。関数に送信される値は、null になる可能性があります。
public List<Models.Position> GetPositions(int EmployeeID)
{
var positions = from position in _context.tbl_positions
where position.people_ID == EmployeeID
select new Models.Position
{
PositionID = position.id
,Department = position.dept_ID == null ? string.Empty : GetDepartment(position.dept_ID)
,JobTitle = position.title
,Building = position.location_ID == null ? string.Empty : GetBuilding(position.location_ID)
,Room = position.room
,Phone = position.public3 == null ? string.Empty : "000-111-" + position.public3
,Fax = position.fax3 == null ? string.Empty : "000-111-" + position.fax3
,College = position.college_ID == null ? string.Empty ? GetCollege(position.college_ID)
};
return positions.ToList();
}
public string GetDepartment(int DeptId)
{
var department = (from departments in _context.tbl_departments
where departments.ID == DeptId
select departments.dept).SingleOrDefault();
return department;
}
public string GetBuilding(int BID)
{
var building = (from buildings in _context.tbl_locations
where buildings.id == BID
select buildings.Name).FirstOrDefault();
return building;
}
public string GetCollege(int CID)
{
var college = (from colleges in _context.tbl_colleges
where colleges.id == CID
select colleges.college).SingleOrDefault();
return college;
}