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.Customer
{
    public interface ICustomerService
    {
        object GetAll();
        object GetActiveCustomer();
        int Add(customerModel data);
        int Edit(customerModel data);
        int Delete(customerModel data);
    }
    public class CustomerService : ICustomerService
    {
        MasterRepository oMasterRepository = new MasterRepository();

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

            return oMasterRepository.GetAll("customer");
        }

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

            return oMasterRepository.GetActive("customer");
        }

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

        }

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

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