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

namespace WK_KLI_LAPS_Service.Controllers.Master.AllocationType
{
    public interface IAllocationTypeService
    {
        object GetAll();
        object GetActiveAllocationType();
        int Add(allocationtypeModel data);
        int Edit(allocationtypeModel data);
        int Delete(allocationtypeModel data);
    }
    public class AllocationTypeService : IAllocationTypeService
    {
        MasterRepository oMasterRepository = new MasterRepository();

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

            return oMasterRepository.GetAll("allocationtype");
        }

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

            return oMasterRepository.GetActive("allocationtype");
        }

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

        }

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

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