//build out our crud //start with create public IHttpActionResult Post(YardGameCreate yardGame) { //start by checking validity of the model state if (!ModelState.IsValid) { return(BadRequest(ModelState)); }//end of if model is not valid //create a service instance var service = new YardGameService(); //now that the service exists, return an error if we can't create the yardGame if (!service.CreateYardGame(yardGame)) { return(InternalServerError()); }//end of if doesnt save //to get here it had to work soo return(Ok()); }//end of method Post
//start with our create method public bool CreateYardGame(YardGameCreate model) { var entity = new YardGame()//Creating an instance of a new YardGame { GameName = model.GameName, AgeRating = model.AgeRating, MaxNumberOfPlayers = model.MaxNumberOfPlayers, MinNumberOfPlayers = model.MinNumberOfPlayers, PublishYear = model.PublishYear, TeamGame = model.TeamGame, SurfaceType = model.SurfaceType, BallGame = model.BallGame, AreaOfPlayInFt = model.AreaOfPlayInFt, Genre = model.Genre, StorageId = model.StorageId, }; using (var ctx = new ApplicationDbContext())//create DbContext to add an entity { ctx.YardGames.Add(entity); return(ctx.SaveChanges() == 1); } }//end of method CreateYardGame