protected int CreateNewProject() { // Initialize usercontentmanager class with the users username UserContentManager contentmanager = new UserContentManager(ticket.Name); string projectname = txtProjectName.Text; string projectdesc = txtProjectDescription.Text; string projectcreator = ticket.Name; string grouptoaddname = String.Empty; double percent = 0; string applicationpath = Request.ApplicationPath; string pictureuri = applicationpath + "Images/no_image.png"; List <group> groupquery = new List <group>(); bool is_same_name = false; bool gooduri = Uri.IsWellFormedUriString(txtPictureURI.Text, UriKind.Absolute); if (gooduri == true) { pictureuri = txtPictureURI.Text; } else { lbmessages.Text = "Enter valid absolute url path of the picture"; } if (ddlGroupList.SelectedItem.Text != ddlGroupList.Items[0].Text) { grouptoaddname = ddlGroupList.SelectedItem.Text; groupquery = contentmanager.GetUserGroups(); } DateTime duedate = calendarDueDate.SelectedDate; try { var rightperson = ctx.person.Where(p => p.username == projectcreator).FirstOrDefault(); // Check that the user does not already have a project with the same name List <project> userprojects = contentmanager.GetUserProjects(); foreach (var project in userprojects) { if (project.name == projectname) { is_same_name = true; } } if (is_same_name == false) { // Search the right group given in the dropdownlist if (grouptoaddname != String.Empty) { var rightgroup = ctx.group.Where(g => g.name == grouptoaddname); } int emptyrow = 0; int addedrow = 0; // First check for any gaps in the number sequence inside the database for (int i = 0; i <= ctx.project.Count(); i++) { project compareProject = new project(); var checkProject = ctx.project.Where(gr => gr.project_id == i).FirstOrDefault(); if (checkProject == compareProject) { emptyrow = i; } else { compareProject = checkProject; } } if (emptyrow == 0) { addedrow = ctx.project.Count() + 1; } else { addedrow = emptyrow; } // Insert new project into database var newproject = new project { name = projectname, description = projectdesc, project_creator = rightperson.username, creation_date = DateTime.Now, due_date = duedate, percent_done = percent, finished = false, privacy = 1, picture_url = pictureuri }; var projectlist = ctx.project.ToList(); if (projectlist != null) { int tagindex = 100; foreach (var project in projectlist) { tagindex = (int)project.project_tag + 1; } newproject.project_tag = tagindex; } else { newproject.project_tag = 100; } ctx.project.Add(newproject); ctx.SaveChanges(); return(newproject.project_id); } else { lbmessages.Text = "Error: You already have a project with that name"; return(-1); } } catch (Exception ex) { lbmessages.Text = ex.Message; return(-1); } }
protected void FillDivs() { // Fill your projects section with the users projects and assignments // and fill your groups section with the users groups UserContentManager contentmanager = new UserContentManager(ticket.Name); try { List <group> usergroups = contentmanager.GetUserGroups(); List <project> userprojects = contentmanager.GetUserProjects(); foreach (var project in userprojects) { var projectassignments = project.assignment.ToList(); HtmlGenericControl projectdiv = new HtmlGenericControl("div"); HtmlGenericControl projectinnerdiv = new HtmlGenericControl("div"); HtmlGenericControl projectassignmentdiv = new HtmlGenericControl("div"); HtmlGenericControl projectassignmentinnerdiv = new HtmlGenericControl("div"); HtmlGenericControl projectlink = new HtmlGenericControl("a"); HtmlGenericControl projectimage = new HtmlGenericControl("img"); HtmlGenericControl projectcut = new HtmlGenericControl("hr"); HtmlGenericControl projectassignmenttitle = new HtmlGenericControl("h3"); HtmlGenericControl projectassignmentul = new HtmlGenericControl("ul"); projectdiv.Attributes.Add("class", "w3-container"); projectdiv.ID = "divProject" + project.project_id; projectinnerdiv.Attributes.Add("class", "w3-container"); projectimage.Attributes.Add("src", project.picture_url); projectimage.Attributes.Add("alt", "Project image"); projectimage.Attributes.Add("height", "150px"); projectimage.Attributes.Add("width", "150px"); projectimage.Attributes.Add("style", "float:left;"); projectinnerdiv.Controls.Add(projectimage); projectlink.Attributes.Add("href", String.Format("Project.aspx?Project={0}", project.project_id)); projectlink.Attributes.Add("style", "float:left; margin-top:5%; margin-left:5%;"); projectlink.InnerText = project.name; projectinnerdiv.Controls.Add(projectlink); projectcut.Attributes.Add("style", "color:#000;background-color:#000; height:5px;"); projectassignmentdiv.Attributes.Add("class", "w3-container"); projectassignmenttitle.InnerText = "Assignments"; projectassignmentdiv.Controls.Add(projectassignmenttitle); projectassignmentinnerdiv.Attributes.Add("style", "width:15%;"); projectassignmentul.Attributes.Add("class", "w3-ul w3-border"); projectassignmentul.Attributes.Add("id", "projectassignmentsul"); foreach (var assignment in projectassignments) { HtmlGenericControl projectassignmentli = new HtmlGenericControl("li"); HtmlGenericControl projectassignmentlink = new HtmlGenericControl("a"); projectassignmentlink.Attributes.Add("href", String.Format("Assignment.aspx?Assignment={0}&Project={1}", assignment.amt_id, project.project_id)); projectassignmentlink.InnerText = assignment.name; projectassignmentli.Controls.Add(projectassignmentlink); projectassignmentul.Controls.Add(projectassignmentli); } projectassignmentinnerdiv.Controls.Add(projectassignmentul); projectassignmentdiv.Controls.Add(projectassignmentinnerdiv); projectdiv.Controls.Add(projectinnerdiv); projectdiv.Controls.Add(projectassignmentdiv); projectdiv.Controls.Add(projectcut); divYourProjects.Controls.Add(projectdiv); } } catch (Exception ex) { lbMessages.Text = ex.Message; } }
protected void FillDivs(int user_id) { // Fill your projects section with the users projects and assignments // and fill your groups with the users groups try { var rightperson = ctx.person.Where(p => p.person_id == user_id).SingleOrDefault(); if (rightperson != null) { UserContentManager contentmanager = new UserContentManager(rightperson.username); List <group> usergroups = contentmanager.GetUserGroups(); List <project> userprojects = contentmanager.GetUserProjects(); foreach (var project in userprojects) { HtmlGenericControl projectdiv = new HtmlGenericControl("div"); HtmlGenericControl projectinnerdiv = new HtmlGenericControl("div"); HtmlGenericControl projectlink = new HtmlGenericControl("a"); HtmlGenericControl projectimage = new HtmlGenericControl("img"); HtmlGenericControl projectcut = new HtmlGenericControl("hr"); projectdiv.Attributes.Add("class", "w3-container"); projectdiv.ID = "divProject" + project.project_id; projectinnerdiv.Attributes.Add("class", "w3-container"); projectimage.Attributes.Add("src", project.picture_url); projectimage.Attributes.Add("alt", "Project image"); projectimage.Attributes.Add("height", "150px"); projectimage.Attributes.Add("width", "150px"); projectimage.Attributes.Add("style", "float:left;"); projectinnerdiv.Controls.Add(projectimage); projectlink.Attributes.Add("href", String.Format("Project.aspx?Project={0}", project.project_id)); projectlink.Attributes.Add("style", "float:left; margin-top:5%; margin-left:5%;"); projectlink.InnerText = project.name; projectinnerdiv.Controls.Add(projectlink); projectcut.Attributes.Add("style", "color:#000;background-color:#000; height:5px;"); projectdiv.Controls.Add(projectinnerdiv); projectdiv.Controls.Add(projectcut); divUserProjects.Controls.Add(projectdiv); } foreach (var group in usergroups) { HtmlGenericControl groupdiv = new HtmlGenericControl("div"); HtmlGenericControl groupinnerdiv = new HtmlGenericControl("div"); HtmlGenericControl grouplink = new HtmlGenericControl("a"); HtmlGenericControl groupimage = new HtmlGenericControl("img"); HtmlGenericControl groupcut = new HtmlGenericControl("hr"); groupdiv.Attributes.Add("class", "w3-container"); groupdiv.ID = "divGroup" + group.group_id; groupinnerdiv.Attributes.Add("class", "w3-container"); groupimage.Attributes.Add("src", group.group_picture_url); groupimage.Attributes.Add("alt", "Group image"); groupimage.Attributes.Add("height", "150px"); groupimage.Attributes.Add("width", "150px"); groupimage.Attributes.Add("style", "float:left;"); if (group.group_picture_url != null) { if (group.group_picture_url != String.Empty) { groupimage.Attributes.Add("src", group.group_picture_url); } } else { groupimage.Attributes.Add("src", Request.ApplicationPath + "Images/no_image.png"); } groupinnerdiv.Controls.Add(groupimage); grouplink.Attributes.Add("href", String.Format("Group.aspx?Group={0}", group.group_id)); grouplink.Attributes.Add("style", "float:left; margin-top:5%; margin-left:5%;"); grouplink.InnerText = group.name; groupinnerdiv.Controls.Add(grouplink); groupcut.Attributes.Add("style", "color:#000;background-color:#000; height:5px;"); groupdiv.Controls.Add(groupinnerdiv); groupdiv.Controls.Add(groupcut); divUserGroups.Controls.Add(groupdiv); } } } catch (Exception ex) { lbMessages.Text = ex.Message; } }
protected void FillDivs() { // Fill your projects section with the users projects and assignments // and fill your groups with the users groups UserContentManager contentmanager = new UserContentManager(ticket.Name); try { divYourGroups.Controls.Clear(); divYourProjects.Controls.Clear(); List <group> usergroups = contentmanager.GetUserGroups(); List <project> userprojects = contentmanager.GetUserProjects(); // First fill the projects section of the page foreach (var project in userprojects) { HtmlGenericControl projectdiv = new HtmlGenericControl("div"); HtmlGenericControl projectinnerdiv = new HtmlGenericControl("div"); HtmlGenericControl projectlink = new HtmlGenericControl("a"); HtmlGenericControl projectimage = new HtmlGenericControl("img"); HtmlGenericControl projectcut = new HtmlGenericControl("hr"); projectdiv.Attributes.Add("class", "w3-container"); projectdiv.ID = "divProject" + project.project_id; projectinnerdiv.Attributes.Add("class", "w3-container"); projectimage.Attributes.Add("alt", "Project image"); projectimage.Attributes.Add("height", "150px"); projectimage.Attributes.Add("width", "150px"); projectimage.Attributes.Add("style", "float:left;"); // if the group has an exsiting picture in the database, we'll fetch it if (project.picture_url != null) { if (project.picture_url != String.Empty) { projectimage.Attributes.Add("src", project.picture_url); } } else { projectimage.Attributes.Add("src", Request.ApplicationPath + "Images/no_image.png"); } projectinnerdiv.Controls.Add(projectimage); projectlink.Attributes.Add("href", String.Format("Project.aspx?Project={0}", project.project_id)); projectlink.Attributes.Add("style", "float:left; margin-top:5%; margin-left:5%;"); projectlink.InnerText = project.name; projectinnerdiv.Controls.Add(projectlink); projectcut.Attributes.Add("style", "color:#000;background-color:#000; height:5px;"); projectdiv.Controls.Add(projectinnerdiv); projectdiv.Controls.Add(projectcut); divYourProjects.Controls.Add(projectdiv); } // Next we'll fill the groups section of the page foreach (var group in usergroups) { HtmlGenericControl groupdiv = new HtmlGenericControl("div"); HtmlGenericControl groupinnerdiv = new HtmlGenericControl("div"); HtmlGenericControl grouplink = new HtmlGenericControl("a"); HtmlGenericControl groupimage = new HtmlGenericControl("img"); HtmlGenericControl groupcut = new HtmlGenericControl("hr"); groupdiv.Attributes.Add("class", "w3-container"); groupdiv.ID = "divGroup" + group.group_id; groupinnerdiv.Attributes.Add("class", "w3-container"); groupimage.Attributes.Add("alt", "Group image"); groupimage.Attributes.Add("height", "150px"); groupimage.Attributes.Add("width", "150px"); groupimage.Attributes.Add("style", "float:left;"); // if the group has an exsiting picture in the database, we'll fetch it if (group.group_picture_url != null) { if (group.group_picture_url != String.Empty) { groupimage.Attributes.Add("src", group.group_picture_url); } } else { groupimage.Attributes.Add("src", Request.ApplicationPath + "Images/no_image.png"); } groupinnerdiv.Controls.Add(groupimage); grouplink.Attributes.Add("href", String.Format("Group.aspx?Group={0}", group.group_id)); grouplink.Attributes.Add("style", "float:left; margin-top:5%; margin-left:5%;"); grouplink.InnerText = group.name; groupinnerdiv.Controls.Add(grouplink); groupcut.Attributes.Add("style", "color:#000;background-color:#000; height:5px;"); groupdiv.Controls.Add(groupinnerdiv); groupdiv.Controls.Add(groupcut); divYourGroups.Controls.Add(groupdiv); } } catch (Exception ex) { lbMessages.Text = ex.Message; } }