Exemple #1
0
        public void Promote(String pk)
        {
            // Transfere nó para nível imediatamente inferior (número do nível)
            try
            {
                byte[]         b = GetHid(pk);
                SqlHierarchyId h = Conversions.Bytes2HierarchyId(b);
                if (h.GetLevel() < 2)
                {
                    throw new Exception("Não é possível a promoção de nível 1 ou 0.");
                }

                long   novamae = 0;
                byte[] grandP  = Conversions.HierarchyId2Bytes(h.GetAncestor(2));
                foreach (var t in repo.Get)
                {
                    byte[] bh = t.hid;
                    if (bh.SequenceEqual(grandP))
                    {
                        novamae = (long)t.GetType().GetProperty(PKName).GetValue(t, null);
                        break;
                    }
                }
                MovSubTree(pk, novamae.ToString());
            }
            catch (Exception ex)
            { throw new Exception("Erro na promoção: " + ex.Message); }
        }
Exemple #2
0
        public async Task <ActionResult <Domaintest> > GetDomain(int id)
        {
            object domain = (from x in _context.Domains.Where(x => x.DomainId == id)
                             select new
            {
                Id = x.DomainId,
                Name = x.DomainName,
                Type = x.DomainTypeId,
                Parent = x.Parentt,
                Path = x.Level.ToString(),
                HighLevel = x.HighLevel
            }).FirstOrDefault();

            //var type = domain.GetType();
            //var strNode = (string) type.GetProperty("Path").GetValue(domain, null);

            dynamic dyn = domain;

            int    myId      = dyn.Id;
            string strName   = dyn.Name;
            int    iType     = dyn.Type;
            string strParent = dyn.Parent;
            string strNode   = dyn.Path;
            //int hLevel = dyn.HighLevel;
            SqlHierarchyId node   = SqlHierarchyId.Parse(dyn.Path);
            int            hLevel = (int)node.GetLevel();

            Domaintest result = new Domaintest(myId, strName, iType, strParent, strNode, hLevel);

            return(result);
        }
Exemple #3
0
        public void DeleteTree(String pk)
        // remove toda uma sub árvore
        {
            try
            {
                long           tree   = long.Parse(pk);
                T              t      = repo.Find(new object[] { tree });
                SqlHierarchyId hid    = Conversions.Bytes2HierarchyId(t.hid);
                Int16          maxNiv = 0;

                foreach (var r in repo.Get)
                {
                    SqlHierarchyId h = Conversions.Bytes2HierarchyId(r.hid);
                    if (h.IsDescendantOf(hid))
                    {
                        if (h.GetLevel() > maxNiv)
                        {
                            maxNiv = (Int16)h.GetLevel();
                        }
                    }
                }


                for (int i = maxNiv; i > 0; i--)
                {
                    foreach (T r in repo.Get)
                    {
                        SqlHierarchyId h = Conversions.Bytes2HierarchyId(r.hid);
                        if (h.IsDescendantOf(hid))
                        {
                            db.Entry(r).State = EntityState.Deleted;
                        }
                    }
                }

                db.SaveChanges();
            }
            catch (Exception ex)
            { throw new Exception("Erro em exclusão de sub-árvore: " + ex.Message); }
        }
Exemple #4
0
 public void Promote(String pk)
 {
     // Transfere nó para nível imediatamente inferior (número do nível)
     try
     {
         byte[]         b = GetHid(pk);
         SqlHierarchyId h = Conversions.Bytes2HierarchyId(b);
         if (h.GetLevel() < 2)
         {
             throw new Exception("It is not allowed promotion from level 1 or 0.");
         }
         var  result  = db.Database.SqlQuery <long>("select " + PKName + " from " + TableName + " where hid = cast((Select cast(hid as hierarchyid) from " + TableName + " where " + PKName + " = " + pk + ").GetAncestor(2) as varbinary)").ToList();
         long novamae = result[0];
         MovSubTree(pk, novamae.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("Error on promote." + ex.Message);
     }
 }