Example #1
0
        public static Result VisitMedicBay(string userId)
        {
            var result = new Result();

            try
            {
                using (var heroContext = new HeroContext())
                {
                    var hero = heroContext.Heroes.Single(p => p.UserId == userId);

                    string validationMessage;
                    if (!ValidationService.Validate(hero, 1, out validationMessage))
                    {
                        throw new Exception(validationMessage);
                    }

                    var dice           = new DiceService();
                    var healthRestored = restoreHealth(hero, dice);
                    heroContext.SaveChanges();

                    var successMessage = string.Format("The Medic Bay restored {0} health!", healthRestored);
                    result.Message = successMessage;
                    result.Hero    = hero;

                    ActivityService.QueueActivity(userId, EventType.Medic, successMessage);
                }
            }
            catch (Exception exception)
            {
                Trace.TraceError(exception.Message);
                throw;
            }
            return(result);
        }
Example #2
0
    public static BattleResult PerformBattle(string userId, RobotDifficulty difficulty)
    {
      BattleResult battleResult;
      try
      {
        using (var heroContext = new HeroContext())
        {
          string validationMessage;
          var hero = heroContext.Heroes.Single(p => p.UserId == userId);
          if (!ValidationService.Validate(hero, 0, out validationMessage))
          {
            throw new Exception(validationMessage);
          }
          
          var dice = new DiceService();
          var robot = RobotFactory.GetRobot(difficulty, dice);

          battleResult = performBattle(hero, robot, dice);
          heroContext.SaveChanges();
        }
      }
      catch (Exception exception)
      {
        Trace.TraceError(exception.Message);
        throw;
      }
      return battleResult;
    }
Example #3
0
    public static Result VisitMedicBay(string userId)
    {
      var result = new Result();
      try
      {
        using (var heroContext = new HeroContext())
        {
          var hero = heroContext.Heroes.Single(p => p.UserId == userId);

          string validationMessage;
          if (!ValidationService.Validate(hero, 1, out validationMessage))
          {
            throw new Exception(validationMessage);
          }

          var dice = new DiceService();
          var healthRestored = restoreHealth(hero, dice);
          heroContext.SaveChanges();

          var successMessage = string.Format("The Medic Bay restored {0} health!", healthRestored);
          result.Message = successMessage;
          result.Hero = hero;

          ActivityService.QueueActivity(userId, EventType.Medic, successMessage);
        }
      }
      catch (Exception exception)
      {
        Trace.TraceError(exception.Message);
        throw;
      }
      return result;
    }
        public static BattleResult PerformBattle(string userId, RobotDifficulty difficulty)
        {
            BattleResult battleResult;

            try
            {
                using (var heroContext = new HeroContext())
                {
                    string validationMessage;
                    var    hero = heroContext.Heroes.Single(p => p.UserId == userId);
                    if (!ValidationService.Validate(hero, 0, out validationMessage))
                    {
                        throw new Exception(validationMessage);
                    }

                    var dice  = new DiceService();
                    var robot = RobotFactory.GetRobot(difficulty, dice);

                    battleResult = performBattle(hero, robot, dice);
                    heroContext.SaveChanges();
                }
            }
            catch (Exception exception)
            {
                Trace.TraceError(exception.Message);
                throw;
            }
            return(battleResult);
        }
Example #5
0
 public static Hero GetHero(string heroId)
 {
   Hero hero;
   using (var heroContext = new HeroContext())
   {
      hero = heroContext.Heroes.Single(p => p.UserId == heroId);
   }
   return hero;
 }
Example #6
0
        public static Hero GetHero(string heroId)
        {
            Hero hero;

            using (var heroContext = new HeroContext())
            {
                hero = heroContext.Heroes.Single(p => p.UserId == heroId);
            }
            return(hero);
        }
Example #7
0
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();

            //var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text };
            
            var user = new ApplicationUser
            {
                UserName = EmailTextBox.Text,
                Email = EmailTextBox.Text
            };

          IdentityResult result = manager.Create(user, Password.Text);
            if (result.Succeeded)
            {
                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                //string code = manager.GenerateEmailConfirmationToken(user.Id);
                //string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
                //manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");

              using (var heroContext = new HeroContext())
              {
                var hero = new Hero
                {
                  UserId = user.Id,
                  Name = HeroNameTextbox.Text,
                  MovesRemaining = 25,
                  Credits = 10,
                  Health = 50,
                  TrainingLevel = 0,
                  ArmorBonus = 0,
                  WeaponBonus = 0,
                  Wins = 0,
                  Losses = 0
                };
                heroContext.Heroes.Add(hero);
                heroContext.SaveChanges();
              }
                IdentityHelper.SignIn(manager, user, isPersistent: false);
                IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
            else 
            {
                ErrorMessage.Text = result.Errors.FirstOrDefault();
            }
        }
 public static IEnumerable<Hero> GenerateLeaderboard()
 {
   IEnumerable<Hero> list;
   try
   {
     using (var heroContext = new HeroContext())
     {
       var heros =
           from p in heroContext.Heroes.Take(10)
           orderby p.Credits descending
           select p;
       list = heros.ToList();
     }
   }
   catch (Exception exception)
   {
     Trace.TraceError(exception.Message);
     throw;
   }
   return list;
 }
Example #9
0
        public static IEnumerable <Hero> GenerateLeaderboard()
        {
            IEnumerable <Hero> list;

            try
            {
                using (var heroContext = new HeroContext())
                {
                    var heros =
                        from p in heroContext.Heroes.Take(10)
                        orderby p.Credits descending
                        select p;
                    list = heros.ToList();
                }
            }
            catch (Exception exception)
            {
                Trace.TraceError(exception.Message);
                throw;
            }
            return(list);
        }
        public static Result PurchaseArmor(string userId)
        {
            var result = new Result();

            try
            {
                using (var heroContext = new HeroContext())
                {
                    var hero = heroContext.Heroes.Single(p => p.UserId == userId);

                    string validationMessage;
                    if (!ValidationService.Validate(hero, 10, out validationMessage))
                    {
                        throw new Exception(validationMessage);
                    }
                    var dice             = new DiceService();
                    var armorImprovement = improveArmor(hero, dice);

                    heroContext.SaveChanges();

                    var successMessage = string.Format(
                        "Armor upgrade was successful giving you an improvement of {0}!",
                        armorImprovement);

                    result.Message = successMessage;
                    result.Hero    = hero;

                    ActivityService.QueueActivity(userId, EventType.Armor, successMessage);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message);
                throw new Exception(ex.Message);
            }
            return(result);
        }
Example #11
0
        public static Result Train(string userId)
        {
            var result = new Result();

            try
            {
                using (var heroContext = new HeroContext())
                {
                    var hero = heroContext.Heroes.Single(p => p.UserId == userId);

                    string validationMessage;
                    if (!ValidationService.Validate(hero, 1, out validationMessage))
                    {
                        throw new Exception(validationMessage);
                    }

                    var dice             = new DiceService();
                    var trainingIncrease = performTraining(hero, dice);
                    heroContext.SaveChanges();

                    var successMessage =
                        string.Format("Training was successful earning you a {0} point training advantage!",
                                      trainingIncrease);

                    result.Message = successMessage;
                    result.Hero    = hero;

                    ActivityService.QueueActivity(userId, EventType.Weapon, successMessage);
                }
            }
            catch (Exception exception)
            {
                Trace.TraceError(exception.Message);
                throw;
            }
            return(result);
        }
Example #12
0
    public static Result PurchaseArmor(string userId)
    {
      var result = new Result();
      try
      {
        using (var heroContext = new HeroContext())
        {
          var hero = heroContext.Heroes.Single(p => p.UserId == userId);

          string validationMessage;
          if (!ValidationService.Validate(hero, 10, out validationMessage))
          {
            throw new Exception(validationMessage);
          }
          var dice = new DiceService();
          var armorImprovement = improveArmor(hero, dice);
          
          heroContext.SaveChanges();

          var successMessage = string.Format(
            "Armor upgrade was successful giving you an improvement of {0}!", 
            armorImprovement);

          result.Message = successMessage;
          result.Hero = hero;

          ActivityService.QueueActivity(userId, EventType.Armor, successMessage);
        }
      }
      catch (Exception ex)
      {
        Trace.TraceError(ex.Message);
        throw new Exception(ex.Message);
      }
      return result;
    }
Example #13
0
    public static Result Train(string userId)
    {
      var result = new Result();
      try
      {
        using (var heroContext = new HeroContext())
        {
          var hero = heroContext.Heroes.Single(p => p.UserId == userId);

          string validationMessage;
          if (!ValidationService.Validate(hero, 1, out validationMessage))
          {
            throw new Exception(validationMessage);
          }

          var dice = new DiceService();
          var trainingIncrease = performTraining(hero, dice);
          heroContext.SaveChanges();

          var successMessage = 
            string.Format("Training was successful earning you a {0} point training advantage!", 
            trainingIncrease);

          result.Message = successMessage;
          result.Hero = hero;

          ActivityService.QueueActivity(userId, EventType.Weapon, successMessage);
        }
      }
      catch (Exception exception)
      {
        Trace.TraceError(exception.Message);
        throw;
      }
      return result;
    }
        private void CreateAndLoginUser()
        {
            if (!IsValid)
            {
                return;
            }
            var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
            //var user = new ApplicationUser() { UserName = email.Text, Email = email.Text };

            var user = new ApplicationUser
            {
              UserName = EmailTextBox.Text,
              Email = EmailTextBox.Text
            };

          
          IdentityResult result = manager.Create(user);
            if (result.Succeeded)
            {
                var loginInfo = Context.GetOwinContext().Authentication.GetExternalLoginInfo();
                if (loginInfo == null)
                {
                    RedirectOnFail();
                    return;
                }
                result = manager.AddLogin(user.Id, loginInfo.Login);
                if (result.Succeeded)
                {

                  using (var heroContext = new HeroContext())
                  {
                    var hero = new Hero
                    {
                      UserId = user.Id,
                      Name = HeroNameTextbox.Text,
                      MovesRemaining = 25,
                      Credits = 10,
                      Health = 50,
                      TrainingLevel = 0,
                      ArmorBonus = 0,
                      WeaponBonus = 0,
                      Wins = 0,
                      Losses = 0
                    };
                    heroContext.Heroes.Add(hero);
                    heroContext.SaveChanges();
                  }

                    IdentityHelper.SignIn(manager, user, isPersistent: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // var code = manager.GenerateEmailConfirmationToken(user.Id);
                    // Send this link via email: IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id)

                    IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
                    return;
                }
            }
            AddErrors(result);
        }