0
WebAPI HttpPostコントローラメソッドからオブジェクトを返そうとしていますが、投稿は成功しましたがオブジェクトは私のAngularJSサービスに戻っていません。私のデータベースでその結果を見ることができるので、コントローラメソッドが呼び出されています。WebAPIからオブジェクトを返す方法httppostコントローラmoethod
WebAPIの方法は、次のコード
erm.service('ERM_ERWeb_MobileSync_Service', ['$http', '$rootScope', 'ERM_Common_Factory', 'ERM_Common_Service',
function ($http, $rootScope, ERM_Common_Factory, ERM_Common_Service) {
this.SendData = function (payload) {
console.log('ERM_ERWeb_MobileSync_Service.SendData called...');
$http.defaults.headers.common.Authorization = 'Basic ' + ERM_Common_Service.Base64Encode(ERM_Common_Factory.GenAuthString());
$http({
url: ERM_Common_Factory.GetWebAPILocation() + '/API/MobileSync/ConsumeData',
dataType: 'json',
method: 'POST',
data: payload,
headers: {
"Content-Type": "application/json"
}
})
.then(function (response) {
$rootScope.$emit('ERM_ERWeb_MobileSync_Service_SendData_Complete', {});
},
function (error) {
$rootScope.$emit('ERM_ERWeb_MobileSync_Service_SendData_Error', {});
});
};
}]);
これはコントローラのメソッドであると呼ばれています。
[HttpPost]
[Route("ConsumeData")]
[ERMobileInstanceAuth]
public IHttpActionResult ConsumeData([FromBody]MobileSyncPayload msp)
{
try
{
_individualService.SetNoShows(msp.NoShows.Select(i => (Models.Data.Instance.T_Individual)i).ToList());
_flightService.SetFlightTimes(msp.Flights.Select(f => (Models.Data.Instance.T_FlightLog)f).ToList());
Dictionary<Guid, int> vNums = new Dictionary<Guid, int>();
foreach (Voucher v in msp.Vouchers)
{
Dictionary<Guid, int> vNumsTemp = _voucherService.SyncVouchers(new List<Models.Data.Instance.T_Voucher>() { v });
vNums = vNums.Concat(vNumsTemp).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
_voucherLineService.SyncVoucherLines(v.VoucherGUID, v.VoucherLines.Select(vl => (Models.Data.Instance.T_VoucherLine)vl).ToList());
_cashPaymentService.SyncCashPayments(v.CashPayments.Select(cp => (Models.Data.Instance.T_CashPayment)cp).ToList());
_cardPaymentService.SyncCardPayments(v.CardPayments.Select(cp => (Models.Data.Instance.T_CardPayment)cp).ToList(), true);
List<CardPaymentAttempt> acpa = new List<CardPaymentAttempt>();
foreach (CardPayment cp in v.CardPayments)
{
acpa.AddRange(cp.CardPaymentAttempts);
}
_cardPaymentAttemptService.SyncCardPaymentAttempts(acpa.Select(cpa => (Models.Data.Instance.T_CardPaymentAttempt)cpa).ToList());
}
var returnobject = new { Response = ConvertToList(vNums) };
return Ok(returnobject);
}
catch (Exception e)
{
Logging.CreateLogEntry("DataService", Logging.ExceptionHandler.Format(e, Logging.ExceptionHandler.LogLevel.Exception));
return InternalServerError();
}
}
私は行方不明ですが、私はそれが何であるかはわかりません。誰もがアイデアを持っていますか?