Я получаю данные из веб-API, но не знаю, как получить этот материал Icollection в мой объект Model
Контроллер Api
public IHttpActionResult Campaigndetails (int id) {
IList<CampaignViewModel> list = null;
using (IdonateEntities2 entities = new IdonateEntities2())
{
list = entities.Campaigns.Include(x => x.Donors).Select(x =>
new CampaignViewModel()
{
campaign_id = x.campaign_id,
title = x.title,
description = x.description,
amount = x.amount,
image = x.image,
raised_amount = x.raised_amount,
category_id = x.category_id,
user_id = x.user_id,
Donor = x.Donors.Select(d=> new DonorViewModel()
{
donor_id = d.donor_id,
donor_name = d.donor_name,
donated_amount = d.donated_amount,
campaign_id = d.campaign_id,
payment_id = d.payment_id
}).ToList()
}).ToList().Where(x => x.campaign_id == id).ToList();
return Ok(list);
}
Контроллер кампании:
public ActionResult Detail (int id) {
List<Category> category = new List<Category>();
string text = string.Empty;
var request = WebRequest.Create("http://localhost:49210/api/campaign/campaigndetails/"+ id);
var response = (HttpWebResponse)request.GetResponse();
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
text = sr.ReadToEnd();
category = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<List<Category>>(text);
}
return View(category);
}
Классы моей модели:
открытый класс Категория {
public Category()
{
this.Donors = new HashSet<DonorViewModel>();
}
public int campaign_id { get; set; }
public string title { get; set; }
public string description { get; set; }
public int amount { get; set; }
public int zipcode { get; set; }
public int category_id { get; set; }
public int user_id { get; set; }
public Nullable <int> raised_amount { get; set; }
public string image { get; set; }
public virtual ICollection<DonorViewModel> Donors { get; set; }
}
public class DonorViewModel
{
public int donor_id { get; set; }
public string donor_name { get; set; }
public int donated_amount { get; set; }
public int campaign_id { get; set; }
public int payment_id { get; set; }
public Nullable<int> user_id { get; set; }
public virtual Category Category { get; set; }
}
}
В тексте отображаются все данные, полученные через веб-интерфейс API, но в объекте категории нет данных в доноре. Я хочу их получить и передать на мой взгляд, чтобы показать