使用.NET API调用中的响应Body作为另一个API调用中的POST Body

时间:2018-04-16 19:51:41

标签: .net asp.net-core asp.net-core-webapi

我有一个内置的API,内置在.NET Core 2.0中,它有一个GET方法,我在这里得到一份员工列表,只返回一个JSON列表。作为.NET新手,如何在后续的POST调用中使用这些结果,我们必须上传这些用户?

EmployeeController.cs

[Produces("application/json")]
[Route("api/Employee")]
public class EmployeeController : Controller
{
    private readonly EDWContext _edwContext;

    public EmployeeController(EDWContext context)
    {
        _edwContext = context;
    }

    [HttpGet(Name = "GetAllEmployees")]
    public ActionResult GetAllEmployees()
    {


        var results = from email in _edwContext.EmployeeEmail
                      join emp in _edwContext.Employee on email.EmployeeID equals emp.EmployeeID
                      join eol in _edwContext.EmployeeOfficeLocation on emp.EmployeeID equals eol.EmployeeID
                      join jc in _edwContext.JobCode on emp.JobCodeID equals jc.JobCodeID
                      join lf in _edwContext.LocationFloor on eol.LocationFloorID equals lf.LocationFloorID
                      join ol in _edwContext.OfficeLocation on lf.OfficeLocationID equals ol.OfficeLocationID
                      join o in _edwContext.Office on ol.OfficeID equals o.OfficeID
                      where emp.EmployeeStatusID == 1 
                      || emp.EmployeeStatusID == 3
                      || emp.EmployeeStatusID == 4
                      where email.EmailtypeID == 1
                      select new
                      {
                          emp.EmployeeID,
                          emp.FirstName,
                          emp.MiddleName,
                          emp.LastName,
                          jc.JobCodeName,
                          email.EmailAddress,
                          o.OfficeName
                      };




        return Json(results.ToList());
    }

0 个答案:

没有答案