public IActionResult GenerateItem(int id) { var item = _enemyServices.GenerateItem(id); var enemy = _enemyServices.GetById(id); string itemName; switch (item) { case -1: itemName = "[No Items Error: Enemy must have minimum 1 Item]"; break; case -2: itemName = "[Null Chance Error: Enemy must have minimum 1 Item with chance > 0]"; break; default: itemName = _itemServices.GetById(item).Name; break; } EnemyItemWithChanceViewModel model = new EnemyItemWithChanceViewModel { EnemyId = id, EnemyName = enemy.Name, ItemId = item, ItemName = itemName, Chance = (item < 0)? 0 : enemy.EnemyItems.FirstOrDefault(i => i.ItemId == item).Chance }; return(View(model)); }
public IActionResult EditItemChance(EnemyItemWithChanceViewModel model) { if (!ModelState.IsValid) { return(View(model)); } _enemyServices .UpdateItemOnEnemy(model.EnemyId, _itemServices.GetById(model.ItemId), model.Chance); return(RedirectToAction("Index", "Enemy")); }
public IActionResult EditItemChance(int enemy, int item) { var enemyName = _enemyServices.GetById(enemy).Name; var enemyItem = _enemyServices .GetById(enemy) .EnemyItems .First(i => i.ItemId == item); EnemyItemWithChanceViewModel model = new EnemyItemWithChanceViewModel { EnemyId = enemy, EnemyName = enemyName, ItemId = item, ItemName = _itemServices.GetById(item).Name, Chance = enemyItem.Chance }; return(View(model)); }