コード例 #1
0
        /// <summary>
        /// 业务对象的属性转换为视图对象的属性
        /// </summary>
        /// <param name="bo"></param>
        private void _BoMapToVM(Department bo, DepartmentVM boVM)
        {
            boVM.Id          = bo.Id;
            boVM.Name        = bo.Name;
            boVM.Description = bo.Description;
            boVM.SortCode    = bo.SortCode;

            boVM.DepartmentType     = bo.DepartmentType;
            boVM.DepartmentTypeName = bo.DepartmentType.ToString();

            if (bo.ParentDepartment != null)
            {
                boVM.ParentDepartmentId   = bo.ParentDepartment.Id.ToString();
                boVM.ParentDepartmentName = bo.ParentDepartment.Name;
            }

            if (bo.Organization != null)
            {
                boVM.OrganizationId   = bo.Organization.Id.ToString();
                boVM.OrganizationName = bo.Organization.Name;
            }

            if (bo.ApplicationRole != null)
            {
                boVM.ApplicationRoleId   = bo.ApplicationRole.Id.ToString();
                boVM.ApplicationRoleName = bo.ApplicationRole.Name;
            }
        }
コード例 #2
0
        /// <summary>
        /// 将视图对象的数据,映射为业务对象数据,进行持久化处理
        /// </summary>
        /// <param name="boService"></param>
        /// <param name="gradeService"></param>
        /// <returns></returns>
        public async Task <bool> SaveBo(DepartmentVM boVM)
        {
            var bo = _boRepository.GetSingle(boVM.Id, r => r.ApplicationRole);

            if (bo == null)
            {
                bo = new Department();
            }

            await _VMMapToBo(bo, boVM);

            // 处理创建用户组
            if (boVM.IsCreateRoleAuto)
            {
                var roleFactory = new ApplicationRoleVMService(_userManager, _roleManager, _boRepository, _gradeAndClassRepository);
                var result      = await roleFactory.CreateOrEditSaveByDepeartment(bo);
            }

            var saveResult = await _boRepository.AddOrEditAndSaveAsyn(bo);

            if (saveResult)
            {
            }
            return(saveResult);
        }
コード例 #3
0
        /// <summary>
        /// 根据业务实体对象返回对应的视图模型
        /// </summary>
        /// <param name="boId"></param>
        /// <returns></returns>
        public async Task <DepartmentVM> GetVM(Department bo)
        {
            var boVM = new DepartmentVM();

            _BoMapToVM(bo, boVM);
            var collection = await _employeeRepository.GetAllAsyn(x => x.Department.Id == bo.Id);

            boVM.PersonAmount = collection.Count();
            return(boVM);
        }
コード例 #4
0
        /// <summary>
        /// 设置用于前端页面需要的关联数据选项
        /// </summary>
        public void SetRelevanceItems(DepartmentVM boVM)
        {
            boVM.DepartmentTypeItemCollection = PlainFacadeItemFactory <Department> .GetByEnum(boVM.DepartmentType);

            boVM.ParentDepartmentItemCollection = SelfReferentialItemFactory <Department> .GetCollection(_boRepository, true);

            boVM.OrganizationItemCollection = PlainFacadeItemFactory <Organ> .Get(_orgRepository);

            boVM.ApplicationRoleItemCollection = _GetApplicationRoleItemCollection(_roleManager.Roles.ToList());
        }
コード例 #5
0
        /// <summary>
        /// 根据业务实体对象 Id 返回对应的视图模型
        /// </summary>
        /// <param name="boId"></param>
        /// <returns></returns>
        public DepartmentVM GetVM(Guid id)
        {
            var boVM = new DepartmentVM();
            // 初始化数据对象
            var bo = _boRepository.GetSingle(id, x => x.ParentDepartment, y => y.Organization, z => z.ApplicationRole);

            if (bo == null)
            {
                bo         = new Department();
                boVM.IsNew = true;
            }
            else
            {
                boVM.IsNew = false;
            }

            // 映射基本的属性值
            _BoMapToVM(bo, boVM);

            // 设置供前端下拉选项所需要的数据集合
            SetRelevanceItems(boVM);

            return(boVM);
        }
コード例 #6
0
        /// <summary>
        /// 视图对象的属性转换为业务对象的属性
        /// </summary>
        /// <param name="bo"></param>
        private async Task _VMMapToBo(Department bo, DepartmentVM boVM)
        {
            bo.Id          = boVM.Id;
            bo.Name        = boVM.Name;
            bo.Description = boVM.Description;
            bo.SortCode    = boVM.SortCode;

            if (!String.IsNullOrEmpty(boVM.ParentDepartmentId))
            {
                bo.ParentDepartment = await _boRepository.GetSingleAsyn(Guid.Parse(boVM.ParentDepartmentId));
            }
            else
            {
                bo.ParentDepartment = bo;
            }
            if (!String.IsNullOrEmpty(boVM.OrganizationId))
            {
                bo.Organization = await _orgRepository.GetSingleAsyn(Guid.Parse(boVM.OrganizationId));
            }
            if (!String.IsNullOrEmpty(boVM.ApplicationRoleId))
            {
                bo.ApplicationRole = await _roleManager.FindByIdAsync(boVM.ApplicationRoleId.ToString());
            }
        }