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;
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (UserProject.IsAllowReadProject(Int32.Parse(Request.QueryString["id"]), Session["userName"].ToString()))
            {
                UserProject myProject = new UserProject();
                List<ProjectRole> pRoles = new List<ProjectRole>();
                pRoles = UserProject.GetProjectRolesByProjectId(Int32.Parse(Request.QueryString["id"]));
                string executeUsers = String.Empty;
                foreach (ProjectRole pRole in pRoles)
                {
                    if (pRole.state == "Yes")
                    {
                        if (pRole.role == "Request")
                        {
                            TableCell2.Text = pRole.userName;
                        }
                        if (pRole.role == "Execute")
                        {
                            executeUsers += pRole.userName + " ";
                        }
                    }
                    if (pRole.role == "Admin")
                    {
                        TableCell1.Text = pRole.userName;
                        TableCell4.Text = pRole.userName;
                    }

                }
                TableCell3.Text = executeUsers;

                TableCell6.Text = "<a href=\"ProjectDocuments/Request.aspx?id=" + Request.QueryString["id"] + "&projectName=" + Request.QueryString["projectName"] + "\">文档</a>";
                TableCell5.Text = "<a href=\"ProjectDocuments/Plan.aspx?id=" + Request.QueryString["id"] + "&projectName=" + Request.QueryString["projectName"] + "\">文档</a>";
                TableCell7.Text = "<a href=\"ProjectDocuments/Execute.aspx?id=" + Request.QueryString["id"] + "&projectName=" + Request.QueryString["projectName"] + "\">文档</a>";
                TableCell8.Text = "<a href=\"ProjectDocuments/Final.aspx?id=" + Request.QueryString["id"] + "&projectName=" + Request.QueryString["projectName"] + "\">文档</a>";
            }
            else
            {
                Response.Redirect("Error.aspx");
            }

            if (BusinessLogicLib.UserProject.IsProjectFinished(Int32.Parse(Request.QueryString["id"])))
            {
                LinkButton1.Visible = false;
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["userName"].ToString() != "traveller")
     {
         if (Request.QueryString["role"] == "Admin")
         {
             UserProject userProject = new UserProject();
             try
             {
                 userProject = UserProject.GetUserSetupProjectById(Int32.Parse(Request.QueryString["id"]), Session["userName"].ToString());
             }
             catch
             {
                 Response.Write("Error!");
             }
             string path = Server.MapPath("~/App_Data/Projects") + "\\" + Request.QueryString["id"];
         }
     }
 }
        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 MySetupProjectTest()
 {
     List<UserProject> myProjects = new List<UserProject>();
     UserProject userProject = new UserProject();
     myProjects = UserProject.GetProjectsByAuthority("Hill",true);
     //Assert.AreEqual((myProjects[0].projectPublishTime).ToString(), "2012/5/16 0:21:33");
     //Assert.AreEqual(myProjects[0].roles[0].role, "Admin");
     //bool result = (myProjects.Count == 0);
     //Assert.AreEqual(false,result);
     Assert.AreEqual(myProjects[0].id, 11);
 }
        private static UserProject getProjectById(ISession session, int id)
        {
            List<ProjectRole> projectRoles = new List<ProjectRole>();
            projectRoles = (from pr in session.Query<ProjectRole>()
                            where pr.projectId == id
                            select pr).ToList<ProjectRole>();

            UserProject project = new UserProject();
            if (projectRoles.Count == 0)
            {
                return project;
            }
            project = (from p in session.Query<DataModels.Object.Project>()
                       where p.id == id
                       select new
                       UserProject
                       {
                           projectName = p.projectName,
                           projectContext = p.projectContext,
                           projectPublishTime = p.projectPublishTime
                       }).First();
            project.id = id;
            project.roles = projectRoles;
            bool state = (from p in session.Query<DataModels.Object.Project>()
                          where p.id == id
                          select p.projectState).First();
            if (state)
            {
                project.projectStateString = "是";
            }
            else
            {
                project.projectStateString = "否";
            }
            return project;
        }
 public static bool IsAllowReadProject(int id, string username)
 {
     UserProject project = new UserProject();
     project = getProjectById(GetNHibernateSession(), id);
     bool result = false;
     if (project == null)
     {
         return result;
     }
     var roles = from r in project.roles
                 select r;
     foreach (var role in roles)
     {
         if (role.userName == username)
         {
             result = true;
         }
     }
     return result;
 }
 public static List<ProjectRole> GetProjectRolesByProjectId(int pr_id)
 {
     UserProject userProject = new UserProject();
     List<ProjectRole> roles = new List<ProjectRole>();
     ISession session = GetNHibernateSession();
     userProject = getProjectById(session,pr_id);
     roles = (from r in userProject.roles
              select r).ToList<ProjectRole>();
     return roles;
 }