Esempio n. 1
0
        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));
        }
        public async Task <bool> Create(Wallet wallet)
        {
            WalletDAO walletDAO = await wASContext.Wallet.Where(w => w.Id == wallet.Id).FirstOrDefaultAsync();

            if (walletDAO == null)
            {
                walletDAO = new WalletDAO()
                {
                    Id      = wallet.Id,
                    Name    = wallet.Name,
                    Balance = wallet.Balance,
                    UserId  = wallet.UserId
                };
                await wASContext.Wallet.AddAsync(walletDAO);
            }
            else
            {
                walletDAO.Name    = wallet.Name;
                walletDAO.Balance = wallet.Balance;
                walletDAO.UserId  = wallet.UserId;
            }
            await wASContext.SaveChangesAsync();

            return(true);
        }
        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 async Task <Wallet> Get(WalletFilter filter)
        {
            IQueryable <WalletDAO> wallets = wASContext.Wallet.AsNoTracking();
            WalletDAO walletDAO            = DynamicFilter(wallets, filter).FirstOrDefault();

            return(new Wallet()
            {
                Id = walletDAO.Id,
                Name = walletDAO.Name,
                Balance = walletDAO.Balance,
                UserId = walletDAO.UserId
            });
        }
        public async Task <Wallet> Get(Guid Id)
        {
            WalletDAO walletDAO = wASContext.Wallet
                                  .Where(w => w.Id.Equals(Id))
                                  .AsNoTracking()
                                  .FirstOrDefault();

            return(new Wallet()
            {
                Id = walletDAO.Id,
                Name = walletDAO.Name,
                Balance = walletDAO.Balance,
                UserId = walletDAO.UserId
            });
        }
        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 async Task <bool> Delete(Guid Id)
        {
            try
            {
                await wASContext.Transaction
                .Where(t => t.WalletId.Equals(Id))
                .AsNoTracking()
                .DeleteFromQueryAsync();

                WalletDAO walletDAO = wASContext.Wallet
                                      .Where(w => w.Id.Equals(Id))
                                      .AsNoTracking()
                                      .FirstOrDefault();
                wASContext.Wallet.Remove(walletDAO);
                await wASContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        private ActionResult ViewWithMaxBet()
        {
            var user   = HttpContext.User.Identity as ClaimsIdentity;
            var userId = user.GetUserId();

            using (var anacondaModel = new AnacondaModel())
            {
                WalletDAO walletDAO = new WalletDAO(anacondaModel);
                if (walletDAO.HasWallet(userId))
                {
                    Wallet wallet = walletDAO.GetWallet(userId);
                    ViewBag.MaxBet = wallet.Credits + wallet.CasinoCredits;
                }
                else
                {
                    ViewBag.MaxBet = int.MaxValue;
                }
            }

            return(View(new GameResult()
            {
                Bet = 100
            }));
        }