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

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace WK_KLI_LAPS_Service.Controllers.Master.Unit
{
    public interface IUnitService
    {
        object GetAll();
        object GetActiveUnit();
        int Add(unitModel data);
        int Edit(unitModel data);
        int Delete(unitModel data);
    }
    public class UnitService : IUnitService
    {
        MasterRepository oMasterRepository = new MasterRepository();

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

            return oMasterRepository.GetAll("unit");
        }

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

            return oMasterRepository.GetActive("unit");
        }

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

        }

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

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