Esempio n. 1
0
        public IActionResult Edit(int id)
        {
            var toEdit     = _context.Players.Single(r => r.ID == id);
            var editRookie = new PlayerAttributeViewModel
            {
                PlayerName  = toEdit.PlayerName,
                Position    = toEdit.Position,
                Age         = toEdit.Age,
                Height      = toEdit.Height,
                Weight      = toEdit.Weight,
                Development = toEdit.Development,
                OVR         = toEdit.OVR,
                SPD         = toEdit.SPD,
                ACC         = toEdit.ACC,
                STR         = toEdit.STR,
                AGI         = toEdit.AGI,
                ELU         = toEdit.ELU,
                BCV         = toEdit.BCV,
                CAR         = toEdit.CAR,
                JKM         = toEdit.JKM,
                SPM         = toEdit.SPM,
                SFA         = toEdit.SFA,
                TRK         = toEdit.TRK,
                CTH         = toEdit.CTH,
                CIT         = toEdit.CIT,
                SPC         = toEdit.SPC,
                RTE         = toEdit.RTE,
                RLS         = toEdit.RLS,
                JMP         = toEdit.JMP,
                THP         = toEdit.THP,
                SAC         = toEdit.SAC,
                MAC         = toEdit.MAC,
                DAC         = toEdit.DAC,
                RUN         = toEdit.RUN,
                PAC         = toEdit.PAC,
                RBK         = toEdit.RBK,
                PBK         = toEdit.PBK,
                IBL         = toEdit.IBL,
                TAK         = toEdit.TAK,
                POW         = toEdit.POW,
                BSH         = toEdit.BSH,
                FMV         = toEdit.FMV,
                PMV         = toEdit.PMV,
                MCV         = toEdit.MCV,
                ZCV         = toEdit.ZCV,
                PRS         = toEdit.PRS,
                PRC         = toEdit.PRC,
                PUR         = toEdit.PUR
            };

            return(View(editRookie));
        }
Esempio n. 2
0
        public IActionResult AddPlayer(PlayerAttributeViewModel player)
        {
            if (_context.Players.Any(p => p.PlayerName == player.PlayerName && p.Position == player.Position))
            {
                //Player name and position already exists
                //since you're checking the combination of the two
                //you can still use ivalidatableobject in the future when you get back to this
                ModelState.AddModelError(nameof(Player.PlayerName), "Player name already exists");
            }

            if (ModelState.IsValid)
            {
                var toCreate = new Player
                {
                    PlayerName  = player.PlayerName,
                    Position    = player.Position,
                    Age         = player.Age,
                    Height      = player.Height,
                    Weight      = player.Weight,
                    Development = player.Development,
                    OVR         = player.OVR,
                    SPD         = player.SPD,
                    ACC         = player.ACC,
                    STR         = player.STR,
                    AGI         = player.AGI,
                    ELU         = player.ELU,
                    BCV         = player.BCV,
                    CAR         = player.CAR,
                    JKM         = player.JKM,
                    SPM         = player.SPM,
                    SFA         = player.SFA,
                    TRK         = player.TRK,
                    CTH         = player.CTH,
                    CIT         = player.CIT,
                    SPC         = player.SPC,
                    RTE         = player.RTE,
                    RLS         = player.RLS,
                    JMP         = player.JMP,
                    THP         = player.THP,
                    SAC         = player.SAC,
                    MAC         = player.MAC,
                    DAC         = player.DAC,
                    RUN         = player.RUN,
                    PAC         = player.PAC,
                    RBK         = player.RBK,
                    PBK         = player.PBK,
                    IBL         = player.IBL,
                    TAK         = player.TAK,
                    POW         = player.POW,
                    BSH         = player.BSH,
                    FMV         = player.FMV,
                    PMV         = player.PMV,
                    MCV         = player.MCV,
                    ZCV         = player.ZCV,
                    PRS         = player.PRS,
                    PRC         = player.PRC,
                    PUR         = player.PUR
                };

                //it's usually a best practice to name your dbsets plural. Note: I mean dbset, not model. The model should be named Player, dbset: Players
                _context.Players.Add(toCreate);
                _context.SaveChanges();


                //redirecttoaction causes you to lose any modelstate validation errors. you just need to return the view
                return(RedirectToAction("Position", new { position = player.Position }));
                //return Json(toCreate);
            }
            return(View());
        }