public IActionResult Index() { var vm = new BankActionModel(); vm.Message = ""; return(View(vm)); }
public IActionResult Index(string button, int accountId, int amount) { var vm = new BankActionModel(); var customer = BankRepository.Customers.FirstOrDefault(c => c.Account.Select(a => a.AccountID == accountId).First()); if (customer != null) { var balance = customer.Account.FirstOrDefault(a => a.AccountID == accountId).Cash; if (button == "Withdraw") { if (amount > balance) { vm.Message = "Du försöker ta ut mer än du har !"; return(View(vm)); } _bankRepository.Withdraw(amount, accountId); vm.Message = "Du lyckades ta ut " + amount + " Du har " + customer.Account.FirstOrDefault(a => a.AccountID == accountId).Cash; } else if (button == "Deposit") { _bankRepository.Deposit(amount, accountId); vm.Message = "Du satte in " + amount + " Du har : " + customer.Account.FirstOrDefault(a => a.AccountID == accountId).Cash; } } else { vm.Message = "Fel konto nummer!"; } return(View(vm)); }
public async Task <PathModel> GetPathByKey(pathKey key) { string userId = User.Claims.First(c => c.Type == "UserID").Value; var user = await _userManager.FindByIdAsync(userId); TrajetDB trajet = _paths.FirstOrDefault(o => o.Key == key.Key); PathModel pathToSend = new PathModel() { Name = trajet.Name, Type = trajet.Type, GroupLevelMax = trajet.GroupLevelMax, GroupLevelMin = trajet.GroupLevelMin, CaptureItem = trajet.CaptureItem, MaxPod = trajet.MaxPod, MonsterQuantityMin = trajet.MonsterQuantityMin, MonsterQuantityMax = trajet.MonsterQuantityMax, ListRessource = trajet.ListRessource, LeaderBank = trajet.LeaderBank, IsCapture = trajet.IsCapture, Key = trajet.Key.ToString() }; pathToSend.PathAction = new List <PathActionModel>(); foreach (var item in trajet.PathAction) { PathActionModel pathactionmodelToAdd = new PathActionModel(); pathactionmodelToAdd.MapPos = Database.Maps.Find(o => o.Key == item.MapId).First().Coordinate.Replace(',', ';').Replace("[", "").Replace("]", ""); pathactionmodelToAdd.Actions = new List <MapActionModel>(); foreach (var action in item.Actions) { MapActionModel mapaction = new MapActionModel() { Order = action.Order }; if (action is FightAction) { FightActionModel fight = new FightActionModel() { IsAlone = ((FightAction)action).IsAlone }; mapaction.FightAction = fight; } else if (action is BankAction) { BankActionModel bank = new BankActionModel() { MapId = item.MapId }; mapaction.BankAction = bank; } else if (action is GatherAction) { GatherActionModel gather = new GatherActionModel() { }; mapaction.GatherAction = gather; } else if (action is InteractionAction) { InteractionActionModel interaction = new InteractionActionModel() { InteractiveidObject = ((InteractionAction)action).InteractiveIdObject, InteractiveIdResponse = ((InteractionAction)action).InteractiveIdResponse, ToBackBank = ((InteractionAction)action).ToBackBank, ToGoBank = ((InteractionAction)action).ToGoBank }; mapaction.InteractionAction = interaction; } else if (action is MoveAction) { MoveActionModel move = null; if (((MoveAction)action).Direction != null) { move = new MoveActionModel() { Cellid = ((MoveAction)action).CellId, ToGoBank = ((MoveAction)action).ToGoBank, ToBackBank = ((MoveAction)action).ToBackBank, Direction = ((MoveAction)action).Direction.ConvertAll(o => o.ToString()), MapId = ((MoveAction)action).MapId }; } else { move = new MoveActionModel() { Cellid = ((MoveAction)action).CellId, ToGoBank = ((MoveAction)action).ToGoBank, ToBackBank = ((MoveAction)action).ToBackBank, Direction = null, MapId = ((MoveAction)action).MapId }; } mapaction.moveAction = move; } else if (action is UseItemAction) { UseItemActionModel useitem = new UseItemActionModel() { ToBackBank = ((UseItemAction)action).ToBackBank, ItemId = ((UseItemAction)action).ItemId, ToGoBank = ((UseItemAction)action).ToGoBank }; mapaction.UseItemAction = useitem; } else if (action is ZaapAction) { ZaapActionModel zaap = new ZaapActionModel() { ToGoBank = ((ZaapAction)action).ToGoBank, ToBackBank = ((ZaapAction)action).ToBackBank, Destination = Database.Maps.Find(o => o.Key == ((ZaapAction)action).Destination).First().Coordinate.Replace(',', ';').Replace("[", "").Replace("]", ""), ZaapId = ((ZaapAction)action).ZaapId }; mapaction.ZaapAction = zaap; } else if (action is ZaapiAction) { ZaapiActionModel zaapi = new ZaapiActionModel() { ToGoBank = ((ZaapAction)action).ToGoBank, ToBackBank = ((ZaapAction)action).ToBackBank, Destination = Database.Maps.Find(o => o.Key == ((ZaapAction)action).Destination).First().Coordinate.Replace(',', ';').Replace("[", "").Replace("]", ""), ZaapiId = ((ZaapAction)action).ZaapId }; mapaction.ZaapiAction = zaapi; } pathactionmodelToAdd.Actions.Add(mapaction); } ; pathToSend.PathAction.Add(pathactionmodelToAdd); } ; return(pathToSend); }