Esempio n. 1
0
 public void AddDamage(int characterId, int damage)
 {
     if (_dbContext.QuestInventory.Any(q => q.CharacterId == characterId && q.QuestStatus.Status == "active"))
     {
         _dbContext.QuestInventory.Where(q => q.CharacterId == characterId).Include(q => q.Quest).SingleOrDefault(q => q.QuestStatus.Status == "active").DamageToday += damage;
         _dbContext.SaveChanges();
     }
 }
Esempio n. 2
0
 public bool CreateUserAccount(string username, string email, string passKey, string passSalt)
 {
     if (!_dbContext.Database.IsInMemory())
     {
         using (var connection = _dbContext.Database.GetDbConnection())
         {
             try
             {
                 var command = connection.CreateCommand();
                 command.CommandType = CommandType.StoredProcedure;
                 command.CommandText = "usp_CreateUser";
                 var parameter = command.CreateParameter();
                 parameter.ParameterName = "@Email";
                 parameter.Value         = email;
                 command.Parameters.Add(parameter);
                 parameter = command.CreateParameter();
                 parameter.ParameterName = "@Username";
                 parameter.Value         = username;
                 command.Parameters.Add(parameter);
                 parameter = command.CreateParameter();
                 parameter.ParameterName = "@PasswordKey";
                 parameter.Value         = passKey;
                 command.Parameters.Add(parameter);
                 parameter = command.CreateParameter();
                 parameter.ParameterName = "@PasswordSalt";
                 parameter.Value         = passSalt;
                 command.Parameters.Add(parameter);
                 connection.Open();
                 command.ExecuteNonQuery();
                 connection.Close();
                 return(true);
             }
             catch (Exception ex)
             {
                 return(false);
             }
         }
     }
     else
     {
         if (!UserExists(email, username))
         {
             _dbContext.Users.Add(new User
             {
                 Username     = username,
                 Email        = email,
                 PasswordKey  = passKey,
                 PasswordSalt = passSalt
             });
             _dbContext.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
Esempio n. 3
0
 public void AddEquipment(int characterId, int equipmentId)
 {
     _dbContext.InventorySlots.Add(new InventorySlot
     {
         CharacterId = characterId,
         EquipmentId = equipmentId,
         Left        = false,
         Wearing     = false
     });
     _dbContext.SaveChanges();
 }
Esempio n. 4
0
        public int AddExperience(int userId, int amount)
        {
            //Character c = (from s in _dbContext.Characters where s.UsersId == userId select s).FirstOrDefault();
            Character character = _dbContext.Characters.SingleOrDefault(c => c.UserId == userId);

            character.Experience += amount;
            if (character.Experience < 0)
            {
                character.Experience = 0;
            }
            _dbContext.SaveChanges();
            return(character.Experience);
        }
        public async Task BuyItem()
        {
            await RegisterUser();

            dbContext.Characters.Add(new Character
            {
                Name          = "Test",
                Coins         = 10000,
                CurrentHealth = 100,
                MaxHealth     = 100,
                Experience    = 0,
                UserId        = 1
            });

            dbContext.WeaponTypes.Add(new WeaponType
            {
                Name = "Sword"
            });

            dbContext.Equipment.Add(new Weapon
            {
                Damage       = 1,
                Image        = "weapon",
                Name         = "weapon",
                Price        = 10,
                WeaponTypeId = 1
            });

            dbContext.SaveChanges();

            await LoginUser();

            string request = "/Inventory/Index";

            var response = await client.GetAsync(request);

            int i = 0;
        }
Esempio n. 6
0
 public int AddDailyTask(int userId, string task)
 {
     if (_dbContext.Users.Any(u => u.Id == userId))
     {
         _dbContext.DailyTasks.Add(new DailyTask
         {
             Name          = task,
             UserId        = userId,
             Done          = false,
             DoneYesterday = false
         });
         _dbContext.SaveChanges();
         return(_dbContext.DailyTasks.Where(d => d.UserId == userId).Last().Id);
     }
     else
     {
         return(-1);
     }
 }