public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); using (var am = new AnacondaModel()) { var walletDao = new WalletDAO(am); walletDao.CreateWallet(user.Id); am.SaveChanges(); } return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
// GET: Credit public ActionResult Index() { using (var am = new AnacondaModel()) { var user = HttpContext.User.Identity as ClaimsIdentity; var userId = user.GetUserId(); bool hasWallet = am.Wallets.Any(x => x.UserId.Equals(userId)); Wallet wallet; if (!hasWallet) { var aspUser = am.AspNetUsers.First(u => u.Id.Equals(userId)); wallet = new Wallet() { AspNetUser = aspUser, CasinoCredits = 100, Credits = 0, UserId = userId }; am.Wallets.Add(wallet); am.SaveChanges(); } wallet = am.Wallets.First(x => x.UserId.Equals(userId)); return(View(wallet)); } }
public ActionResult SlotMachineSimple(FormCollection collection) { int bet = collection["Bet"].AsInt(); GameResult result = new GameResult(); List <SlotItem>[] slotColumns = new List <SlotItem>[] { new List <SlotItem>(), new List <SlotItem>(), new List <SlotItem>() }; RandomColumns rc = new RandomColumns(); Random rand = new Random(); for (int i = 0; i < 3; i++) { slotColumns[i] = rc.GetRandomColumnFruit(rand); } ViewBag.Column1Row1 = slotColumns[0][0].DisplayName; ViewBag.Column1Row2 = slotColumns[0][1].DisplayName; ViewBag.Column1Row3 = slotColumns[0][2].DisplayName; ViewBag.Column2Row1 = slotColumns[1][0].DisplayName; ViewBag.Column2Row2 = slotColumns[1][1].DisplayName; ViewBag.Column2Row3 = slotColumns[1][2].DisplayName; ViewBag.Column3Row1 = slotColumns[2][0].DisplayName; ViewBag.Column3Row2 = slotColumns[2][1].DisplayName; ViewBag.Column3Row3 = slotColumns[2][2].DisplayName; var user = HttpContext.User.Identity as ClaimsIdentity; var userId = user.GetUserId(); CheckRows cr = new CheckRows(); using (var anacondaModel = new AnacondaModel()) { WalletDAO walletDAO = new WalletDAO(anacondaModel); if (walletDAO.Pay(userId, bet)) { result = cr.WinResult(slotColumns, new GameContext(bet)); } else { result = new GameResult() { Bet = bet, CreditsGained = 0, Status = ResultStatus.InsufficientCredits }; } var wallet = anacondaModel.Wallets.First(u => u.UserId == userId); wallet.Credits += result.CreditsGained; anacondaModel.SaveChanges(); } ViewBag.Bet = bet; return(View(result)); }
public ActionResult WheelOfFortune(FormCollection collection) { int bet = collection["Bet"].AsInt(); GameResult result = new GameResult(); var items = new List <RandomItem <ISpinAction> > { new RandomItem <ISpinAction>(0.6, new BetMultiplier(0.5m)), new RandomItem <ISpinAction>(0.2, new BetMultiplier(1.1m)), new RandomItem <ISpinAction>(0.1, new BetMultiplier(0m)), new RandomItem <ISpinAction>(0.1 / 3, new BetMultiplier(1.5m)), new RandomItem <ISpinAction>(0.1 / 3, new BetMultiplier(2m)), new RandomItem <ISpinAction>(0.1 / 3, new BetMultiplier(3m)) }; Random rand = new Random(); var rp = new RandomPicker <ISpinAction>(items, rand.Next()); //TODO: rand.next gives the same order for each player, would be better to have a different order for each player var user = HttpContext.User.Identity as ClaimsIdentity; var userId = user.GetUserId(); using (var anacondaModel = new AnacondaModel()) { WalletDAO walletDAO = new WalletDAO(anacondaModel); if (walletDAO.Pay(userId, bet)) { result = rp.Pick().Item.Execute(new GameContext(bet)); } else { result = new GameResult() { Bet = bet, CreditsGained = 0, Status = ResultStatus.InsufficientCredits }; } var wallet = anacondaModel.Wallets.First(u => u.UserId == userId); wallet.Credits += result.CreditsGained; anacondaModel.SaveChanges(); } ViewBag.Bet = bet; return(View(result)); }
public ActionResult AddCredits(FormCollection form) { var creditsToAdd = form["creditsToAdd"].AsInt(); var user = HttpContext.User.Identity as ClaimsIdentity; var userId = user.GetUserId(); Wallet wal = null; using (var am = new AnacondaModel()) { wal = am.Wallets.First(w => w.UserId == userId); wal.Credits += creditsToAdd; am.SaveChanges(); } return(RedirectToAction("Index")); }