public AddWeaponViewModel(AddVehicleViewModel vehicle, UserWeapon userWeapon) : this(vehicle, userWeapon?.Weapon) { this.Id = userWeapon?.Id ?? Guid.NewGuid(); this.Facing = userWeapon?.Facing; this.Location = userWeapon?.Location; }
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")); }
//UserWeapons public void AddUserWeapon(UserWeapon userWeapon) { _context.UserWeapons.Add(userWeapon); if (_context.SaveChanges() == 0) { throw new BeerException("An error occured when adding UserWeapon."); } }
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)); }
public void UserName2_TestingGetter_ReturnString() { // Arrange UserWeapon n = new UserWeapon(); // Act n.UserName = "******"; // Assert Assert.Equal("name", n.UserName); }
public void UserID_TestingGetter_ReturnInt() { // Arrange UserWeapon n = new UserWeapon(); // Act n.UserID = 4; // Assert Assert.Equal(4, n.UserID); }
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."); } }
public void WeaponName_TestingSetter_ReturnString() { // Arrange UserWeapon n = new UserWeapon() { WeaponName = "name" }; // Act n.WeaponName = "diffName"; // Assert Assert.Equal("diffName", n.WeaponName); }
public void UserID_TestingSetter_ReturnInt() { // Arrange UserWeapon n = new UserWeapon() { UserID = 6 }; // Act n.UserID = 3; // Assert Assert.Equal(3, n.UserID); }
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."); } }
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); } }
public void DeleteUserWeapon(UserWeapon userWeapon) { _context.DeleteUserWeapon(userWeapon); }
public void AddUserWeapon(UserWeapon userWeapon) { _context.AddUserWeapon(userWeapon); }