【发布时间】:2015-04-12 06:50:58
【问题描述】:
这是我的previous question 的扩展。
我必须将 CorelationID 传递给我的 API 服务并匹配部门和员工记录。
我从 Javascript 传递的数组如下
EmployeesAPIController.cs
using System.Web.Http;
namespace EmployeeService
{
[RoutePrefix("Employee")]
public class EmployeesAPIController : ApiController
{
[HttpPost]
[Route("InsertEmployeeDepartment")]
public EmployeeDepartment InsertEmployeeAndDepartment(object employeedepartment)
{
var empDept = JsonConvert.DeserializeObject<EmployeeDepartment>(employeedepartment.ToString());
//insert the new department records
DepartmentRecords = InsertDepartment(empDept.Departments);
//fill the employee record with the associated Coreration Id
Here I have to join the Employee and Department Records by the CorelationID
//insert employee records
EmployeeRecords = InsertEmployee(empDept.Employees);
}
}
}
JS文件如下
var guid = GenerateGuid();
//build the employee object
var Employee = {
EmployeeId: $scope.EmployeeId,
EmployeeName: $scope.EmployeeName,
Age: $scope.Age,
Salary: $scope.Salary,
CorrelationID: guid
};
//build the department object
var Department = {
Deptid: $scope.DepartmentID,
Deptname: $scope.DepartmentName,
CorrelationID: guid
};
我该怎么做?
对象看起来像(一个例子)
编辑
我正在尝试使用 Expando Object,如下所示
public EmployeeDepartment InsertEmployeeAndDepartment(ExpandoObject 员工)
如何从这里获取员工和部门数组?
【问题讨论】:
-
部门记录长什么样?插入后 CorrelationId 会改变吗?
-
这取决于插入类型。如果成功,则相关性将保持不变,否则它将改变。基于此,我需要匹配员工,并且只有具有匹配 corelationID 的员工才有资格进行有效插入
-
我在我的回答中输入了这个查询,它将只接受与
CorrelationId匹配的员工。
标签: javascript c# asp.net-web-api