public IActionResult Create(AddGoalBindingModel bindingModel) { var goalToCreate = new Goal { GoalName = bindingModel.GoalName, /// Time = bindingModel.Time, Description = bindingModel.Description, PictureURL = "https://www.thebalancesmb.com/thmb/f3_NuKDRY2fe11yaHZ0Eh3ZebK4=/1333x1000/smart/filters:no_upscale()/smart-goal-examples-2951827_final-5b6887cc46e0fb0050aa0bc9.png", //CreatedAt = DateTime.Now }; dbContext.Goals.Add(goalToCreate); dbContext.SaveChanges(); //index returns all the cats return(RedirectToAction("Index")); }
public async Task <IHttpActionResult> Post([FromBody] AddGoalBindingModel model) { var game = await _db.Games .WithDetails() .SingleOrDefaultAsync(g => g.Id == model.GameId); if (game == null) { return(NotFound()); } var newGoal = new Goal { PlayerId = model.PlayerId, Count = model.Count }; game.Goals.Add(newGoal); await _db.SaveChangesAsync(); return(CreatedAtRoute("GetPlayerGoals", new { id = model.PlayerId }, newGoal)); }