Exemplo n.º 1
0
        public void AddOrganizationHierarchy(Organization parent,Organization child,OrganizationHierarchyType organizationHierarchyType)
        {
            Guard.Against<ArgumentNullException>(_organizationHierarchyRepository == null, "建構式需指定repository");

            OrganizationHierarchy organizationHierarchy =
                new OrganizationHierarchy()
                {
                    Level = 1,
                    ParentOrganizationId = parent.Id,
                    ChildOrganizationId = child.Id,
                    OrganizationHierarchyType = organizationHierarchyType
                };
            _organizationHierarchyRepository.SaveOrUpdate(organizationHierarchy);

            ISpecification<OrganizationHierarchy> specFindParents =
                new Specification<OrganizationHierarchy>(
                    s => s.ChildOrganizationId == parent.Id && s.OrganizationHierarchyType == organizationHierarchyType);

            IList<OrganizationHierarchy> allParents = _organizationHierarchyRepository.Query(specFindParents);

            foreach(var up in allParents)
            {
                OrganizationHierarchy hierarchy =
                   new OrganizationHierarchy()
                   {
                       Level = up.Level + 1,
                       ParentOrganizationId = up.ParentOrganizationId,
                       ChildOrganizationId = child.Id,
                       OrganizationHierarchyType = organizationHierarchyType
                   };
                _organizationHierarchyRepository.SaveOrUpdate(hierarchy);
            }
        }
Exemplo n.º 2
0
        public void CreatePermissionForOrganization(Organization organization, Entity entity, Operation operation)
        {
            Permission permission = new Permission()
            {
                Organization = organization,
                Entity = entity,
                Operation = operation,
                Level = 0
            };

            _permissionRepository.SaveOrUpdate(permission);
        }
Exemplo n.º 3
0
        public void TestCreateParentOrgan()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Organization,Guid> organRepository = new Repository<Organization,Guid>(store);
                IRepository<OrganizationHierarchy,Guid> organHireRepository = new Repository<OrganizationHierarchy,Guid>(store);
                Organization organ1 = new Organization()
                {
                    Name = "總經理室"
                };

                Organization organ2 = new Organization()
                {
                    Name = "業務部"
                };

                Organization organ3 = new Organization()
                {
                    Name = "人資部"
                };

                Organization organ4 = new Organization()
                {
                    Name = "企畫課"
                };

                organRepository.SaveOrUpdate(organ1);
                organRepository.SaveOrUpdate(organ2);
                organRepository.SaveOrUpdate(organ3);
                organRepository.SaveOrUpdate(organ4);

                unitwork.SaveChanges();

                OrganizationService service = new OrganizationService(organHireRepository);
                service.AddOrganizationHierarchy(organ1, organ2, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(organ1, organ3, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(organ3, organ4,OrganizationHierarchyType.AM);
                unitwork.SaveChanges();

            }
        }
Exemplo n.º 4
0
        public void TestAddPartyToOrganization()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Organization, Guid> organRepository = new Repository<Organization, Guid>(store);
                IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);

                Organization org1 = new Organization()
                {
                    Name = "總經理室"
                };

                organRepository.SaveOrUpdate(org1);

                Party party1 = partyRepository.Query(q => q.Name == "總經理室主管").First();
                Party party2 = partyRepository.Query(q => q.Name == "總經理室副主管").First();
                org1.Parties.Add(party1);
                org1.Parties.Add(party2);

                unitwork.SaveChanges();

            }
        }
Exemplo n.º 5
0
        public IList<Operation> GetOperationFor(Organization organ, Entity entity)
        {
            using (var cn = new SqlConnection(ConfigurationManager.ConnectionStrings["SecurityContext"].ConnectionString))
            {
                var operations =
                cn.Query<Operation, Operation, Operation>(string.Format(
                    @"
                        SELECT o.Id,o.Comment,o.ParentOperation_Id AS Id FROM Permission pm
                        INNER JOIN Operation o on pm.Operation_Id = o.Id
                        WHERE (pm.Party_Id is null) AND (pm.Organization_Id is null OR pm.Organization_Id = '{0}') AND Entity_Id = '{1}'
                    ", organ.Id
                     , entity.Id),
                     (org, parentorg) =>
                     {
                         org.Parent = parentorg;
                         return org;
                     }, splitOn: "Id");

                var allIds = operations.Select(s => s.Id).ToList();
                foreach (var ope in operations)
                {
                    if (ope.Parent == null) continue;

                    if (allIds.Contains(ope.Parent.Id))
                    {
                        allIds.Remove(ope.Id);
                    }
                }

                return operations.ToList().Where(s => allIds.Contains(s.Id)).ToList();
            }
        }
Exemplo n.º 6
0
        public void TestAddOrganization()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Organization, Guid> organRepository = new Repository<Organization, Guid>(store);
                IRepository<OrganizationHierarchy, Guid> organHireRepository = new Repository<OrganizationHierarchy, Guid>(store);

                Organization org1 = new Organization() { Name = "總經理室" };
                Organization org2 = new Organization() { Name = "人資部" };
                Organization org3 = new Organization() { Name = "業務部" };
                Organization org4 = new Organization() { Name = "企畫課" };
                Organization org5 = new Organization() { Name = "管理課" };
                Organization org6 = new Organization() { Name = "業務一課" };
                Organization org7 = new Organization() { Name = "業務二課" };
                Organization org8 = new Organization() { Name = "業務三課" };

                organRepository.SaveOrUpdate(org1);
                organRepository.SaveOrUpdate(org2);
                organRepository.SaveOrUpdate(org3);
                organRepository.SaveOrUpdate(org4);
                organRepository.SaveOrUpdate(org5);
                organRepository.SaveOrUpdate(org6);
                organRepository.SaveOrUpdate(org7);
                organRepository.SaveOrUpdate(org8);

                unitwork.SaveChanges();

                OrganizationService service = new OrganizationService(organHireRepository);
                service.AddOrganizationHierarchy(org1, org2, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org1, org3, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org2, org4, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org2, org5, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org3, org6, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org3, org7, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org3, org8, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
            }
        }