public async Task<IHttpActionResult> CreateAccount(CreateAccountRequest request) { var user = new HaloUser { UserName = request.Username }; var creationResult = await _userManager.CreateAsync(user, request.Password); if (creationResult.Succeeded == false) { return BadRequest(string.Join(", ", creationResult.Errors)); } var userBaseData = new UserBaseData { User = new UserId { Id = user.UserId }, Nickname = request.Nickname, BattleTag = "", Level = 0, Clan = new ClanId { Id = 0 }, ClanTag = "" }; await _userBaseDataRepository.SetUserBaseDataAsync(userBaseData); var token = AuthenticateUser(user); return Ok(token); }
public Task SetUserBaseDataAsync(UserBaseData userBaseData) { var user = _context.Users.Find(userBaseData.User.Id); if (user == null) { return Task.FromResult(0); } user.Nickname = userBaseData.Nickname; user.BattleTag = userBaseData.BattleTag; user.Level = userBaseData.Level; // TODO: Fix setting ClanId //user.ClanId = userBaseData.Clan.Id; _context.SaveChanges(); return Task.FromResult(0); }
public static void Register(HttpConfiguration config) { using (var scope = config.DependencyResolver.BeginScope()) { var userManager = (IHaloUserManager) scope.GetService(typeof (IHaloUserManager)); var userBaseDataRepository = (IUserBaseDataRepository) scope.GetService(typeof (IUserBaseDataRepository)); HaloUser testUser1 = new HaloUser { UserName = "******" }; HaloUser testUser2 = new HaloUser { UserName = "******" }; HaloUser testUser3 = new HaloUser { UserName = "******" }; userManager.CreateAsync(testUser1, "123").Wait(); userManager.CreateAsync(testUser2, "456").Wait(); userManager.CreateAsync(testUser3, "no1dead").Wait(); UserBaseData testUser1Data = new UserBaseData { User = new UserId { Id = testUser1.UserId }, Nickname = "no1dead", Clan = new ClanId { Id = 1 }, ClanTag = "ClanTag", Level = 2, BattleTag = "BattleTag" }; UserBaseData testUser2Data = new UserBaseData { User = new UserId { Id = testUser2.UserId }, Nickname = "Nickname", Clan = new ClanId { Id = 1 }, ClanTag = "ClanTag", Level = 10, BattleTag = "BattleTag" }; UserBaseData testUser3Data = new UserBaseData { User = new UserId { Id = testUser3.UserId }, Nickname = "Nickname", Clan = new ClanId { Id = 1 }, ClanTag = "ClanTag", Level = 10, BattleTag = "BattleTag" }; userBaseDataRepository.CreateUserBaseDataAsync(testUser1Data); userBaseDataRepository.CreateUserBaseDataAsync(testUser2Data); userBaseDataRepository.CreateUserBaseDataAsync(testUser3Data); } }
public Task CreateUserBaseDataAsync(UserBaseData userBaseData) { _userBaseData[userBaseData.User.Id] = userBaseData; return Task.FromResult(0); }
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."); } }