public Task<bool> RemoveAsync(int userId)
 {
     var entity = new User {Id = userId};
     UnitOfWork.Users.Attach(entity);
     UnitOfWork.Users.Remove(entity);
     return UnitOfWork.SaveChangesAsync().ContinueWith(x => x.Result > 0);
 }
        public Task<ClaimsIdentity> CreateIdentityAsync(User user, string authenticationType, ClaimsIdentity externalIdentity)
        {
            var identity = new ClaimsIdentity(authenticationType, ClaimTypes.Name, ClaimTypes.Role);

            identity.AddClaims(externalIdentity.Claims);
            identity.AddClaim(new Claim(ClaimTypes.Name, user.Name, ClaimValueTypes.String));
            identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString(), ClaimValueTypes.String));

            if (user.IsAdmin)
            {
                identity.AddClaim(new Claim(ClaimTypes.Role, "admin", ClaimValueTypes.String));
            }

            if (externalIdentity.HasClaim(claim => claim.Type == "urn:reddit:moderator_of"))
            {
                identity.AddClaim(new Claim(ClaimTypes.Role, "moderator", ClaimValueTypes.String));
            }

            if (user.IsBanned)
            {
                identity.AddClaim(new Claim(ClaimTypes.Role, "banned", ClaimValueTypes.String));
            }

            return Task.FromResult(identity);
        }
 private async Task SignInAsync(ClaimsIdentity externalIdentity, User user)
 {
     var owin = HttpContext.GetOwinContext();
     // kill the reddit cookie
     owin.Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie);
     var identity =
         await _users.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie, externalIdentity);
     await Task.Run(() => owin.Authentication.SignIn(new AuthenticationProperties {IsPersistent = true}, identity));
 }
 public async Task<Summoner> AddSummonerAsync(User user, int summonerId, string region, string name)
 {
     user.Summoners.Add(new Summoner
     {
         LeagueInfo = new LeagueInfo(),
         Name = name,
         Region = region,
         SummonerId = summonerId,
         User = user
     });
     await UnitOfWork.SaveChangesAsync();
     return user.Summoners.First(summoner => summoner.SummonerId == summonerId);
 }
        public async Task<User> CreateAsync(string name)
        {
            var user = new User {Name = name};

            if (await Roles.IsAdminAsync(name))
            {
                user.IsAdmin = true;
            }

            UnitOfWork.Users.Add(user);
            if (await UnitOfWork.SaveChangesAsync() == 0)
            {
                throw new InvalidOperationException("Error saving user to data store.");
            }
            return user;
        }
 public Task<bool> AddAsync(User user)
 {
     UnitOfWork.Users.Add(user);
     return UnitOfWork.SaveChangesAsync().ContinueWith(x => x.Result > 0);
 }
 private async Task<string> GetFlairTextAsync(User user)
 {
     var summoner = await _summoners.GetActiveSummonerAsync(user);
     return summoner == null ? "" : LeagueUtil.Stringify(summoner.LeagueInfo);
 }
 public Task<Summoner> GetActiveSummonerAsync(User user)
 {
     return Task.Run(() => user.Summoners.FirstOrDefault(x => x.IsActive));
 }