public ClanCreateResult ClanCreate(ClanCreateRequest request)
        {
            int userId;
            this.TryGetUserId(out userId);

            Clan newClan = new Clan
            {
                Name = request.Name,
                Tag = request.Tag,
                Description = request.Description
            };

            _clanRepository.CreateAsync(newClan).Wait();
            var leaderMembership = new ClanMembership
            {
                ClanId = newClan.ClanId,
                UserId = userId,
                Role = 1
            };
            _clanMembershipRepository.CreateAsync(leaderMembership).Wait();

            var leaderBaseData = _userBaseDataRepository.GetByUserIdAsync(userId).Result;

            return new ClanCreateResult
            {
                Result = new ServiceResult<UserBaseData>
                {
                    Data = leaderBaseData
                }
            };
        }
 public Task DeleteAsync(Clan clan)
 {
     var foundClan = _context.Clans.Find(clan.ClanId);
     if (foundClan == null) return Task.FromResult(0);
     _context.Clans.Remove(foundClan);
     return _context.SaveChangesAsync();
 }
 public Task UpdateAsync(Clan clan)
 {
     var foundClan = _context.Clans.Find(clan.ClanId);
     if (foundClan == null) return Task.FromResult(0);
     foundClan.Name = clan.Name;
     foundClan.Tag = clan.Tag;
     foundClan.Description = clan.Description;
     return _context.SaveChangesAsync();
 }
 public Task CreateAsync(Clan clan)
 {
     var newClan = new Model.Clan
     {
         Name = clan.Name,
         Tag = clan.Tag,
         Description = clan.Description
     };
     _context.Clans.Add(newClan);
     _context.SaveChanges();
     clan.ClanId = newClan.Id;
     return Task.FromResult(0);
 }
        private ClanMembershipDataVersioned GetClanMembershipDataVersioned(Clan clan)
        {
            var clanMembers = _clanMembershipRepository.FindByClanId(clan.ClanId)
                .Result
                .Select(m => new ClanMember
                {
                    Id = new UserId(m.UserId),
                    ClanRole = m.Role
                });

            return new ClanMembershipDataVersioned
            {
                Clan = new ClanId(clan.ClanId),
                Version = _version++,
                MembershipData = new ClanMembershipData
                {
                    Members = clanMembers.ToList()
                }
            };
        }
        private static void SeedServer(IDependencyScope scope)
        {
            var userManager = (IHaloUserManager) scope.GetService(typeof (IHaloUserManager));
            var userBaseDataRepository = (IUserBaseDataRepository) scope.GetService(typeof (IUserBaseDataRepository));
            var userSubscriptionRepository = (IUserSubscriptionRepository)scope.GetService(typeof(IUserSubscriptionRepository));
            var clanRepository = (IClanRepository)scope.GetService(typeof(IClanRepository));
            var clanMembershipRepository = (IClanMembershipRepository) scope.GetService(typeof (IClanMembershipRepository));

            try
            {
                var clan = clanRepository.FindByNamePrefixAsync("Clan1").Result.FirstOrDefault();
                if (clan == null)
                {
                    clan = new Clan
                    {
                        Name = "Clan1",
                        Description = "First clan",
                        Tag = "TAG"
                    };
                    clanRepository.CreateAsync(clan).Wait();
                }

                HaloUser testUser1 = new HaloUser
                {
                    UserName = "******"
                };
                HaloUser testUser2 = new HaloUser
                {
                    UserName = "******"
                };

                userManager.CreateAsync(testUser1, "123").Wait();
                userManager.CreateAsync(testUser2, "test").Wait();

                UserBaseData testUser1Data = new UserBaseData
                {
                    User = new UserId
                    {
                        Id = testUser1.UserId
                    },
                    Nickname = "User1",
                    Clan = new ClanId
                    {
                        Id = 0
                    },
                    ClanTag = "",
                    Level = 2,
                    BattleTag = "BattleTag1"
                };

                UserBaseData testUser2Data = new UserBaseData
                {
                    User = new UserId
                    {
                        Id = testUser2.UserId
                    },
                    Nickname = "User2",
                    Clan = new ClanId
                    {
                        Id = 0
                    },
                    ClanTag = "",
                    Level = 10,
                    BattleTag = "BattleTag2"
                };

                userBaseDataRepository.SetUserBaseDataAsync(testUser1Data);
                userBaseDataRepository.SetUserBaseDataAsync(testUser2Data);

                var testUser1ClanMembership = new ClanMembership
                {
                    UserId = testUser1.UserId,
                    ClanId = clan.ClanId,
                    Role = 1
                };

                clanMembershipRepository.CreateAsync(testUser1ClanMembership).Wait();

                var testUser1Subscription = new UserSubscription
                {
                    UserId = testUser1.UserId,
                    FriendUserId = testUser2.UserId
                };
                userSubscriptionRepository.CreateAsync(testUser1Subscription).Wait();

            }
            catch (Exception)
            {
                Debug.WriteLine("Server initialization failed.");
            }
        }