Ejemplo n.º 1
0
        public ReturnMenuRole SaveRoleWithPermissionMenus(MenuRole menuRole)
        {
            ReturnMenuRole returnMenuRole = new ReturnMenuRole();

            try
            {
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        cmd.CommandText = "sp_tRoleMenu_SaveRoleWithPermissionMenus";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@RoleID", menuRole.RoleID);
                        cmd.Parameters.AddWithValue("@MenuID", menuRole.ID);
                        cmd.Parameters.AddWithValue("@Permission", menuRole.Permission != null ? menuRole.Permission : "");
                        cmd.ExecuteNonQuery();
                        returnMenuRole.Code    = "00";
                        returnMenuRole.Message = "Cập nhật dữ liệu thành công.";
                    }
                }
            }
            catch (Exception ex)
            {
                returnMenuRole.Code        = "99";
                returnMenuRole.Message     = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnMenuRole.Total       = 0;
                returnMenuRole.lstMenuRole = null;
                mylog4net.Error("public ReturnUserWithRoles SaveUserWith_aRole(int userID, Role role) ", ex);
            }
            return(returnMenuRole);
        }
Ejemplo n.º 2
0
        public ReturnMenuRole GetMenusByUserID(User user)
        {
            List <MenuRole> lstMenu    = null;
            MenuRole        menuRole   = null;
            ReturnMenuRole  returnMenu = new ReturnMenuRole();

            try
            {
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        cmd.CommandText = "tMenu_listMenu_ByOrder_WithUserID";
                        cmd.Parameters.Add(new SqlParameter("@isReturnAllMenu", SqlDbType.Int)).Value = 0; // get  menu item corresponding to UserID.
                        cmd.Parameters.Add(new SqlParameter("@UserID", SqlDbType.Int)).Value          = user.ID;
                        cmd.CommandType = CommandType.StoredProcedure;

                        using (SqlDataReader sqlDr = ConnectSQLCommon.ExecuteDataReader(cmd))
                        {
                            if (sqlDr.HasRows)
                            {
                                lstMenu = new List <MenuRole>();
                                while (sqlDr.Read())
                                {
                                    menuRole              = new MenuRole();
                                    menuRole.ID           = int.Parse(sqlDr["ID"].ToString());
                                    menuRole.MenuName     = sqlDr["MenuName"].ToString();
                                    menuRole.DisplayName  = sqlDr["DisplayName"].ToString();
                                    menuRole.ParentMenuID = int.Parse(sqlDr["ParentMenuID"].ToString());
                                    menuRole.isActive     = int.Parse(sqlDr["isActive"].ToString());
                                    menuRole.UrlLink      = sqlDr["UrlLink"].ToString();
                                    menuRole.Permission   = sqlDr["Permission"].ToString();
                                    if (menuRole.isActive == 1)
                                    {
                                        lstMenu.Add(menuRole);
                                    }
                                }
                                returnMenu.Code        = "00";
                                returnMenu.Message     = "Lấy dữ liệu thành công.";
                                returnMenu.lstMenuRole = lstMenu;
                            }
                            else
                            {
                                returnMenu.Code        = "01";
                                returnMenu.Message     = "Không tồn tại bản ghi nào.";
                                returnMenu.Total       = 0;
                                returnMenu.lstMenuRole = null;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                returnMenu.Code        = "99";
                returnMenu.Message     = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnMenu.Total       = 0;
                returnMenu.lstMenuRole = null;
                mylog4net.Error("public ReturnMenuRole GetMenusByUserID(User user) ", ex);
            }
            return(returnMenu);
        }