public void ChangeBadge(Badge badge, ApplicationUser user, Challenge currentChallenge)
 {
 }
 public Badge GenerateNewBadge(ApplicationUser user, Challenge currentChallenge)
 {
     if (user.Challenges.Count(c => c.Done) >= 10)
         return new Badge() { Name = "trotsegebruiker", Description = "    " };
     return null;
 }
        public Badge GenerateNewBadge(ApplicationUser user, Challenge currentChallenge)
        {
            if (user.Challenges.Count == 1 && currentChallenge.Done == false)
                return new Badge() {
                    Name = "starter",
                    Description = "You requested your first challenge!"
                };

            return null;
        }
 public Badge GenerateNewBadge(ApplicationUser user, Challenge currentChallenge)
 {
     //  throw new NotImplementedException();
     if (user.Challenges.Count(c => c is TextChallenge && c.Done && c.Type.Equals("Suikervrij")) == 1 && currentChallenge is TextChallenge && currentChallenge.Done && currentChallenge.Type.Equals("Suikervrij"))
         return new Badge() { Name = "sugarrush", Description = "            " };
     return null;
 }
 public void ChangeBadge(Badge badge, ApplicationUser user, Challenge currentChallenge)
 {
     if (user.Points >= 50)
         badge.Name = "level6";
 }
 public Badge GenerateNewBadge(ApplicationUser user, Challenge currentChallenge)
 {
     //  throw new NotImplementedException();
     return null;
 }
 public Badge GenerateNewBadge(ApplicationUser user, Challenge currentChallenge)
 {
     //  throw new NotImplementedException();
     if (user.Challenges.Count(c => c is RestaurantChallenge) == 1 && currentChallenge is RestaurantChallenge && currentChallenge.Done)
         return new Badge() { Name = "genieter", Description = "      " };
     return null;
 }
 public Badge GenerateNewBadge(ApplicationUser user, Challenge currentChallenge)
 {
     var levels = new string[] { "level1", "level2", "level3", "level4", "level5", "level6" };
     foreach (var level in levels)
         if (user.HasBadge(level))
             return null;
     if (user.Points == 0)
         return new Badge() { Name = "level1", Description = "Level one reached." };
     return null;
 }
 public Badge GenerateNewBadge(ApplicationUser user, Challenge currentChallenge)
 {
     //  throw new NotImplementedException();
     if (user.Challenges.Count(c => c is RecipeChallenge && c.Done && (c as RecipeChallenge).Recipe.Properties.Count(p => p.Type.Equals("Regio")) >= 1) == 1 && currentChallenge is RestaurantChallenge && currentChallenge.Done)
         return new Badge() { Name = "explorer", Description = "            " };
     return null;
 }
 public Badge GenerateNewBadge(ApplicationUser user, Challenge currentChallenge)
 {
     //  throw new NotImplementedException();
     if (user.Challenges.Count(c => c is RecipeChallenge && c.Done && (c as RecipeChallenge).PrepareFor != TargetSubject.Self) == 1 && currentChallenge is RecipeChallenge && currentChallenge.Done && (currentChallenge as RecipeChallenge).PrepareFor != TargetSubject.Self)
         return new Badge() { Name = "gastheer", Description = "            " };
     return null;
 }
 public Badge GenerateNewBadge(ApplicationUser user, Challenge currentChallenge)
 {
     if (user.Challenges.Count(c => c.Done) == 21)
         return new Badge() {
             Name = "doorzetter",
             Description = "  "
         };
     return null;
 }
 public Badge GenerateNewBadge(ApplicationUser user, Challenge currentChallenge)
 {
     //  throw new NotImplementedException();
     if (user.Challenges.Count(c => c is CreativeCookingChallenge && c.Done) == 1 && currentChallenge is CreativeCookingChallenge && currentChallenge.Done)
         return new Badge() { Name = "creatieveling", Description = "            " };
     return null;
 }
        public void RewardBadges(ApplicationUser user, Challenge current)
        {
            foreach (var kv in _rewarders) {

                if (user.HasBadge(kv.Key))
                    kv.Value.ChangeBadge(user.GiveBadge(kv.Key), user, current);
                else {
                    var newBadge = kv.Value.GenerateNewBadge(user, current);
                    if (newBadge != null)
                        user.Badges.Add(newBadge);
                }
            }
        }
        public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model) {
            if (!ModelState.IsValid) {
                return BadRequest(ModelState);
            }

            var info = await Authentication.GetExternalLoginInfoAsync();

            if (info == null) {
                return InternalServerError();
            }

            var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };

            IdentityResult result = await UserManager.CreateAsync(user);
            if (!result.Succeeded) {
                return GetErrorResult(result);
            }

            result = await UserManager.AddLoginAsync(user.Id, info.Login);
            if (!result.Succeeded) {
                return GetErrorResult(result);
            }
            return Ok();
        }
        public async Task<IHttpActionResult> Register(RegisterBindingModel model) {
            if (!ModelState.IsValid) {
                return BadRequest(ModelState);
            }

            var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded) {
                return GetErrorResult(result);
            }

            return Ok();
        }