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

namespace WK_KLI_LAPS_Service.Controllers.Master.Department
{
    public interface IDepartmentService
    {
        object GetAll();
        object GetActiveDepartment();
        int Add(departmentModel data);
        int Edit(departmentModel data);
        int Delete(departmentModel data);
        object GetByMappedUser();
    }

    public class DepartmentService : IDepartmentService
    {
        MasterRepository oMasterRepository = new MasterRepository();
        CommonRepository oCommonRepository = new CommonRepository();

        //code to retrieve list of all records
        public object GetAll()
        {
            return oMasterRepository.GetAll("department");
        }

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

            return oMasterRepository.GetActive("department");
        }

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

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

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

        public object GetByMappedUser()
        {
            return oCommonRepository.ExecuteSP_ReturnList("spdepartmentmasterselect", null, "getbymappeduser");
        }
    }
}
