/// <summary> /// Saves this instance. /// </summary> /// <returns></returns> public static bool SaveOrUpdate(Category entity) { if (entity == null) throw new ArgumentNullException("entity"); if (entity.ProjectId <= Globals.NEW_ID) throw (new ArgumentException("Cannot save category, the project id is invalid")); if (string.IsNullOrEmpty(entity.Name)) throw (new ArgumentException("The category name cannot be empty or null")); if (entity.Id > Globals.NEW_ID) return (DataProviderManager.Provider.UpdateCategory(entity)); var tempId = DataProviderManager.Provider.CreateNewCategory(entity); if (tempId <= 0) return false; entity.Id = tempId; return true; }
public int AddCategory(string projectId, string name, string parentCategoryId) { if (string.IsNullOrEmpty(projectId)) throw new ArgumentNullException("projectId"); if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); if (string.IsNullOrEmpty(parentCategoryId)) throw new ArgumentNullException("parentCategoryId"); var validParojectId = 0; var validParentCategoryId = 0; if(projectId.Is<int>()) validParojectId = int.Parse(projectId); if(parentCategoryId.Is<int>()) validParentCategoryId = int.Parse(parentCategoryId); var userName = Thread.CurrentPrincipal.Identity.Name; if (!UserManager.IsInRole(userName, Convert.ToInt32(projectId), Globals.ProjectAdminRole) && !UserManager.IsInRole(userName, 0, Globals.SUPER_USER_ROLE)) throw new UnauthorizedAccessException(LoggingManager.GetErrorMessageResource("AccessDenied")); var entity = new Category { ProjectId = validParojectId, ParentCategoryId = validParentCategoryId, Name = name, ChildCount = 0 }; CategoryManager.SaveOrUpdate(entity); return entity.Id; }
/// <summary> /// Updates the category. /// </summary> /// <param name="categoryToUpdate">The category to update.</param> /// <returns></returns> public override bool UpdateCategory(Category categoryToUpdate) { var sqlCmd = new SqlCommand(); AddParamToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null); AddParamToSqlCmd(sqlCmd, "@CategoryId", SqlDbType.Int, 0, ParameterDirection.Input, categoryToUpdate.Id); AddParamToSqlCmd(sqlCmd, "@ProjectId", SqlDbType.Int, 0, ParameterDirection.Input, categoryToUpdate.ProjectId); AddParamToSqlCmd(sqlCmd, "@CategoryName", SqlDbType.NText, 255, ParameterDirection.Input, categoryToUpdate.Name); AddParamToSqlCmd(sqlCmd, "@ParentCategoryId", SqlDbType.Int, 0, ParameterDirection.Input, categoryToUpdate.ParentCategoryId); SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_CATEGORY_UPDATE); ExecuteScalarCmd(sqlCmd); var returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value; return (returnValue == 0); }
/// <summary> /// Creates the new category. /// </summary> /// <param name="newCategory">The new category.</param> /// <returns></returns> public override int CreateNewCategory(Category newCategory) { if (newCategory == null) throw (new ArgumentNullException("newCategory")); using (var sqlCmd = new SqlCommand()) { AddParamToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null); AddParamToSqlCmd(sqlCmd, "@ProjectId", SqlDbType.Int, 0, ParameterDirection.Input, newCategory.ProjectId); AddParamToSqlCmd(sqlCmd, "@CategoryName", SqlDbType.NText, 255, ParameterDirection.Input, newCategory.Name); AddParamToSqlCmd(sqlCmd, "@ParentCategoryId", SqlDbType.Int, 0, ParameterDirection.Input, newCategory.ParentCategoryId); SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_CATEGORY_CREATE); ExecuteScalarCmd(sqlCmd); return ((int)sqlCmd.Parameters["@ReturnValue"].Value); } }
public abstract bool UpdateCategory(Category categoryToUpdate);
// Category public abstract int CreateNewCategory(Category newCategory);
/// <summary> /// Handles the Click event of the OkButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void OkButton_Click(object sender, EventArgs e) { var oldCategoryId = 0; if(!string.IsNullOrEmpty(HiddenField1.Value)) oldCategoryId = Convert.ToInt32(HiddenField1.Value); if (oldCategoryId != 0) { var queryClauses = new List<QueryClause> { new QueryClause("AND", "iv.[IssueCategoryId]", "=", HiddenField1.Value, SqlDbType.Int) }; var issues = IssueManager.PerformQuery(queryClauses, null, ProjectId); if (RadioButton1.Checked) //delete category { //if (RecursiveDelete.Checked == true) //Category.DeleteChildCategoriesByCategoryId(OldCategoryId); //delete the category. CategoryManager.Delete(oldCategoryId); } if (RadioButton2.Checked) //reassign issues to existing category. { if (DropCategory.SelectedValue == 0) { Message1.ShowErrorMessage(GetLocalResourceObject("NoCategorySelected").ToString()); return; } if (oldCategoryId == DropCategory.SelectedValue) { Message1.ShowErrorMessage(GetLocalResourceObject("SameCategorySelected").ToString()); return; } foreach (var issue in issues) { issue.CategoryName = DropCategory.SelectedText; issue.CategoryId = DropCategory.SelectedValue; IssueManager.SaveOrUpdate(issue); } //delete the category. CategoryManager.Delete(oldCategoryId); } //assign new category if (RadioButton3.Checked) { if(string.IsNullOrEmpty(NewCategoryTextBox.Text)) { Message1.ShowErrorMessage(GetLocalResourceObject("NewCategoryNotEntered").ToString()); return; } var c = new Category { ProjectId = ProjectId, ParentCategoryId = 0, Name = NewCategoryTextBox.Text, ChildCount = 0 }; CategoryManager.SaveOrUpdate(c); foreach (var issue in issues) { issue.CategoryName = NewCategoryTextBox.Text; issue.CategoryId = c.Id; IssueManager.SaveOrUpdate(issue); } //delete the category. CategoryManager.Delete(oldCategoryId); } } else { Message1.ShowErrorMessage(GetLocalResourceObject("CannotDeleteRootCategory").ToString()); } }
/// <summary> /// Builds a Tree node /// </summary> /// <param name="category">The category information for the node</param> /// <param name="depth">The depth at which the node resides</param> /// <returns>A node for the tree view</returns> private TreeNode GetTreeNode(Category category, int depth) { var tNode = new TreeNode(); // now cut it if it needs it var catText = GetCategoryText(category.Name, depth); if (ShowIssueCount) { tNode.Text = String.Format("{0}</a></td><td style='width:100%;text-align:right;'><a>{1} ", catText, category.IssueCount); tNode.NavigateUrl = String.Format("~/Issues/IssueList.aspx?pid={0}&c={1}", ProjectId, category.Id); } else { tNode.Text = catText; } tNode.Value = category.Id.ToString(); //If node has child nodes, then enable on-demand populating tNode.PopulateOnDemand = (category.ChildCount > 0); return tNode; }
/// <summary> /// Populate the child nodes for the treeview /// </summary> /// <param name="parent">The parent category to populate the children for</param> /// <param name="nodes">The actual tree nodes to populate</param> /// <param name="depth">The current depth of the node structure</param> /// <param name="all">The full category list for the project</param> private void PopulateChildNodes(Category parent, TreeNodeCollection nodes, int depth, List<Category> all) { foreach (var pCat in all.FindAll(p => p.ParentCategoryId == parent.Id)) { var node = GetTreeNode(pCat, depth); if (pCat.ChildCount > 0) { PopulateChildNodes(pCat, node.ChildNodes, depth + 1, all); } nodes.Add(node); } }
private static List<JsTreeNode> PopulateChildNodes(Category parent, List<Category> all) { var tree = new List<JsTreeNode>(); foreach (var pCat in all.FindAll(p => p.ParentCategoryId == parent.Id)) { var pNode = new JsTreeNode { attr = new Attributes() }; pNode.attr.id = Convert.ToString(pCat.Id); pNode.attr.rel = "cat" + Convert.ToString(pCat.Id); pNode.data = new Data { title = Convert.ToString(pCat.Name), icon = "../../images/plugin.gif" }; tree.Add(pNode); if (pCat.ChildCount > 0) { pNode.children = PopulateChildNodes(pCat, all); } } return tree; }