using Newtonsoft.Json;
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.MailTemplate
{
    public interface IMailTemplateService
    {
        object GetAll();
        int Add(mailtemplateModel data);
        int Edit(mailtemplateModel data);
        int Delete(mailtemplateModel data);
        object GetById(mailtemplateModel data);
        object GetActiveTemplate();
    }
    public class MailTemplateService : IMailTemplateService
    {
        MasterRepository oMasterRepository = new MasterRepository();

        //code to retrieve list of all active mail template list
        public object GetAll()
        {
            return oMasterRepository.GetAll("mailtemplate");
        }
        //code to retrieve list of  active mail template list
        public object GetActiveTemplate()
        {
            return oMasterRepository.GetActive("mailtemplate");
        }
        //Code to add new role mail template 
        public int Add(mailtemplateModel data)
        {
            if (string.IsNullOrEmpty(data.mailtemplatename))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.add(data, "mailtemplate");
            return retval;
        }
        //code to update role details
        public int Edit(mailtemplateModel data)
        {
            if (string.IsNullOrEmpty(data.mailtemplatename))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.Edit(data, "mailtemplate");
            return retval;
        }
        //code to retrieve list of all records
        public object GetById(mailtemplateModel data)
        {
            string input = JsonConvert.SerializeObject(data);
            return oMasterRepository.GetById("mailtemplate", input);
        }

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

    }
}
