public IEnumerable <MenuHdr> GetUserModule(int userid) { List <MenuHdr> MenuLists = new List <MenuHdr>(); using (SqlConnection conObj = new SqlConnection(conStr)) { SqlCommand cmdObj = new SqlCommand("spGetMenuData", conObj); cmdObj.CommandType = CommandType.StoredProcedure; cmdObj.Parameters.Add(new SqlParameter("@userID", userid)); conObj.Open(); SqlDataReader readerObj = cmdObj.ExecuteReader(); while (readerObj.Read()) { MenuHdr MenuList = new MenuHdr(); MenuList.menuID = Convert.ToInt32(readerObj["ID"].ToString()); MenuList.MenuText = readerObj["MenuText"].ToString(); MenuList.ParentID = readerObj["ParentId"] != DBNull.Value ? Convert.ToInt32(readerObj["ParentId"]) : (int?)null; MenuList.isActive = Convert.ToBoolean(readerObj["Active"].ToString()); MenuList.Link = readerObj["Link"].ToString(); MenuLists.Add(MenuList); } conObj.Close(); } return(MenuLists); }
public int InsertNewMenu(MenuHdr menu) { using (SqlConnection conObj = new SqlConnection(conStr)) { conObj.Open(); SqlCommand cmdObj = new SqlCommand("uspInsertMenu", conObj); cmdObj.CommandType = CommandType.StoredProcedure; cmdObj.Parameters.Add(new SqlParameter("@menuText", menu.MenuText)); cmdObj.Parameters.Add(new SqlParameter("@parentID", menu.ParentID)); cmdObj.Parameters.Add(new SqlParameter("@link", menu.Link)); return(Convert.ToInt32(cmdObj.ExecuteScalar())); } }