コード例 #1
0
ファイル: OrgImp.cs プロジェクト: XtremeKevinChow/rdroad
        public static void DeleteOrg(ISession session, OrgType type, int id)
        {
            Org org = Org.Get(session, type, id);

            if (org == null)
            {
                return;
            }
            org.Deleted = true;
            org.Update(session, "Deleted");

            Org parent = Org.Get(session, type, org.ParentId);

            if (parent == null)
            {
                return;
            }
            parent.RemoveChild(org);
        }
コード例 #2
0
ファイル: OrgImp.cs プロジェクト: XtremeKevinChow/rdroad
        public static SimpleJson SaveOrg(ISession session, Org org, OrgType type, string action, User oper)
        {
            Org original = null;

            switch (action)
            {
            case "create":
                Org parent = Org.Get(session, type, org.ParentId);
                if (parent == null)
                {
                    return(new SimpleJson().HandleError(string.Format("父节点{0}不存在", org.ParentId)));
                }

                org.CreateBy   = oper.UserId;
                org.CreateDate = DateTime.Now;
                org.IsVirtual  = false;
                org.IsRoot     = false;
                org.OrgType    = type;
                org.Deleted    = false;
                org.OrgSeq     = org.OrgSeq <= 0 ? (short)(Org.MaxSeq(session, org.ParentId) + 1) : org.OrgSeq;
                org.Create(session);

                if (OrgTypeRegistry.HasExtAttr(type) && org.ExtAttr != null)
                {
                    IOrgExtend oext = org.ExtAttr as IOrgExtend;
                    oext.OrgId = org.OrgId;
                    oext.Create(session);
                }

                parent.AddChild(org);
                Org.SortOrg(parent, org);
                return(Org.GetOrgJSON(session, org));

            case "update":
                original = Org.Get(session, type, org.OrgId);
                if (original == null)
                {
                    return(new SimpleJson().HandleError(string.Format("{0}不存在", org.OrgId)));
                }
                original.OrgCode     = org.OrgCode;
                original.OrgName     = org.OrgName;
                original.Description = org.Description;
                original.ModifyBy    = oper.UserId;
                original.ModifyDate  = DateTime.Now;
                original.OrgSeq      = org.OrgSeq;
                original.Manager     = org.Manager;
                original.Update(session, "OrgCode", "OrgName", "Description", "ModifyBy", "ModifyDate", "OrgSeq", "Manager");

                if (OrgTypeRegistry.HasExtAttr(type) && org.ExtAttr != null)
                {
                    IOrgExtend oext = org.ExtAttr as IOrgExtend;
                    oext.OrgId = org.OrgId;
                    oext.Update(session);
                    original.ExtAttr = oext;
                }

                Org.SortOrg(Org.Get(session, type, original.ParentId), original);
                return(Org.GetOrgJSON(session, original));

            default:
                return(new SimpleJson().HandleError(string.Format("无效的操作{0}", action)));
            }
        }