微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 休息时的关系?

我想在社区中添加一个人,我不确定它是如何完成的?

我的datacontract看起来像这样:

[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>");

希望这更清楚它的两个问题我猜.

解决方法

我认为你的方法,基于你所说的,可能看起来像这样:

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数据可能如下所示:

<Community>
  <CommunityName>CrazyTown</CommunityName>
  <People>
     <Person>Moe Howard</Person>
  </People>
</Community>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐