Пример #1
0
        public void MainTest01()
        {
            Console.WriteLine("Start Test");
            InitialiseDatabase.RunOnce();
            //InitialiseDatabase.ImportRegionExcel(@"C:\Temp\SystemRegion.xls");

            LiveEntities dbEntity = new LiveEntities(ConfigHelper.LiveConnection.Connection);

            Guid gUserID = (from u in dbEntity.MemberUsers
                            where u.LoginName == "test"
                            select u.Gid).FirstOrDefault();

            var oPrivilege1 = (from p in dbEntity.MemberPrivileges
                              where p.UserID == gUserID && p.Ptype == (byte)ModelEnum.UserPrivType.PROGRAM
                              select p).FirstOrDefault();
            var oProgram = (from p in dbEntity.GeneralPrograms.Include("ProgramNodes")
                            where p.Code == "ProgramIndex"
                            select p).FirstOrDefault();
            oPrivilege1.PrivilegeItems.Add(
                new MemberPrivItem
                {
                    RefID = oProgram.Gid
                });

            var oPrivilege2 = (from p in dbEntity.MemberPrivileges
                               where p.UserID == gUserID && p.Ptype == (byte)ModelEnum.UserPrivType.PROGRAM_NODE
                               select p).FirstOrDefault();
            if (oPrivilege2 == null)
            {
                oPrivilege2 = new MemberPrivilege
                {
                    Ptype = (byte)ModelEnum.UserPrivType.PROGRAM_NODE,
                    UserID = gUserID,
                    PrivilegeItems = new List<MemberPrivItem>
                    {
                        new MemberPrivItem
                        {
                            RefID = oProgram.FindProgramNode("EnableEdit").Gid,
                            NodeCode = "EnableEdit",
                            NodeValue = "1"
                        }
                    }

                };
                dbEntity.MemberPrivileges.Add(oPrivilege2);
            }

            dbEntity.Entry(oPrivilege1).State = EntityState.Modified;
            dbEntity.SaveChanges();
        }