コード例 #1
0
        public async Task <IActionResult> SyncUsers()
        {
            _people.FillDictionary();
            List <User> userdc = _people.GetAllUser();
            long        size   = userdc.Count;

            foreach (var user in userdc)
            {
                try
                {
                    if (UserExists(user.Id))
                    {
                        _context.Update(user);
                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        _context.Add(user);
                        await _context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(Ok(new { count = size, size }));
        }