【发布时间】:2012-04-06 16:20:02
【问题描述】:
我想向社区添加一个人,但我不确定它是如何完成的?
我的数据合约如下所示:
[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; }
}
在我的服务中,我可以像这样添加一个人或一个社区:
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
}
但我不确定如何将某人加入社区
public void AddPersonToCommunity(Person person, Community community)
{
//community.CommunityName(Person.Add);?
}
我有一个 Windows 窗体,当我发布一个人或一个社区时,它是这样完成的:
{
StringBuilder Community = new StringBuilder();
Community.AppendLine("<Community>");
Community.AppendLine("<CommunityName>" + this.textBox4.Text + "</CommunityName>");
Community.AppendLine("</Community>");
但是您将如何(一旦完成)使用 AddPersonToCommunity 并创建一个字符串构建器以便将一个人添加到社区?
{
StringBuilder CommunityAddPerson = new StringBuilder();
CommunityAddPerson.AppendLine("<Community&{1}>");
CommunityAddPerson.AppendLine ......
CommunityAddPerson.AppendLine("<CommunityName>" + this.textBox4.Text + "</CommunityName>");
CommunityAddPerson.AppendLine("</Community>");
希望这更清楚我猜它的两个问题。
【问题讨论】:
-
你不认为你需要一个
AddPersonToCommunity(Community community, Person person)方法来完成你所说的吗? -
是的,Bryan,但我应该在方法中添加什么?
-
您的问题和想法无处不在。请重新表述您的问题并更加连贯。不清楚你在问什么。
标签: c# wcf web-services rest