public async Task <AReturn_Return> GetReturnAsync(long returnId) { using var log = BeginFunction(nameof(ReturnAdminService), nameof(GetReturnAsync), returnId); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); var mReturn = await FulfillmentMicroService.GetReturnAsync(returnId).ConfigureAwait(false); var mTransactions = await FulfillmentMicroService.GetReturnTransactionSummariesAsync(returnId, null, null); var mEvents = await FulfillmentMicroService.GetReturnEventLogSummariesAsync(returnId, null, null); var mReturnRequests = new List <MFulfillment_ReturnRequest>(); foreach (var mReturnItem in mReturn.ReturnItems) { // Retrieve the associated fulfillable if we haven't already. // var returnRequestId = mReturnItem.ReturnRequestId; if (!mReturnRequests.Any(r => r.ReturnRequestId == returnRequestId)) { var mReturnRequest = await FulfillmentMicroService.GetReturnRequestAsync(returnRequestId).ConfigureAwait(false); mReturnRequests.Add(mReturnRequest); } } var mFulfillables = new List <MFulfillment_Fulfillable>(); foreach (var mReturnItem in mReturn.ReturnItems) { // Retrieve the associated fulfillable if we haven't already. // var fulfillableId = mReturnItem.FulfillableId; if (!mFulfillables.Any(r => r.FulfillableId == fulfillableId)) { var mFulfillable = await FulfillmentMicroService.GetFulfillableAsync(fulfillableId).ConfigureAwait(false); mFulfillables.Add(mFulfillable); } } var allowEdit = await SecurityPolicy.AllowEditFulfillment(); var result = Create.AReturn_Return(mReturn, mTransactions, mEvents, mReturnRequests, mFulfillables, allowEdit); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }