using System;
using WK_KLI_LAPS_Service.App_Data;
using WK_KLI_LAPS_Service.Models.Master;

namespace WK_KLI_LAPS_Service.Controllers.Master.ChapterType
{
    public interface IChapterTypeService
    {
        object GetAll();
        object GetActiveChapterType();
        int Add(chaptertypeModel data);
        int Edit(chaptertypeModel data);
        int Delete(chaptertypeModel data);
    }

    public class ChapterTypeService : IChapterTypeService
    {
        MasterRepository oMasterRepository = new MasterRepository();

        //code to retrieve list of all records
        public object GetAll()
        {

            return oMasterRepository.GetAll("chaptertype");
        }

        //code to retrieve list of active records
        public object GetActiveChapterType()
        {

            return oMasterRepository.GetActive("chaptertype");
        }

        //Code to add data
        public int Add(chaptertypeModel data)
        {
            if (string.IsNullOrEmpty(data.chaptertype))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.add(data, "chaptertype");
            return retval;

        }

        //code to update data
        public int Edit(chaptertypeModel data)
        {
            if (string.IsNullOrEmpty(data.chaptertype))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.Edit(data, "chaptertype");
            return retval;
        }

        //code to activate or deactivate record
        public int Delete(chaptertypeModel data)
        {
            int retval = oMasterRepository.Delete(data, "chaptertype");
            return retval;
        }
    }
}
