Exemplo n.º 1
0
 private void SetParttimeJobs(EmployeeOutput s, EmployeeDetailVm d)
 {
     d.ParttimeJobs = new List <ParttimeJobListVm>();
     foreach (var posId in s.ParttimePositionIds)
     {
         if (_positionListCache.ContainsKey(posId))
         {
             var pos = _positionListCache[posId];
             var vm  = new ParttimeJobListVm();
             vm.PositionName    = pos.Name;
             vm.DepartmentNames = new List <string>();
             //最多设置两级部门名称
             if (_departmentListCache.ContainsKey(pos.DepartmentId))
             {
                 var dep = _departmentListCache[pos.DepartmentId];
                 vm.DepartmentNames.Add(dep.Name);
                 if (dep.ParentId.HasValue && _departmentListCache.ContainsKey(dep.ParentId.Value))
                 {
                     vm.DepartmentNames.Add(_departmentListCache[dep.ParentId.Value].Name);
                 }
             }
             d.ParttimeJobs.Add(vm);
         }
     }
 }
Exemplo n.º 2
0
 //返回完整层级
 private void SetDepartmentNames(EmployeeOutput s, EmployeeDetailVm d)
 {
     d.DepartmentNames = new List <string>();
     if (_departmentListCache.ContainsKey(s.PrimaryDepartmentId))
     {
         var item = _departmentListCache[s.PrimaryDepartmentId];
         d.DepartmentNames.Add(item.Name);
         while (item.ParentId.HasValue && _departmentListCache.ContainsKey(item.ParentId.Value))
         {
             var sub = _departmentListCache[item.ParentId.Value];
             d.DepartmentNames.Add(sub.Name);
             item = sub;
         }
     }
 }
Exemplo n.º 3
0
        public async Task Test_GetById_GetByUserId()
        {
            var dep0 = new DepartmentListOutput
            {
                Id   = Guid.NewGuid(),
                Name = "sclq",
            };
            var dep1 = new DepartmentListOutput
            {
                Id       = Guid.NewGuid(),
                Name     = "sclq-jt",
                ParentId = dep0.Id,
            };
            var dep2 = new DepartmentListOutput
            {
                Id       = Guid.NewGuid(),
                Name     = "sclq-gs",
                ParentId = dep0.Id,
            };
            var pos1 = new PositionListOutput
            {
                Id           = Guid.NewGuid(),
                Name         = "pos1",
                DepartmentId = dep1.Id,
            };
            var pos2 = new PositionListOutput
            {
                Id           = Guid.NewGuid(),
                Name         = "pos2",
                DepartmentId = dep2.Id,
            };
            var emp0 = new EmployeeOutput
            {
                Id     = Guid.NewGuid(),
                UserId = Guid.NewGuid(),
                Name   = "aaa",
                PrimaryDepartmentId = dep1.Id,
                PrimaryPositionId   = pos1.Id,
                ParttimePositionIds = new List <Guid> {
                    pos2.Id
                },
            };

            var departmentAppService = Substitute.For <IDepartmentAppService>();

            departmentAppService.GetAllListAsync()
            .Returns(Task.FromResult((new[] { dep0, dep1, dep2 }).ToList()));

            var positionAppService = Substitute.For <IPositionAppService>();

            positionAppService.GetAllListAsync()
            .Returns(Task.FromResult((new[] { pos1, pos2 }).ToList()));

            var employeeAppService = Substitute.For <IEmployeeAppService>();

            employeeAppService.GetByIdAsync(emp0.Id)
            .Returns(Task.FromResult(emp0));
            employeeAppService.GetByUserIdAsync(emp0.UserId.Value)
            .Returns(Task.FromResult(emp0));

            var groupAppService = Substitute.For <IGroupAppService>();

            groupAppService.CheckSameWhiteListGroupAsync(User_EmployeeMdmId, emp0.Id)
            .Returns(Task.FromResult(true));

            var userFavoriteAppService = Substitute.For <IUserFavoriteAppService>();

            userFavoriteAppService.IsFavoritedAsync(User_Id, emp0.Id)
            .Returns(Task.FromResult(true));

            var userSettingAppService = Substitute.For <IUserSettingAppService>();

            userSettingAppService.GetInfoVisibilityAsync(emp0.UserId.Value)
            .Returns(Task.FromResult(new InfoVisibility {
                Mobile = false
            }));

            var target = new EmployeeController(
                CreateMemoryCache(),
                CreateMapper(),
                departmentAppService,
                positionAppService,
                employeeAppService,
                groupAppService,
                _ => userFavoriteAppService,
                _ => userSettingAppService
                );

            target.ControllerContext = CreateMockContext();

            var result = await target.GetById(emp0.Id);

            var data = result.Value;

            data.SameWhiteListGroup.Should().BeTrue();
            data.IsFavorited.Should().BeTrue();
            data.Name.Should().Be(emp0.Name);
            data.Mobile.Should().Be("***");
            data.PositionName.Should().Be(pos1.Name);

            data.DepartmentNames.Count.Should().Be(2);
            data.DepartmentNames[0].Should().Be(dep1.Name);

            data.ParttimeJobs.Count.Should().Be(1);
            data.ParttimeJobs[0].PositionName.Should().Be(pos2.Name);
            data.ParttimeJobs[0].DepartmentNames.Count.Should().Be(2);
            data.ParttimeJobs[0].DepartmentNames[0].Should().Be(dep2.Name);

            result = await target.GetByUserId(emp0.UserId.Value);

            data = result.Value;
            data.Should().NotBeNull();
        }