public async Task <IActionResult> ListInternal()
        {
            var roles = await _roleTitleService.GetAllInternalRoles();

            return(new JsonResult(new
            {
                code = 200,
                Message = $"success, {roles.Count()} records.",
                data = roles
            }));
        }
        private async Task <List <EffortUsedByRoleByDate> > CalculateACByDateByRole(string projectGid, string taskGid, DateTime date, List <TimeEntryWithRoleViewModel> timeEntriesByTask)
        {
            // 取出所有的role
            var roles = await _roleTitleService.GetAllInternalRoles();

            var acByRoles = new List <EffortUsedByRoleByDate>();
            //foreach (var role in roles)
            //{
            //    acByRoles.Add(new EffortUsedAccountingViewModel()
            //    {
            //        RoleId = role.Id,
            //        TotalHours = 0,
            //        TotalHoursRate = 0,
            //        RoleName = role.Title,
            //        RoleRate = role.Rate
            //    });
            //}

            var timeEntriesByRole = timeEntriesByTask.Where(a => a.Date.Date == date.Date).GroupBy(a => a.RoleId);

            foreach (var r in timeEntriesByRole)
            {
                var roleId = r.Key;
                var role   = roles.FirstOrDefault(a => a.Id == roleId);
                if (role == null)
                {
                    role = new RoleTitle()
                    {
                        Id         = 0,
                        Rate       = 100,
                        Title      = "Default Title",
                        Category   = "Others Category",
                        ShortTitle = "Default",
                        Type       = "internal",
                        Sort       = 1000
                    };
                }
                var totalHours     = r.Sum(a => a.TotalHours);
                var totalHoursRate = totalHours * role.Rate;

                var acRole = acByRoles.FirstOrDefault(a => a.RoleId == roleId);
                if (acRole == null)
                {
                    acRole = new EffortUsedByRoleByDate()
                    {
                        RoleId         = role.Id,
                        TotalHours     = 0,
                        TotalHoursRate = 0,
                        RoleName       = role.Title,
                        RoleRate       = role.Rate,
                        Date           = date,
                        ProjectGid     = projectGid,
                        TaskGid        = taskGid,
                        RoleCategory   = role.Category,
                        RoleShortTitle = role.ShortTitle
                    };
                    acByRoles.Add(acRole);
                }
                acRole.TotalHours     = totalHours;
                acRole.TotalHoursRate = totalHoursRate;
            }

            return(acByRoles);
        }