public List <MenuGroupDTO> FindMenuGroupAll(object data) { List <MenuGroupDTO> objMGList = new List <MenuGroupDTO>(); MenuGroupDTO objMG = null; string procName = "sp_M_MENUGROUP_FindAll"; SqlConnection conn = OpenConnection(); command = new SqlCommand(procName, conn); command.CommandType = CommandType.StoredProcedure; try { using (SqlDataReader reader = command.ExecuteReader()) { // objList = DTO.Util.ConvertX.GetListFromDataReader<MenuDTO>(reader) as List<MenuDTO>; while (reader.Read()) { objMG = new MenuGroupDTO(); objMG.MENU_OID = reader["MENU_OID"].ToString(); objMG.OrderNo = reader["OrderNo"].ToString(); objMG.Name = reader["Name"].ToString(); objMGList.Add(objMG); } } } catch (Exception ex) { } finally { CloseConnection(); } return(objMGList); }
public static List <MenuGroupDTO> GetAll() { List <MenuGroupDTO> rtn = new List <MenuGroupDTO>(); List <SP_MenuGroup_Menu_GetAll_Result> menuGroupModelList = MenuDAL.GetAll(); foreach (SP_MenuGroup_Menu_GetAll_Result menuGroupModel in menuGroupModelList) { if (rtn.Any(x => x.Id == menuGroupModel.IdMenuGroup)) { // El grupo ya fue generado en la lista de devolución. MenuGroupDTO actualMenu = rtn.Where(z => z.Id == menuGroupModel.IdMenuGroup).FirstOrDefault(); if (actualMenu != null) { if (!actualMenu.MenuList.Any(y => y.Id == menuGroupModel.IdMenu)) { actualMenu.MenuList.Add(MenuService.GetById(menuGroupModel.IdMenu)); } } } else { // El grupo no fue generado en la lista de devolución. Se genera. MenuGroupDTO menuGroup = new MenuGroupDTO(); menuGroup.Id = menuGroupModel.IdMenuGroup; menuGroup.Name = menuGroupModel.MenuGroupName; menuGroup.Detail = menuGroupModel.MenuGroupDetail; menuGroup.MenuList = new List <MenuDTO>(); menuGroup.MenuList.Add(MenuService.GetById(menuGroupModel.IdMenu)); rtn.Add(menuGroup); } } return(rtn); }