public async Task <IActionResult> Upgrade(UpgradeSystem selected) { UpdateAll upengine = new UpdateAll(); var Town = await _context.Towns.LastOrDefaultAsync(x => x.UserId == User.GetUserId()); var Player = await _userManager.FindByIdAsync(User.GetUserId()); UpgradeSystem buildings = new UpgradeSystem(_context, Player); buildings.BuildingPage(Town); var production = buildings.Upgrades.ElementAt(selected.UpgradeIndex); upengine.UpdateResource(Town); upengine.UpdateBuildings(Town); await _context.SaveChangesAsync(); if (ModelState.IsValid && production.Cost_Iron <= Town.TownIRON && production.Cost_Meat <= Town.TownMEAT && production.Cost_Wheat <= Town.TownWHEAT && production.Cost_Wood <= Town.TownWOOD) { Town.TownWHEAT = Town.TownWHEAT - production.Cost_Wheat; Town.TownMEAT = Town.TownMEAT - production.Cost_Meat; Town.TownIRON = Town.TownIRON - production.Cost_Iron; Town.TownWOOD = Town.TownWOOD - production.Cost_Wood; UpgradeSystem Engine = new UpgradeSystem(_context, Player); UpgradeQueue NewUpgrade = new UpgradeQueue(); NewUpgrade.BuildingINDEX = production.index; NewUpgrade.TownID = Town.TownId; NewUpgrade.ProductionTime = DateTime.Now.AddSeconds(production.Buildtime); _context.upgradeQueue.Add(NewUpgrade); await _context.SaveChangesAsync(); return(View("Buildings", buildings)); } else { await _context.SaveChangesAsync(); ModelState.AddModelError("", "Not Enough Resources"); return(View("Buildings", buildings)); } }
public async Task <IActionResult> Buildings() { var Town = await _context.Towns.LastOrDefaultAsync(x => x.UserId == User.GetUserId()); var Player = await _userManager.FindByIdAsync(User.GetUserId()); var Set = await _context.UserGameSettings.LastOrDefaultAsync(x => x.UserId == User.GetUserId()); UpgradeSystem model = new UpgradeSystem(); UpdateAll Engine = new UpdateAll(); Engine.UpdateResource(Town); Engine.UpdateBuildings(Town); model.BuildingPage(Town); await _context.SaveChangesAsync(); return(View(model)); }