在休息的关系? [英] relationships in rest?
问题描述
我要一个人添加到社区和IM不知道如何做。
I want to add a person to a community and im not sure how its done?
我datacontract看起来是这样的:
My datacontract looks like this:
[DataContract(Name = "Community")]
public class Community
{
public Group()
{
People = new List<Person>();
}
[DataMember(Name = "CommunityName")]
public string CommunityName { get; set; }
public List<Person> People { get; set; }
}
[DataContract(Name = "Person")]
public class Person
{
[DataMember(Name = "PersonName")]
public string PersonName { get; set; }
}
在我的服务,我可以添加一个人或像这样一个社会:
In my service I can add a person or a community like so:
List<Community> Communitys = new List<Community>();
List<Person> people = new List<Person>();
public void AddCommunity(Community community)
{
Communitys.Add(community);
}
public void AddPerson(Person person)
{
people.Add(person);
}
public void AddPersonToCommunity(Person person, Community community)
{
//not sure what to do here
}
但我不能确定如何加入一个人到社区
But I am unsure how to join a person to a community
public void AddPersonToCommunity(Person person, Community community)
{
//community.CommunityName(Person.Add);?
}
和我有一个Windows窗体,当我张贴任何一个人或一个社区它是像这样完成的:
And I have a windows form which when I POST either a person or a community it is done like so:
{
StringBuilder Community = new StringBuilder();
Community.AppendLine("<Community>");
Community.AppendLine("<CommunityName>" + this.textBox4.Text + "</CommunityName>");
Community.AppendLine("</Community>");
但你会如何(一次完成)采取AddPersonToCommunity,使一个字符串生成器,以增加人社区?
But How would you (once completed) take the AddPersonToCommunity and make a string builder in order to add a person to a community?
{
StringBuilder CommunityAddPerson = new StringBuilder();
CommunityAddPerson.AppendLine("<Community&{1}>");
CommunityAddPerson.AppendLine ......
CommunityAddPerson.AppendLine("<CommunityName>" + this.textBox4.Text + "</CommunityName>");
CommunityAddPerson.AppendLine("</Community>");
希望这是更清楚在一个我想它的两个问题。
Hope this is more clear its two questions in one I guess.
推荐答案
我觉得你的方法,根据你说的话,可能是这样的:
I think your method, based on what you are saying, might look like this:
public void AddPersonToCommunity(string person, string communityName)
{
var result = communities.Where(n => String.Equals(n.CommunityName, communityName)).FirstOrDefault();
if (result != null)
{
result.Add(new Person() { Name = person });
}
}
您POST数据可能看起来像这样:
Your POST data may look like this:
<Community>
<CommunityName>CrazyTown</CommunityName>
<People>
<Person>Moe Howard</Person>
</People>
</Community>
这篇关于在休息的关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!