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.Role
{
    public interface IRoleService
    {
        object GetAll();
        object FindAllOrActiveMenus();
        object GetById(roleModel data);
        object getActionLst();
        int Add(roleModel data);
        int Edit(roleModel data);
        int Delete(roleModel data);
    }
    public class RoleService : IRoleService
    {
        MasterRepository oMasterRepository = new MasterRepository();
        CommonRepository oCommonRepository = new CommonRepository();
        //code to retrieve list of all active role list
        public object GetAll()
        {
            return oMasterRepository.GetAll("role");
        }
        //code to retrieve list of all records
        public object FindAllOrActiveMenus()
        {
            return oMasterRepository.GetActive("menu");
        }
        //code to retrieve list of actions available 
        public object getActionLst()
        {
            return oCommonRepository.getActionList();
        }
        //Code to add new role details 
        public int Add(roleModel data)
        {
            if (string.IsNullOrEmpty(data.rolename))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.add(data, "role");
            return retval;
        }

        //code to update role details
        public int Edit(roleModel data)
        {
            if (string.IsNullOrEmpty(data.rolename))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.Edit(data, "role");
            return retval;
        }
        //code to retrieve list of all records
        public object GetById(roleModel data)
        {
            string input = JsonConvert.SerializeObject(data);
            return oMasterRepository.GetById("role", input);
        }

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

    }
}
