コード例 #1
0
        private void SetWards(ISession session, Guardian guardian, List<Ward> wards)
        {
            guardian.Wards.Clear();

            //add new ward list
            foreach (var ward in wards)
            {

                var juniorPlayer = session.CreateCriteria(typeof(Player))
                    .List<Player>()
                    .FirstOrDefault(x => x.Member.Id.Equals(ward.MemberId));

                if (juniorPlayer != null)
                {
                    guardian.AddWard(juniorPlayer);
                }
                else
                {
                    juniorPlayer = new Player();
                    var juniorMember = session.CreateCriteria(typeof(Member))
                        .List<Member>().FirstOrDefault(x => x.Id.Equals(ward.MemberId));

                    if (juniorMember == null)
                    {
                        juniorMember = new Member
                        {
                            Lastname = ward.Lastname,
                            Firstname = ward.Firstname,
                            Types = new List<MemberType>(),
                            MemberKey =
                                CustomStringHelper.BuildKey(new[] { ward.Lastname, ward.Firstname })
                        };
                        var juniorType = session.CreateCriteria(typeof(MemberType))
                            .List<MemberType>().FirstOrDefault(x => x.Name.Equals("Player"));
                        juniorMember.AddMemberType(juniorType);
                    }

                    juniorMember.Dob = ward.Dob;
                    SetAudit(juniorMember);
                    session.SaveOrUpdate(juniorMember);

                    juniorPlayer.Member = juniorMember;
                    juniorPlayer.Nickname = ward.Nickname;
                    juniorPlayer.PlayerType = (int)PlayerType.Junior;
                    juniorPlayer.Guardians = new List<Guardian>();
                    SetAudit(juniorPlayer);
                    session.SaveOrUpdate(juniorPlayer);
                    guardian.AddWard(juniorPlayer);
                }
            }
        }