这是我关于stackoverflow的第一个问题,所以如果标题或问题不好,请原谅。
目前我获得了VoucherResponse课程
public class VoucherResponse
{
public int VoucherID { get; set; }
public string VoucherTitle { get; set; }
public IEnumerable<VoucherVariant> VoucherVariants { get; set; }
public string[] VoucherImages { get; set; }
}
和Web api方法
return Ok(from v in distinctby
select new VoucherResponse
{
VoucherID = v.VoucherID,
VoucherTitle = v.VoucherTitle,
VoucherVariants = (from voucher in voucherToLookup[v.VoucherID]
select new VoucherVariant
{
VoucherDiscountedPrice = voucher.VoucherPrice - (voucher.VoucherPrice * voucher.VoucherDiscount/ 100),
VoucherVariantId = voucher.VoucherVariantId,
VoucherPrice = voucher.VoucherPrice,
VoucherStock = 1
}),
VoucherImages = (from image in distinctby
where v.VoucherID == image.VoucherID
select image.VoucherImages
// URLHelper.GetAbsoluteUrl(ModuleCommands.MediaLibraryGetMediaFileUrl(image.FileGUID, voucher.NodeAlias + "_" + image.ImageOrder))).ToArray(),
).ToArray()
});
目前我正在获得结果
{
"voucherID": 380,
"voucherTitle": "Woolworths e-Gift Card",
"voucherVariants": [
{
"voucherVariantId": 397,
"voucherPrice": 100,
"voucherDiscountedPrice": 95,
"voucherStock": 1
},
{
"voucherVariantId": 389,
"voucherPrice": 200,
"voucherDiscountedPrice": 190,
"voucherStock": 1
},
{
"voucherVariantId": 393,
"voucherPrice": 300,
"voucherDiscountedPrice": 285,
"voucherStock": 1
},
{
"voucherVariantId": 394,
"voucherPrice": 400,
"voucherDiscountedPrice": 380,
"voucherStock": 1
},
{
"voucherVariantId": 395,
"voucherPrice": 500,
"voucherDiscountedPrice": 475,
"voucherStock": 1
}
],
"voucherImages": [
" B4A3A070-3ED1-4086-8B33-21465AA58C7A, 2FB01963-2D71-4C79-9EE8-38A114CAF1A6"
]
我需要像这样返回voucherImages
"VoucherImages" : [
{"www.kentico.info/imageOne.jpg"}
{"www.kentico.info/imageTwo.jpg"}
]
答案 0 :(得分:0)
首先感谢您试图帮助我。 我自己解决了这个问题。 @rocky图像存储在媒体库中,我创建的方法接缝工作但我仍然得到“丑陋的网址”像 “http://localhost:50848/getmedia/8f5f2e87-782c-4ee2-b6c0-dba614588fe4/ 我希望得到类似“http://localhost:50848/getmedia/image1.jpg的内容 但是会对此进行研究,如果有人需要该功能中的代码,我将粘贴方法
private string[] GetImageURLs(string guids, string voucherTitle)
{
List<string> result = new List<string>();
string[] guid = guids.Split(',');
string alias, url,image;
foreach (var item in guid)
{
url = ModuleCommands.MediaLibraryGetMediaFileUrl(ValidationHelper.GetGuid(item, Guid.Empty), SiteContext.CurrentSiteName);
image = URLHelper.GetAbsoluteUrl(url);
result.Add(image);
}
return result.ToArray();
}