Esempio n. 1
0
 public AddWeaponViewModel(AddVehicleViewModel vehicle, UserWeapon userWeapon)
     : this(vehicle, userWeapon?.Weapon)
 {
     this.Id       = userWeapon?.Id ?? Guid.NewGuid();
     this.Facing   = userWeapon?.Facing;
     this.Location = userWeapon?.Location;
 }
Esempio n. 2
0
        public IActionResult AddWeapoonToUser(string weaponName, string userName)
        {
            Weapons uw = _context.Weapons.FirstOrDefault(w => w.WeaponName == weaponName);

            Weapons weapon;

            if (uw == null)
            {
                Weapons w = new Weapons {
                    WeaponName = weaponName
                };
                _context.Weapons.Add(w);
                _context.SaveChanges();
                weapon = _context.Weapons.Last();
            }
            else
            {
                weapon = uw;
            }


            if (_context.UserWeapons.Any(x => x.WeaponName != weaponName))
            {
                UserWeapon nuw = new UserWeapon
                {
                    WeaponID   = weapon.ID,
                    WeaponName = weaponName,
                    UserName   = "******"
                };
                _context.UserWeapons.Add(nuw);
                _context.SaveChanges();
            }

            return(RedirectToAction("UserFavoriteWeapons"));
        }
Esempio n. 3
0
 //UserWeapons
 public void AddUserWeapon(UserWeapon userWeapon)
 {
     _context.UserWeapons.Add(userWeapon);
     if (_context.SaveChanges() == 0)
     {
         throw new BeerException("An error occured when adding UserWeapon.");
     }
 }
Esempio n. 4
0
 public void UpdateUserWeaponInUse(UserWeapon userWeapon)
 {
     if (userWeapon.Weapon.MinimumLevel > userWeapon.User.Level)
     {
         throw new BeerException("You do not have the enough level yet !");
     }
     _context.UpdateUserWeaponInUse(userWeapon);
     UpdateBeerUserInformations(BeerCalculationService.CharacteristicsCalculation(userWeapon.User, userWeapon.Weapon));
 }
Esempio n. 5
0
        public void UserName2_TestingGetter_ReturnString()
        {
            // Arrange
            UserWeapon n = new UserWeapon();

            // Act
            n.UserName = "******";

            // Assert
            Assert.Equal("name", n.UserName);
        }
Esempio n. 6
0
        public void UserID_TestingGetter_ReturnInt()
        {
            // Arrange
            UserWeapon n = new UserWeapon();

            // Act
            n.UserID = 4;

            // Assert
            Assert.Equal(4, n.UserID);
        }
Esempio n. 7
0
 public void DeleteUserWeapon(UserWeapon userWeapon)
 {
     if (userWeapon.InUse == true)
     {
         throw new BeerException("You can't delete a weapon that is in use !");
     }
     _context.UserWeapons.Remove(userWeapon);
     if (_context.SaveChanges() == 0)
     {
         throw new BeerException("An error occured when deleting UserWeapon.");
     }
 }
Esempio n. 8
0
        public void WeaponName_TestingSetter_ReturnString()
        {
            // Arrange
            UserWeapon n = new UserWeapon()
            {
                WeaponName = "name"
            };

            // Act
            n.WeaponName = "diffName";

            // Assert
            Assert.Equal("diffName", n.WeaponName);
        }
Esempio n. 9
0
        public void UserID_TestingSetter_ReturnInt()
        {
            // Arrange
            UserWeapon n = new UserWeapon()
            {
                UserID = 6
            };

            // Act
            n.UserID = 3;

            // Assert
            Assert.Equal(3, n.UserID);
        }
Esempio n. 10
0
        public void UpdateUserWeaponInUse(UserWeapon userWeapon)
        {
            var weapons = _context.UserWeapons.Where(w => w.User.Id == userWeapon.User.Id && w.InUse == true).ToList();

            foreach (UserWeapon w in weapons)
            {
                w.InUse = false;
            }
            userWeapon.InUse = true;
            var weapon = _context.UserWeapons.Where(w => w == userWeapon);

            if (_context.SaveChanges() == 0)
            {
                throw new BeerException("An error occured when updating UserWeapon in use.");
            }
        }
Esempio n. 11
0
        public List <UserWeapon> GetUserWeapons(BeerUser beerUser)
        {
            var userWeapons = _context.GetUserWeapons(beerUser);

            if (userWeapons == null || userWeapons.Count == 0)
            {
                var        weapon     = _context.GetWeaponByAttackMore(beerUser.GamerType.WeaponType, 2);
                UserWeapon userWeapon = new UserWeapon(beerUser, weapon, true);
                AddUserWeapon(userWeapon);
                return(_context.GetUserWeapons(beerUser));
            }
            else
            {
                return(userWeapons);
            }
        }
Esempio n. 12
0
 public void DeleteUserWeapon(UserWeapon userWeapon)
 {
     _context.DeleteUserWeapon(userWeapon);
 }
Esempio n. 13
0
 public void AddUserWeapon(UserWeapon userWeapon)
 {
     _context.AddUserWeapon(userWeapon);
 }