public async Task <int> SyncGroups(string userid, string token)
        {
            var currentUser = HttpContext.Current.User.Identity.Name;

            // 先到clockify获取数据
            var ls = await _clockifyService.GetUserGroups(userid, token);

            var list = new List <Entities.Group>();

            var userGroups = new List <UserGroup>();

            foreach (var l in ls)
            {
                list.Add(new Entities.Group()
                {
                    Gid             = l.id,
                    Name            = l.name,
                    CompanyId       = "",
                    WorkspaceId     = l.workspaceId,
                    CreatedDate     = DateTime.Now,
                    CreatedUserID   = currentUser,
                    CreatedUserName = currentUser,
                    IsDeleted       = false,
                    UpdatedDate     = DateTime.Now,
                    UpdatedUserID   = currentUser,
                    UpdatedUserName = currentUser
                });

                foreach (var uid in l.userIds)
                {
                    userGroups.Add(new UserGroup()
                    {
                        GroupId         = l.id,
                        UserId          = uid,
                        CreatedDate     = DateTime.Now,
                        CreatedUserID   = currentUser,
                        CreatedUserName = currentUser,
                        IsDeleted       = false,
                        UpdatedDate     = DateTime.Now,
                        UpdatedUserID   = currentUser,
                        UpdatedUserName = currentUser
                    });
                }
            }

            // 然后在本地插入或者同步数据
            int affectedRecordCount = _groupService.Repository.SqlExcute("truncate table [Group]");

            affectedRecordCount = await _groupService.Repository.InsertAsync(list);

            int affectedRecordCount1 = _userGroupService.Repository.SqlExcute("truncate table [UserGroup]");

            affectedRecordCount1 = await _userGroupService.Repository.InsertAsync(userGroups);

            return(affectedRecordCount);
        }
        public async Task <int> SyncGroups(string userid, string token)
        {
            // 先到clockify获取数据
            var ls = await _clockifyService.GetUserGroups(userid, token);

            var list = new List <Group>();

            var userGroups = new List <UserGroup>();

            foreach (var l in ls)
            {
                list.Add(new Group()
                {
                    Gid             = l.id,
                    Name            = l.name,
                    CompanyId       = "",
                    WorkspaceId     = l.workspaceId,
                    CreatedDate     = DateTime.Now,
                    CreatedUserID   = userid,
                    CreatedUserName = userid,
                    IsDeleted       = false,
                    UpdatedDate     = DateTime.Now,
                    UpdatedUserID   = userid,
                    UpdatedUserName = userid
                });

                foreach (var uid in l.userIds)
                {
                    userGroups.Add(new UserGroup()
                    {
                        GroupId         = l.id,
                        UserId          = uid,
                        CreatedDate     = DateTime.Now,
                        CreatedUserID   = userid,
                        CreatedUserName = userid,
                        IsDeleted       = false,
                        UpdatedDate     = DateTime.Now,
                        UpdatedUserID   = userid,
                        UpdatedUserName = userid
                    });
                }
            }

            // 然后在本地插入或者同步数据
            await _groupService.Clear();

            var affectedRecordCount = await _groupService.AddManyAsync(list);

            await _userGroupService.Clear();

            var affectedRecordCount1 = await _userGroupService.AddManyAsync(userGroups);

            return(affectedRecordCount1);
        }