コード例 #1
0
        public ActionResult Create()
        {
            try
            {
                User user = (User)Session["User"];
                CoinflipViewModel coinflipViewModel = new CoinflipViewModel();

                coinflipViewModel.Inventory    = skinRepository.GetAllFromInv(user, true);
                coinflipViewModel.OrderedSkins = coinflipViewModel.ChunkBy(coinflipViewModel.Inventory.Skins, 16);
                Session["CVM"] = coinflipViewModel;
                return(View(coinflipViewModel));
            }
            catch
            {
                return(RedirectToAction("Index", "Account"));
            }
        }
コード例 #2
0
        public ActionResult Join()
        {
            try
            {
                User user = (User)Session["User"];
                CoinflipViewModel coinflipViewModel = new CoinflipViewModel();

                coinflipViewModel.Inventory    = skinRepository.GetAllFromInv(user, true);
                coinflipViewModel.OrderedSkins = coinflipViewModel.ChunkBy(coinflipViewModel.Inventory.Skins, 16);
                Session["CVM"] = coinflipViewModel;
                if (coinflipRepository.PotentialJoin((Coinflip)Session["Coinflip"]))
                {
                    return(View(coinflipViewModel));
                }
                else
                {
                    return(RedirectToAction("Error", "Coinflip", "Something went wrong when joining the coinflip."));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Account"));
            }
        }
コード例 #3
0
        public ActionResult Create(CoinflipViewModel coinflipViewModel)
        {
            CoinflipViewModel sessioncoinflipViewModel = (CoinflipViewModel)Session["CVM"];

            sessioncoinflipViewModel.SelectedSkins = coinflipViewModel.SelectedSkins;


            foreach (Skin skin in sessioncoinflipViewModel.OrderedSkins[sessioncoinflipViewModel.Index])
            {
                if (sessioncoinflipViewModel.SelectedSkins.Contains(skin.ID))
                {
                    if (sessioncoinflipViewModel.FinalSkinList.Contains(skin))
                    {
                    }
                    else
                    {
                        sessioncoinflipViewModel.FinalSkinList.Add(skin);
                    }
                }
                else
                {
                    if (sessioncoinflipViewModel.FinalSkinList.Contains(skin))
                    {
                        sessioncoinflipViewModel.FinalSkinList.Remove(skin);
                    }
                }
            }

            if (Request.Form["Next"] != null)
            {
                sessioncoinflipViewModel.Index++;
            }
            else if (Request.Form["Previous"] != null)
            {
                sessioncoinflipViewModel.Index--;
            }
            else if (Request.Form["Submit"] != null)
            {
                if (sessioncoinflipViewModel.FinalSkinList.Count > 0)
                {
                    Session["CoinflipCreateList"] = sessioncoinflipViewModel.FinalSkinList;
                }
                else
                {
                    return(RedirectToAction("Error", "Coinflip", "You did not select any skins to create a coinflip with."));
                }
                return(RedirectToAction("ConfirmCreate"));
            }
            else
            {
                return(View("Index", "Home"));
            }

            sessioncoinflipViewModel.SelectedSkins = new List <int>();

            int x = 0;

            foreach (Skin skin in sessioncoinflipViewModel.OrderedSkins[sessioncoinflipViewModel.Index])
            {
                if (sessioncoinflipViewModel.FinalSkinList.Any(m => m.ID == skin.ID))
                {
                    sessioncoinflipViewModel.SelectedSkins.Add(skin.ID);
                }
                else
                {
                    sessioncoinflipViewModel.SelectedSkins.Add(0);
                }
                x++;
            }


            Session["CVM"] = sessioncoinflipViewModel;
            return(View("Create", sessioncoinflipViewModel));
        }
コード例 #4
0
        public ActionResult Join(CoinflipViewModel coinflipViewModel)
        {
            CoinflipViewModel sessioncoinflipViewModel = (CoinflipViewModel)Session["CVM"];

            sessioncoinflipViewModel.SelectedSkins = coinflipViewModel.SelectedSkins;
            sessioncoinflipViewModel.ErrorMessage  = null;

            foreach (Skin skin in sessioncoinflipViewModel.OrderedSkins[sessioncoinflipViewModel.Index])
            {
                if (sessioncoinflipViewModel.SelectedSkins.Contains(skin.ID))
                {
                    if (sessioncoinflipViewModel.FinalSkinList.Contains(skin))
                    {
                    }
                    else
                    {
                        sessioncoinflipViewModel.FinalSkinList.Add(skin);
                    }
                }
                else
                {
                    if (sessioncoinflipViewModel.FinalSkinList.Contains(skin))
                    {
                        sessioncoinflipViewModel.FinalSkinList.Remove(skin);
                    }
                }
            }

            if (Request.Form["Next"] != null)
            {
                sessioncoinflipViewModel.Index++;
            }
            else if (Request.Form["Previous"] != null)
            {
                sessioncoinflipViewModel.Index--;
            }
            else if (Request.Form["Submit"] != null)
            {
                Coinflip coinflip = (Coinflip)Session["Coinflip"];
                if (sessioncoinflipViewModel.GetFinalSkinListPrice() >= coinflip.getBetPrice(0) * 0.95M)
                {
                    if (sessioncoinflipViewModel.GetFinalSkinListPrice() <= coinflip.getBetPrice(0) * 1.05M)
                    {
                        Session["CoinflipJoinList"] = sessioncoinflipViewModel.FinalSkinList;
                        return(RedirectToAction("ConfirmJoin"));
                    }
                    else
                    {
                        sessioncoinflipViewModel.ErrorMessage = "The total price of your selected skins ($" + sessioncoinflipViewModel.GetFinalSkinListPrice() +
                                                                ") was too high to meet the required maximal price of $" + (coinflip.getBetPrice(0) * 1.05M);
                    }
                }
                else
                {
                    sessioncoinflipViewModel.ErrorMessage = "The total price of your selected skins ($" + sessioncoinflipViewModel.GetFinalSkinListPrice() +
                                                            ") was too low to meet the required minimal price of $" + (coinflip.getBetPrice(0) * 0.95M);
                }
            }
            else
            {
                return(View("Index", "Home"));
            }

            sessioncoinflipViewModel.SelectedSkins = new List <int>();

            int x = 0;

            foreach (Skin skin in sessioncoinflipViewModel.OrderedSkins[sessioncoinflipViewModel.Index])
            {
                if (sessioncoinflipViewModel.FinalSkinList.Any(m => m.ID == skin.ID))
                {
                    sessioncoinflipViewModel.SelectedSkins.Add(skin.ID);
                }
                else
                {
                    sessioncoinflipViewModel.SelectedSkins.Add(0);
                }
                x++;
            }


            Session["CVM"] = sessioncoinflipViewModel;
            return(View(sessioncoinflipViewModel));
        }
コード例 #5
0
        // GET: Coinflip
        public ActionResult Index()
        {
            CoinflipViewModel coinflipViewModel = new CoinflipViewModel(coinflipRepository.GetAll());

            return(View(coinflipViewModel));
        }