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.CustomerContact
{
    public interface ICustomerContactService
    {
        object GetAll();
        object GetActiveCustomerContact();
        int Add(customercontactModel data);
        int Edit(customercontactModel data);
        int Delete(customercontactModel data);
    }
    public class CustomerContactService : ICustomerContactService
    {
        CommonRepository oCommonRepository = new CommonRepository();

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

            return oCommonRepository.ExecuteSP_ReturnList("spcustomercontactselect", "{}", "getall");
        }

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

            return oCommonRepository.ExecuteSP_ReturnList("spcustomercontactselect", "{}", "getactive");
        }

        //Code to add data
        public int Add(customercontactModel data)
        {
            if (data.customerid < 0)
                throw new Exception("Value should not be empty");
            int retval = oCommonRepository.ExecuteSP_ReturnInt("spcustomercontact", data, "insert", "Inserting Customer contact");
            return retval;

        }

        //code to update data
        public int Edit(customercontactModel data)
        {
            if (data.customerid < 0)
                throw new Exception("Value should not be empty");
            int retval = oCommonRepository.ExecuteSP_ReturnInt("spcustomercontact", data, "update", "Updating Customer contact");
            return retval;
        }

        //code to activate or deactivate record
        public int Delete(customercontactModel data)
        {
            int retval = oCommonRepository.ExecuteSP_ReturnInt("spcustomercontact", data, "activeordeactive", "Activating or deactivating Customer contact");
            return retval;
        }
    }
}
