예제 #1
0
        public async Task <IActionResult> PutPerson(int id, Person person)
        {
            if (id != person.Id)
            {
                return(BadRequest());
            }

            _context.Entry(person).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PersonExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        public async Task <ActionResult <IEnumerable <Team> > > GetTeams()
        {
            var teams = await _context.Teams.ToListAsync();

            foreach (var team in teams)
            {
                var teamDetails = _context.Entry(team)
                                  .Collection(m => m.People)
                                  .Query()
                                  .ToList();
                team.People      = teamDetails;
                team.PeopleCount = teamDetails.Count();
            }
            await _context.SaveChangesAsync();

            return(teams);
        }