using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain;

namespace Service.Implement
{
	public class FaultTypeManager : GenericManagerBase<FaultType>, IFaultTypeManager
	{
		public Dao.IFaultRecordsRepository FaultRecordsRepository { get; set; }

        public IList<FaultType> LoadAllByPage(out long total, int page, int rows, string order, string sort, int hotelID)
		{
            return ((Dao.IFaultTypeRepository)(this.CurrentRepository)).LoadAllByPage(out total, page, rows, order, sort, hotelID).ToList();
		}

		public FaultType Get(string code)
		{
			return ((Dao.IFaultTypeRepository)(this.CurrentRepository)).Get(code);
		}

		public override void Delete(IList<object> idList)
		{
			if (idList != null && idList.Count > 0)
			{
				foreach (int id in idList)
				{
					if (FaultRecordsRepository.GetFaultsCount(id) > 0)
					{
						FaultType faultType = base.Get(id);
						throw new ApplicationException(String.Format("删除失败，请先清空类别为【{0}】的故障。", faultType.Name));
					}
				}

				base.Delete(idList);
			}
		}
	}
}
