示例#1
0
        public async Task<IHttpActionResult> Delete(int id) {
            var goal = new Goal { Id = id };

            _db.Goals.Attach(goal);
            _db.Goals.Remove(goal);

            await _db.SaveChangesAsync();

            return StatusCode(HttpStatusCode.NoContent);
        }
示例#2
0
        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);
        }