public Task DeleteAsync(Party party)
 {
     var foundParty = _context.Parties.FirstOrDefault(p => p.Id == party.Id);
     if (foundParty != null)
     {
         _context.Parties.Remove(foundParty);
         _context.SaveChanges();
     }
     return Task.FromResult(0);
 }
 public Task UpdateAsync(Party party)
 {
     var foundParty = _context.Parties.FirstOrDefault(p => p.Id == party.Id);
     if (foundParty != null)
     {
         foundParty.MatchmakeState = party.MatchmakeState;
         foundParty.GameData = party.GameData;
         _context.SaveChanges();
     }
     return Task.FromResult(0);
 }
 public Task CreateAsync(Party party)
 {
     var newParty = new Model.Party
     {
         Id = party.Id,
         MatchmakeState = party.MatchmakeState,
         GameData = party.GameData
     };
     _context.Parties.Add(newParty);
     _context.SaveChanges();
     return Task.FromResult(0);
 }
 private bool TryGetParty(string partyId, out Party party)
 {
     party = _partyRepository.FindByPartyIdAsync(partyId).Result;
     return party != null;
 }
 private PartyStatus GetPartyStatus(Party party, IEnumerable<PartyMember> partyMembers)
 {
     return new PartyStatus
     {
         Party = new PartyId(party.Id),
         MatchmakeState = party.MatchmakeState,
         GameData = party.GameData,
         SessionMembers = partyMembers.Select(p =>
             new PartyMemberDto
             {
                 User = new UserId(p.UserId),
                 IsOwner = p.IsOwner
             }).ToList()
     };
 }
        public PresenceConnectResult PresenceConnect(PresenceConnectRequest request)
        {
            int userId;
            this.TryGetUserId(out userId);

            var party = new Party
            {
                Id = Guid.NewGuid().ToString(),
                MatchmakeState = 0,
                GameData = new byte[100]
            };
            _partyRepository.CreateAsync(party).Wait();

            var partyOwner = new PartyMember
            {
                UserId = userId,
                PartyId = party.Id,
                IsOwner = true
            };
            _partyMemberRepository.CreateAsync(partyOwner).Wait();

            var partyStatus = GetPartyStatus(party, new[] { partyOwner });

            return new PresenceConnectResult
            {
                Result = new ServiceResult<PartyStatus>
                {
                    Data = partyStatus
                }
            };
        }
        public PartyGetStatusResult PartyGetStatus(PartyGetStatusRequest request)
        {
            PartyMember partyMember;
            Party party;
            IEnumerable<PartyMember> partyMembers;
            if (TryGetUserPartyMember(out partyMember) &&
                TryGetParty(partyMember.PartyId, out party))
            {
                partyMembers = _partyMemberRepository.FindByPartyId(party.Id).Result;
            }
            else
            {
                party = new Party
                {
                    Id = "",
                    MatchmakeState = 0,
                    GameData = new byte[0]
                };
                partyMembers = new PartyMember[0];
            }
            var partyStatus = GetPartyStatus(party, partyMembers);

            return new PartyGetStatusResult
            {
                Result = new ServiceResult<PartyStatus>
                {
                    Data = partyStatus
                }
            };
        }