public void AddNewProjectTest()
        {
            ProjectRole role = new ProjectRole
            {
                projectId = 6,
                role = "Admin",
                userName = "******",
                state = null
            };
            NHibernateHelper NHelper = NHibernateHelper.NHelper;
            ISession session = NHelper.GetSession();

            session.Save(role);
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text != "")
            {
                List<ProjectRole> roles = new List<ProjectRole>();

                ProjectRole roleAdmin = new ProjectRole{ role="Admin",
                                                         userName=Session["userName"].ToString()};
                roles.Add(roleAdmin);
                if(!Object.Equals(Session["requestUser"],null))
                {
                    ProjectRole roleRequest = new ProjectRole{ role="Request", userName=Session["requestUser"].ToString(),
                                                               state="Unknown"};
                    roles.Add(roleRequest);
                }
                if(!Object.Equals(Session["executeUsers"],null))
                {
                    List<string> users = new List<string>();
                    users = Session["executeUsers"] as List<string>;
                    foreach(string u in users)
                    {
                        ProjectRole roleExecute = new ProjectRole{ role = "Execute", state="Unknown", userName=u};
                        roles.Add(roleExecute);
                    }
                }
                UserProject newProject = new UserProject{
                                                           projectContext= TextBox2.Text,
                                                           projectName=TextBox1.Text,
                                                           projectPublishTime = DateTime.Now,
                                                           projectState= false,
                                                           roles = roles
                                                            };
                UserProject.AddNewProject(newProject);
                Response.Redirect("MyProject.aspx");
            }
            else
            {
                Label7.ForeColor =System.Drawing.Color.Red;
                Label7.Text = "项目名不能为空";
            }
        }
        public void DbConnectionTest1()
        {
            Configuration cfg = new Configuration();
            cfg.AddAssembly("DataModels");
            ISessionFactory factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession();
            ITransaction tx = session.BeginTransaction();

            ProjectRole role = new ProjectRole();
            role = session.Get<ProjectRole>(11);
            tx.Commit();
            session.Close();
            factory.Close();
            Assert.AreEqual("Hill",role.userName);
        }
 public static bool AddNewProject(UserProject userProject)
 {
     try
     {
         ISession session = GetNHibernateSession();
         DataModels.Object.Project project = new DataModels.Object.Project
         {
             projectName = userProject.projectName,
             projectContext = userProject.projectContext,
             projectPublishTime = userProject.projectPublishTime,
             projectState = userProject.projectState
         };
         session.Save(project);
         int pr_id = (from p in session.Query<DataModels.Object.Project>()
                      orderby p.id descending
                      select p.id).First();
         foreach (ProjectRole r in userProject.roles)
         {
             ProjectRole role = new ProjectRole
             {
                 projectId = pr_id,
                 role = r.role,
                 userName = r.userName,
                 state = r.state
             };
             session.Save(role);
         }
         session.Flush();
         return true;
     }
     catch
     {
         return false;
     }
 }
        public static bool ChangeRequestor(int projectId, string userName)
        {
            try
            {
                ISession session = GetNHibernateSession();
                int count = (from r in session.Query<ProjectRole>()
                             where r.projectId == projectId && r.role == "Request"
                             select r).Count();
                if (count == 0)
                {
                    ProjectRole p = new ProjectRole
                    {
                        projectId = projectId,
                        role = "Request",
                        state = "Unknown",
                        userName = userName
                    };

                    session.Save(p);
                }
                else
                {
                    ProjectRole p = (from r in session.Query<ProjectRole>()
                                     where r.projectId == projectId && r.role == "Request"
                                     select r).First();
                    session.Delete(p);
                    ProjectRole p1 = new ProjectRole
                    {
                        projectId = projectId,
                        role = "Request",
                        state = "Unknown",
                        userName = userName
                    };
                    session.Save(p1);
                }

                //session.Flush();
                return true;
            }
            catch
            {
                return false;
            }
        }