【发布时间】:2017-06-18 06:09:57
【问题描述】:
我正在开发 iTunes/amazon/googlePlay 联盟计划,并希望将 AffiliateCode 添加到我在 Web 服务的 ExternalLinks 表中的 URL。这意味着网络服务首先使用 id_cd 从 ExternalLinks[Table] 收集不同的可用链接,然后需要循环访问 AffiliateProgram[Table] 以比较每个链接是否有可用的匹配联属计划。
ExternalLink[Table]
public int id_external_link { get; set; }
public int id_cd { get; set; }
public string Name { get; set; }
public string URL { get; set; }
AffiliateProgram[Table]
public int ID { get; set; }
public string AffiliateName { get; set; }
public string AffiliateSite { get; set; }
public string AffiliateCode { get; set; }
public Nullable<int> CodePosition { get; set; }
AffiliateProgram[Table]AffiliateName 和 ExternalLinks[Table]Name 始终相同。
这就是我设置它的方式,但我还没有让它工作,而且最近几天卡住了。
[Route("api/Cds/ExternalLinks/{id_cd}")]
public async Task<List<ExternalLink>> GetAllExternalLinks(int id_cd)
{
List<ExternalLink> externallinks = await db.ExternalLink
.Where(EL => EL.id_cd == id_cd)
.ToListAsync();
List<ExternalLink> ListAllExternalLinks = new List<ExternalLink>();
for (int i = 0; i < 4; i++)
{
ExternalLink CDEL = new ExternalLink();
if (CDEL.Name == "Itunes") {
var query = from EL in db.ExternalLink
join AP in db.AffiliateProgram on EL.Name equals AP.AffiliateName
select new
{
AffiliateName = AP.AffiliateName,
Name = EL.Name,
AffilateCode = AP.AffiliateCode,
URL = EL.URL
};
URL = query.First().Name + "?mt=1&at=" + query.First().AffiliateCode + "&ct=" + id_cd;
}
ListAllExternalLinks.Add(CDEL);
}
ListAllExternalLinks.AddRange(externallinks);
return ListAllExternalLinks;
}
这会在 postmaster 中产生以下结果,有 4 个空结果:
[
{},
{},
{},
{},
{
"id_external_link": 1459,
"id_cd": 13376,
"name": "Itunes",
"url": "https://itunes.apple.com/...countingcrows"
},
{
"id_external_link": 1460,
"id_cd": 13376,
"name": "Amazon",
"url": "https://www.amazon.com/....countingcrows"
},
{
"id_external_link": 1461,
"id_cd": 13376,
"name": "GooglePlay",
"url": "https://play.google.com/...countingcrows"
}
]
【问题讨论】:
标签: c# sql asp.net-mvc web-services model-view-controller