public static BaseHelper MenuGet(Model.Session data) { var retVal = new BaseHelper(); var objJSON = new Output.Session(); var objJSONMenu = new Output.Menu(); try { var entity = User.ValidateSession(data, objJSON); retVal.SQLElapsed = entity.SQLElapsed; retVal.SQLInfo($"sp : {entity.SQLDetail}, elapsed : {entity.SQLElapsed}"); if (objJSON.ResultCode == 1) { var dataMenu = new Model.User { UserID = objJSON.Content.Data[0].UserID, StampUser = objJSON.Content.Data[0].UserLogin }; var entityMenu = Dashboard.MenuGet(dataMenu, objJSONMenu); retVal.SQLElapsed += entityMenu.SQLElapsed; retVal.SQLInfo($"sp : {entityMenu.SQLDetail}, elapsed : {entityMenu.SQLElapsed}"); retVal.IsError = (entityMenu.ResultCode == 1) ? false : true; } else { objJSONMenu.ResultCode = objJSON.ResultCode; objJSONMenu.ErrorMessage = objJSON.ErrorMessage; } } catch (Exception ex) { retVal.Exception = ex; if (ex is System.Data.SqlClient.SqlException sqlEx) { retVal.SQLInfo($"sp:{sqlEx.Procedure}, line:{sqlEx.LineNumber}, detail:{data.SqlDetail}"); retVal.SQLException = true; objJSON.ResultCode = 69998; objJSON.ErrorMessage = "SQL Exception"; } else { objJSON.ResultCode = 69999; objJSON.ErrorMessage = "Unknown Error"; } } finally { retVal.SerializeObject <Output.Menu>(objJSONMenu); } return(retVal); }
public static BasicEntity MenuGet(Model.User data, Output.Menu obj) { var retVal = new BasicEntity(); retVal.AddParameter("@user_id", data.UserID); data.SqlDetail = retVal.SQLCommandBuilder("spDashboardMenuGet"); using (SqlDataReader reader = retVal.ExecReader()) { while (reader.Read()) { obj.ResultCode = (reader.IsDBNull(0)) ? 0 : reader.GetInt32(0); obj.ErrorMessage = (reader.IsDBNull(1)) ? string.Empty : reader.GetString(1); retVal.ResultCode = obj.ResultCode; } if (retVal.ResultCode == 1) { reader.NextResult(); while (reader.Read()) { var itemSection = new Output.SectionData(); var itemMenu = new Output.MenuData(); itemMenu.MenuID = (reader.IsDBNull(0)) ? string.Empty : reader.GetString(0); itemMenu.MenuName = (reader.IsDBNull(1)) ? string.Empty : reader.GetString(1); itemMenu.MenuOrder = (reader.IsDBNull(2)) ? 0 : reader.GetInt32(2); itemMenu.WebName = (reader.IsDBNull(3)) ? string.Empty : reader.GetString(3); itemMenu.WebURL = (reader.IsDBNull(4)) ? string.Empty : reader.GetString(4); itemSection.SectionID = (reader.IsDBNull(5)) ? string.Empty : reader.GetString(5); itemSection.SectionName = (reader.IsDBNull(6)) ? string.Empty : reader.GetString(6); itemSection.SectionIcon = (reader.IsDBNull(7)) ? string.Empty : reader.GetString(7); var objFind = obj.Content.Data.Find(d => d.SectionID == itemSection.SectionID); if (objFind is null) { itemSection.Data.Add(itemMenu); obj.Content.Data.Add(itemSection); } else { objFind.Data.Add(itemMenu); } } } reader.Close(); } retVal.Close(); return(retVal); }