コード例 #1
0
        public IHttpActionResult Post(SeasonStatCreate season)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            SeasonStatService service = new SeasonStatService();

            if (!service.CreateSeason(season))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
コード例 #2
0
        //CREATE
        public bool CreateSeason(SeasonStatCreate season)
        {
            var playerSeason = new SeasonStat()
            {
                PlayerId          = season.PlayerId,
                Year              = season.Year,
                PassingYards      = season.PassingYards,
                RushingYards      = season.RushingYards,
                Completions       = season.Completions,
                Attempts          = season.Attempts,
                PassingTouchdowns = season.PassingTouchdowns,
                RushingTouchdowns = season.RushingTouchdowns,
                Interceptions     = season.Interceptions,
                PlayerNumber      = season.PlayerNumber,
                Team              = season.Team
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.SeasonStat.Add(playerSeason);
                return(ctx.SaveChanges() == 1);
            }
        }