Esempio n. 1
0
        public ActionResult New(PlayerStatPlayerViewModel pspViewModel)
        {
            ViewBag.DivisionList = GetAllDivisions();
            try
            {
                if (ModelState.IsValid)
                {
                    PlayerStat playerStat = new PlayerStat
                    {
                        NrWins   = pspViewModel.NrWins,
                        NrLosses = pspViewModel.NrLosses,
                        UserId   = pspViewModel.UserId
                    };
                    db.PlayersStat.Add(playerStat);

                    Player player = new Player {
                        Name       = pspViewModel.Name,
                        PlayerStat = playerStat,
                        DivisionId = pspViewModel.DivisionId,
                        UserId     = pspViewModel.UserId
                    };
                    db.Players.Add(player);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View(pspViewModel));
            }
            catch (Exception e)
            {
                var msg = e.Message;
                return(View(pspViewModel));
            }
        }
Esempio n. 2
0
        public ActionResult Edit(int?id)
        {
            ViewBag.DivisionList = GetAllDivisions();
            if (id.HasValue)
            {
                Models.Player player     = db.Players.Find(id);
                PlayerStat    playerStat = db.PlayersStat.Find(player.PlayerStat.PlayerStatId);

                if (player == null)
                {
                    return(HttpNotFound("Coludn't find the player with id " + id.ToString() + "!"));
                }

                if (User.IsInRole("Player"))
                {
                    if (User.Identity.GetUserId() != player.UserId)
                    {
                        return(new HttpUnauthorizedResult("Unauthorized acces!"));
                    }
                }
                PlayerStatPlayerViewModel pspViewModel = new PlayerStatPlayerViewModel {
                    Name       = player.Name,
                    NrWins     = playerStat.NrWins,
                    NrLosses   = playerStat.NrLosses,
                    DivisionId = player.DivisionId,
                };

                return(View(pspViewModel));
            }
            return(HttpNotFound("Missing player id parameter!"));
        }
Esempio n. 3
0
        public ActionResult New()
        {
            PlayerStatPlayerViewModel psp = new PlayerStatPlayerViewModel();

            psp.UserId           = User.Identity.GetUserId();
            ViewBag.DivisionList = GetAllDivisions();
            return(View(psp));
        }