public List<tblClientSiteDevice> GetAllClientSiteDevice(int ClientID, int pageNumber, int pageSize, int sortColumnIndex, string sortOrder, string searchText, ref int totalRecords)
        {
            List<tblClientSiteDevice> lstAllClientSiteDevice = new List<tblClientSiteDevice>();

            int errNum = 0;
            string errDesc = "";

            DataAccess.resetParams();
            DataAccess.addSqlParam("@ClientID", ParameterDirection.Input, 16, MySqlDbType.Int32, ClientID);
            DataAccess.addSqlParam("@pageNumber", ParameterDirection.Input, 16, MySqlDbType.Int32, pageNumber);
            DataAccess.addSqlParam("@pageRecord", ParameterDirection.Input, 16, MySqlDbType.Int32, pageSize);
            DataAccess.addSqlParam("@sortColumnIndex", ParameterDirection.Input, 16, MySqlDbType.Int32, sortColumnIndex);
            DataAccess.addSqlParam("@searchOrder", ParameterDirection.Input, 4, MySqlDbType.VarChar, sortOrder);
            DataAccess.addSqlParam("@searchText", ParameterDirection.Input, 100, MySqlDbType.VarChar, searchText);

            DataSet ds = DataAccess.ExecuteDataSet(GET_ALL_CLIENT_SITE_DEVICE, ref errNum, ref errDesc);
            tblClientSiteDevice ClientsiteDevice = new tblClientSiteDevice();
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                DataTable dtClientsiteDevice = ds.Tables[0];
                DataTable dtTotalRecords = ds.Tables[1];
                totalRecords = Common.ConvertToInt(dtTotalRecords.Rows[0], "TotalRecords");
                if (dtClientsiteDevice != null && dtClientsiteDevice.Rows.Count > 0)
                {
                    for (int i = 0; i < dtClientsiteDevice.Rows.Count; i++)
                    {
                        DataRow dr = dtClientsiteDevice.Rows[i];
                        ClientsiteDevice = new tblClientSiteDevice();
                        ClientsiteDevice.DeviceID = Common.ConvertToInt(dr, "ClientSiteDeviceID");
                        ClientsiteDevice.ClientID = Common.ConvertToInt(dr, "ClientID");
                        ClientsiteDevice.DeviceType = new DeviceType();
                        ClientsiteDevice.DeviceType.ID = Common.ConvertToInt(dr, "DeviceType");
                        ClientsiteDevice.DeviceType.Name = LookUpValue.GetDeviceType(ClientsiteDevice.DeviceType.ID.Value);
                        ClientsiteDevice.DeviceIDFromRMMTool = Common.ConvertToString(dr, "DeviceIDFromRMMTool");
                        ClientsiteDevice.DeviceDescription = Common.ConvertToString(dr, "Description");
                        ClientsiteDevice.UserName = Common.ConvertToString(dr, "UserName");
                        ClientsiteDevice.Password = Common.ConvertToString(dr, "Password");
                        ClientsiteDevice.MiscInfo = Common.ConvertToString(dr, "MiscInfo");
                        ClientsiteDevice.IsAccessPolicy = new PolicyType();
                        ClientsiteDevice.IsAccessPolicy.Name = Common.ConvertToString(dr, "AccessPolicyName");
                        ClientsiteDevice.IsMaintenancePolicy = new PolicyType();
                        ClientsiteDevice.IsMaintenancePolicy.Name = Common.ConvertToString(dr, "MaintenancePolicyName");
                        ClientsiteDevice.IsPatchingPolicy = new PolicyType();
                        ClientsiteDevice.IsPatchingPolicy.Name = Common.ConvertToString(dr, "PatchingPolicyName");
                        ClientsiteDevice.IsAntiVirus = new PolicyType();
                        ClientsiteDevice.IsAntiVirus.Name = Common.ConvertToString(dr, "AVPolicy");

                        ClientsiteDevice.IsRMMTool = new PolicyType();
                        ClientsiteDevice.IsRMMTool.Name = Common.ConvertToString(dr, "ToolInfomationName");
                        ClientsiteDevice.IsBackUpPolicy = new PolicyType();
                        ClientsiteDevice.IsBackUpPolicy.Name = Common.ConvertToString(dr, "BackupPolicyName");
                        lstAllClientSiteDevice.Add(ClientsiteDevice);
                    }
                }
            }
            return lstAllClientSiteDevice;
        }
        public JsonResult Device(tblClientSiteDevice model)
        {
            try
            {
                BLClientSiteDevice clientSiteDeviceBL = new BLClientSiteDevice();
                model.CustomerID = SessionHelper.UserSession.CustomerID;
                clientSiteDeviceBL.SaveClientSiteDevice(model);
            }
            catch
            {
                ModelState.AddModelError("", "Error occurred while saving device information.");
                return Json(new { errors = KeyValue.GetErrorsFromModelState(ViewData) });
            }

            return Json(new { success = true, ClientID = model.ClientID });
        }
        public tblClientSiteDevice GetClientSiteDevice(int ClientSiteDeviceID, int CustomerID)
        {
            int errNum = 0;
            string errDesc = "";

            DataAccess.resetParams();
            DataAccess.addSqlParam("@ClientSiteDeviceID", ParameterDirection.Input, 16, MySqlDbType.Int32, ClientSiteDeviceID);
            DataAccess.addSqlParam("@CustomerID", ParameterDirection.Input, 16, MySqlDbType.Int32, CustomerID);
            DataSet ds = DataAccess.ExecuteDataSet(GET_CLIENT_SITE_DEVICE, ref errNum, ref errDesc);
            tblClientSiteDevice ClientsiteDevice = new tblClientSiteDevice();
            if (ds != null && ds.Tables.Count > 0)
            {
                DataTable dtClientsiteDevice = ds.Tables[0];
                if (dtClientsiteDevice != null && dtClientsiteDevice.Rows.Count > 0)
                {
                    DataRow dr = dtClientsiteDevice.Rows[0];
                    ClientsiteDevice.DeviceID = Common.ConvertToInt(dr, "ClientSiteDeviceID");
                    ClientsiteDevice.ClientID = Common.ConvertToInt(dr, "ClientID");
                    ClientsiteDevice.DeviceType = new DeviceType();
                    ClientsiteDevice.DeviceType.ID = Common.ConvertToInt(dr, "DeviceType");
                    ClientsiteDevice.DeviceType.Name = LookUpValue.GetDeviceType(ClientsiteDevice.DeviceType.ID.Value);
                    ClientsiteDevice.DeviceIDFromRMMTool = Common.ConvertToString(dr, "DeviceIDFromRMMTool");
                    ClientsiteDevice.DeviceDescription = Common.ConvertToString(dr, "Description");
                    ClientsiteDevice.UserName = Common.ConvertToString(dr, "UserName");
                    ClientsiteDevice.Password = Common.ConvertToString(dr, "Password");
                    ClientsiteDevice.MiscInfo = Common.ConvertToString(dr, "MiscInfo");
                    ClientsiteDevice.IsAccessPolicy = new PolicyType();
                    ClientsiteDevice.IsAccessPolicy.ID = Common.ConvertToInt(dr, "PolicyID");
                    ClientsiteDevice.IsAccessPolicy.Name = LookUpValue.GetOptionType(ClientsiteDevice.IsAccessPolicy.ID.Value);
                    ClientsiteDevice.IsMaintenancePolicy = new PolicyType();
                    ClientsiteDevice.IsMaintenancePolicy.ID = Common.ConvertToInt(dr, "MaintenancePolicyID");
                    ClientsiteDevice.IsMaintenancePolicy.Name = LookUpValue.GetOptionType(ClientsiteDevice.IsMaintenancePolicy.ID.Value);
                    ClientsiteDevice.IsPatchingPolicy = new PolicyType();
                    ClientsiteDevice.IsPatchingPolicy.ID = Common.ConvertToInt(dr, "PatchingPolicyID");
                    ClientsiteDevice.IsPatchingPolicy.Name = LookUpValue.GetOptionType(ClientsiteDevice.IsPatchingPolicy.ID.Value);
                    ClientsiteDevice.IsAntiVirus = new PolicyType();
                    ClientsiteDevice.IsAntiVirus.ID = Common.ConvertToInt(dr, "AntiVirusID");
                    ClientsiteDevice.IsAntiVirus.Name = LookUpValue.GetOptionType(ClientsiteDevice.IsAntiVirus.ID.Value);
                    ClientsiteDevice.IsBackUpPolicy = new PolicyType();
                    ClientsiteDevice.IsBackUpPolicy.ID = Common.ConvertToInt(dr, "BackUpPolicyID");
                    ClientsiteDevice.IsBackUpPolicy.Name = LookUpValue.GetOptionType(ClientsiteDevice.IsBackUpPolicy.ID.Value);
                    ClientsiteDevice.IsRMMTool = new PolicyType();
                    ClientsiteDevice.IsRMMTool.ID = Common.ConvertToInt(dr, "ToolID");
                    ClientsiteDevice.IsRMMTool.Name = LookUpValue.GetOptionType(ClientsiteDevice.IsRMMTool.ID.Value);
                }
            }
            return ClientsiteDevice;
        }
        public int SaveClientSiteDevice(tblClientSiteDevice clientSitedevice)
        {
            int errorNum = 0;
            string errorDesc = "";
            DataAccess.resetParams();
            DataAccess.addSqlParam("@ClientSiteDeviceID", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSitedevice.DeviceID);
            DataAccess.addSqlParam("@ClientID", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSitedevice.ClientID);
            DataAccess.addSqlParam("@DeviceType", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSitedevice.DeviceType.ID);
            DataAccess.addSqlParam("@Description", ParameterDirection.Input, 100, MySqlDbType.VarChar, clientSitedevice.DeviceDescription);
            DataAccess.addSqlParam("@DeviceIDFromRMMTool", ParameterDirection.Input, 100, MySqlDbType.VarChar, clientSitedevice.DeviceIDFromRMMTool);
            DataAccess.addSqlParam("@MiscInfo", ParameterDirection.Input, 200, MySqlDbType.VarChar, clientSitedevice.MiscInfo);
            DataAccess.addSqlParam("@UserName", ParameterDirection.Input, 100, MySqlDbType.VarChar, clientSitedevice.UserName);
            DataAccess.addSqlParam("@Password", ParameterDirection.Input, 100, MySqlDbType.VarChar, clientSitedevice.Password);
            DataAccess.addSqlParam("@AccessPolicyID", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSitedevice.IsAccessPolicy.ID);
            DataAccess.addSqlParam("@MaintenancePolicyID", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSitedevice.IsMaintenancePolicy.ID);
            DataAccess.addSqlParam("@PatchingPolicyID", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSitedevice.IsPatchingPolicy.ID);
            DataAccess.addSqlParam("@AntiVirusID", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSitedevice.IsAntiVirus == null ? 0:clientSitedevice.IsAntiVirus.ID);
            DataAccess.addSqlParam("@BackUpPolicyID", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSitedevice.IsBackUpPolicy == null ? 0:clientSitedevice.IsBackUpPolicy.ID);
            DataAccess.addSqlParam("@ToolID", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSitedevice.IsRMMTool.ID);
            DataAccess.addSqlParam("@Isactive", ParameterDirection.InputOutput, 16, MySqlDbType.Int16, 1);
            DataAccess.addSqlParam("@Identity", ParameterDirection.InputOutput, 16, MySqlDbType.Int32);

            DataAccess.ExecuteNonQuery(SET_CLIENT_SITE_DEVICE, ref errorNum, ref errorDesc);
            return Common.ConvertToInt(DataAccess.getSQLParam("@Identity").ToString());
        }