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

namespace WK_KLI_LAPS_Service.Controllers.Master.JobMeta
{
    public interface IJobMetaService
    {
        object GetAll();
        object GetActiveJobMeta();
        int Add(jobmetaModel data);
        int Edit(jobmetaModel data);
        int Delete(jobmetaModel data);
        object Get_projectdeflst(jobmetaModel data);
    }
    public class JobMetaService : IJobMetaService
    {
        MasterRepository oMasterRepository = new MasterRepository();

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

            return oMasterRepository.GetAll("jobmeta");
        }

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

            return oMasterRepository.GetActive("jobmeta");
        }

        public object Get_projectdeflst(jobmetaModel data)
        {
            string input = JsonConvert.SerializeObject(data);
            return oMasterRepository.Master_select("spjobmetamasterselect", input, "getprojectdefintionlst");
        }

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

        }

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

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