public int addMenu(Menu menuEntity) { menu menuData = new menu(); var menuNewID = from x in entity.menus orderby x.menuId descending select x; menuData.menuId = (menuNewID.FirstOrDefault().menuId) + 1; menuData.menu1 = menuEntity.MenuName; menuData.url = menuEntity.Url; menuData.parentId = menuEntity.ParentId; entity.menus.Add(menuData); entity.SaveChanges(); return menuData.menuId; }
protected void tvMenuSetting_SelectedNodeChanged(object sender, EventArgs e) { this.initializeControls(); menuEntity = menuFaca.fillMenuEntity(tvMenuSetting.SelectedValue); this.lblMenuID.Text = menuEntity.MenuID; this.txtMenuName.Text = menuEntity.MenuName; this.txtUrl.Text = menuEntity.Url; this.lblParentID.Text = menuEntity.ParentId; dvParentMenu.Visible = false; butSave.Text = "Save"; this.bindToRoleByMenuid(); txtMenuName.Focus(); }
protected void butSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtMenuName.Text)) { showMessage("Type Menu name and url!"); txtMenuName.Focus(); } else { if (butSave.Text.Equals("Save")) { menuEntity = new ClassLibrary.Entities.Menu(); menuEntity.MenuID = lblMenuID.Text; menuEntity.MenuName = txtMenuName.Text; menuEntity.Url = txtUrl.Text; menuFaca.updateMenu(menuEntity); menuFaca.addMenuByRole(Int32.Parse(lblMenuID.Text), this.getSelectedRoleIdList()); initializeControls(); } else if (butSave.Text.Equals("Add Parent")) { menuEntity = new ClassLibrary.Entities.Menu(); menuEntity.MenuName = txtMenuName.Text; menuEntity.Url = txtUrl.Text; menuEntity.ParentId = "0"; int menuId = menuFaca.addMenu(menuEntity); menuFaca.addMenuByRole(menuId, this.getSelectedRoleIdList()); initializeControls(); } else if (butSave.Text.Equals("Add Child")) { menuEntity = new ClassLibrary.Entities.Menu(); menuEntity.MenuName = txtMenuName.Text; menuEntity.Url = txtUrl.Text; menuEntity.ParentId = ddlParentMenu.SelectedValue; int menuId = menuFaca.addMenu(menuEntity); menuFaca.addMenuByRole(menuId, this.getSelectedRoleIdList()); initializeControls(); } bindTreeMenu(); bindParentMenu(); } }
public Menu fillMenuEntity(string menuId) { menu menuData = getMenuDataById(Int32.Parse(menuId)); menuEntity = new Menu(); menuEntity.MenuID = menuData.menuId.ToString(); menuEntity.MenuName = menuData.menu1; menuEntity.Url = menuData.url; menuEntity.ParentId = menuData.parentId; return menuEntity; }
public void updateMenu(Menu menuEntity) { int menuid = int.Parse(menuEntity.MenuID); menu menuData = (from x in entity.menus where x.menuId == menuid select x).SingleOrDefault(); menuData.menu1 = menuEntity.MenuName; menuData.url = menuEntity.Url; entity.SaveChanges(); }