using System;
using System.Collections.Generic;
using System.Text;
using Model;
using IDDal;
/************菜肴的业务逻辑层***********
 * 关于菜肴的增加,删除,修改,查询
 * 类设计者:魏莹
 * 设计时间5月30日
 ***************************************/
namespace Business
{
    /// <summary>
    /// 菜肴操作的业务逻辑层
    /// </summary>
    public class BItem
    {
        ItemDal<Item> itemop = new ImpDDal.ImpItemDal();
        /// <summary>
        /// 增加一个菜肴
        /// </summary>
        /// <param name="item">菜肴对象</param>
        /// <returns>1成功增加,0增加失败</returns>
        public int AddItem(Item item)
        {
            try
            {
                
                return itemop.AddItem(item);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 修改一个菜肴信息
        /// </summary>
        /// <param name="item">菜肴对象</param>
        /// <returns>1成功修改,0修改失败</returns>
        public int ModifyItem(Item item)
        {
            try
            {   
                return itemop.EditItem(item);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 修改一个菜肴的分类信息
        /// </summary>
        /// <param name="item">菜肴对象</param>
        /// <returns>1成功修改,0修改失败</returns>
        public int ModifyItemType(Item item)
        {
            try
            {
                return itemop.EditItemType(item);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 删除一个菜肴
        /// </summary>
        /// <param name="item">菜肴对象</param>
        /// <returns>1成功删除,0删除失败</returns>
        public int DeleteItem(Item item)
        {
            try
            {
                return itemop.DeleteItem(item);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 根据菜肴类别查询菜肴
        /// </summary>
        /// <param name="type">类别编号</param>
        /// <returns>菜肴集合</returns>
        public IList<Item> Select(int type)
        {
            try
            {
                return itemop.SelectItem(type);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 根据菜肴名模糊查询
        /// </summary>
        /// <param name="itemName">菜肴名称</param>
        /// <returns>菜肴集合</returns>
        public IList<Item> Select(string itemName)
        {
            try
            {
                return itemop.SelectItem(itemName);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 查询新加入的菜肴,提供主页浏览
        /// </summary>
        /// <returns>菜肴集合</returns>
        public IList<Item> SelectNewItem()
        {
            try
            {
                return itemop.SelectNewItemByIndex();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 查询某种菜肴的前几条记录
        /// </summary>
        /// <param name="type">菜肴类型</param>
        /// <param name="top">前几条记录</param>
        /// <returns>菜肴集合</returns>
        public IList<Item> SelectSubItem(int type,int top)
        {
            try
            {
                return itemop.SelectItem(type,top);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 根据菜肴编号返回一个菜肴信息
        /// </summary>
        /// <param name="systemId">菜肴编号</param>
        /// <returns>菜肴对象</returns>
        public Item SelectOneItem(long systemId)
        {
            try
            {
                return itemop.SelectOneItem(systemId);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 随机读取前TOP个菜肴
        /// </summary>
        /// <param name="top">前几个</param>
        /// <returns>菜肴集合</returns>
        public IList<Item> SelectRandom(int top)
        {
            try
            {
                return itemop.SelectItemTop(top);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IList<Item> SelectHotItems()
        {
            try
            {
                return itemop.SelectHotItems();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

    }
}
