using System;
using System.Collections.Generic;
using System.Text;
using Model;
using ImpDDal;
using IDDal;
using System.Collections;
/********菜单详细信息的业务逻辑层**********
 * 设计者:魏莹
 * 设计时间:6月1日
 *****************************************/
namespace Business
{
    /// <summary>
    /// 菜单详细信息操作类
    /// </summary>
    public class BMenuType
    {
        MenuTypeDal<MenuType> menuTypeOp = new ImpMenuType();
        /// <summary>
        /// 增加一个菜单详细信息
        /// </summary>
        /// <param name="menutype">菜单详细信息对象</param>
        /// <returns>菜单号</returns>
        public string AddMenuType(MenuType menutype)
        {
            try
            {
                return menuTypeOp.AddMenuType(menutype);
            }
            catch (Exception ex)
            {
                
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 删除一个菜单,包括所包含的所有菜肴
        /// </summary>
        /// <param name="menutype">菜单详细信息对象</param>
        /// <returns>1表示删除成功,0表示删除失败</returns>
        public int DeleteMenuType(MenuType menutype)
        {
            try
            {
                return menuTypeOp.DeleteMenuType(menutype);
            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 修改一个菜单详细信息
        /// </summary>
        /// <param name="menutype">菜单详细信息对象</param>
        /// <returns>1表示修改成功,0表示修改失败</returns>
        public int ModifyMenuType(MenuType menutype)
        {
            try
            {
                return menuTypeOp.EditMenuType(menutype);
            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 根据菜单类型返回菜单
        /// </summary>
        /// <param name="type">菜单类型</param>
        /// <returns>菜单详细信息集合</returns>
        public IList<MenuType> SelectMenuType(string type)
        {
            try
            {
                return menuTypeOp.MenuTypes(type);
            }
            catch (Exception ex)
            {
                
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 根据菜单类型和创接者ID返回菜单列表
        /// </summary>
        /// <param name="type">菜单类型</param>
        /// <param name="createrid">创建者ID</param>
        /// <returns>菜单列表</returns>
        public IList<MenuType> SelectMenuType(string type, string createrid)
        {
            try
            {
                return menuTypeOp.MenuTypes(type, createrid);
            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 根据菜单类型,创接者ID和菜单名返回菜单列表
        /// </summary>
        /// <param name="type">菜单类型</param>
        /// <param name="createrid">创建者</param>
        /// <param name="menuname">菜单名</param>
        /// <returns>菜单列表</returns>
        public IList<MenuType> SelectMenuType(string type, string createrid, string menuname)
        {
            try
            {
                return menuTypeOp.MenuTypes(type, createrid,menuname);
            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 根据菜单ID返回一个菜单信息对象
        /// </summary>
        /// <param name="menuid">菜单ID</param>
        /// <returns> 菜单详细信息对象</returns>
        public MenuType ShowOneMenu(string menuid)
        {
            try
            {
                return menuTypeOp.GetOneMenu(menuid);
            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 根据现有菜单构造一个含有菜肴详细信息的菜单对象
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        private IList<MenuType> AddItemsInfo(IList<MenuType> list)
        {
            IList<MenuType> newList = new List<MenuType>();
            MenuType newMenuType = null;
            foreach (MenuType menutype in list)
            {
                newMenuType = this.ShowOneMenu(menutype.MenuId);
                newList.Add(newMenuType);
            }
            return newList;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IList<MenuType> GetHotMenu()
        {
            
            IList<MenuType> listItems = new List<MenuType>();
            IList<MenuType> list = menuTypeOp.SelectHotMenu();
            MenuType menuType=null;
            foreach (MenuType _menuType in list)
            {
                menuType=menuTypeOp.GetOneMenu(_menuType.MenuId);
                listItems.Add(menuType);
            }
            return listItems;
        }
    }
}
