//Get
        public ActionResult Device(int? DeviceID, int? ClientID)
        {
            BindLookups();

            List<tblMaintenancePolicy> Manitenancepoly = new List<tblMaintenancePolicy>();
            List<tblAccessPolicy> Accesspoly = new List<tblAccessPolicy>();
            List<tblAntiVirusPolicy> Antiviruspoly = new List<tblAntiVirusPolicy>();
            List<tblBackUpPolicy> Backuppoly = new List<tblBackUpPolicy>();
            List<tblPatchingPolicy> PatchingPoly = new List<tblPatchingPolicy>();
            List<tbltoolInfomation> ToolInfoPoly = new List<tbltoolInfomation>();

            BLClientSiteDevice clientSiteDeviceBL = new BLClientSiteDevice();

            clientSiteDeviceBL.FillDropDownList(ref Manitenancepoly, ref Accesspoly, ref Antiviruspoly, ref Backuppoly, ref PatchingPoly, ref ToolInfoPoly);
            tblClientSiteDevice clientSiteDevice = clientSiteDeviceBL.GetClientSiteDevice(DeviceID.Value,SessionHelper.UserSession.CustomerID);
            clientSiteDevice.ClientID = ClientID.Value;

            ViewBag.Maintenancepoly = Manitenancepoly;
            ViewBag.Accesspoly = Accesspoly;
            ViewBag.Antiviruspoly = Antiviruspoly;
            ViewBag.Backuppoly = Backuppoly;
            ViewBag.PatchingPoly = PatchingPoly;
            ViewBag.ToolInfoPoly = ToolInfoPoly;
            if (Request.IsAjaxRequest())
                return PartialView(clientSiteDevice);
            else
                return View(clientSiteDevice);
        }
        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 });
        }
        //Get
        public JsonResult DeleteDevices(int? contactID)
        {
            BLClientSiteDevice clientBL = new BLClientSiteDevice();

            int? DeletionStatus = null;
            if (contactID != null && contactID.Value > 0)
            {
                DeletionStatus = clientBL.DelContact(contactID.Value);
            }
            if (DeletionStatus.Value == 0)
            {
                return Json(new { success = true, errDesc = "Device deleted successfully" }, JsonRequestBehavior.AllowGet);

            };

            return Json(new { errors = true, errDesc = "Device deletion failed" }, JsonRequestBehavior.AllowGet);
        }
        //GET
        public ActionResult ManageDevice(int? DeviceID)
        {
            BLClientSiteDevice customerBL = new BLClientSiteDevice();
            tblClientSiteDevice tblclientdevice = customerBL.GetClientSiteDevice(DeviceID.Value,SessionHelper.UserSession.CustomerID);
            List<KeyValue> lstKeyVal = new List<KeyValue>();

            //ToolTypeRT

            lstKeyVal.Add(new KeyValue() { Key = "User Name", Value = tblclientdevice.UserName });
            lstKeyVal.Add(new KeyValue() { Key = "Password", Value = tblclientdevice.Password });
            lstKeyVal.Add(new KeyValue() { Key = "Misc Information", Value = tblclientdevice.MiscInfo });

            if (Request.IsAjaxRequest())
                return PartialView("Detail", lstKeyVal);
            else
                return View("Detail", lstKeyVal);
        }
        //Get
        public ActionResult DeviceGridRecord(jQueryDataTableParamModel param)
        {
            int totalRecords = 0;

            var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
            var sortDirection = Request["sSortDir_0"]; // asc or desc

            int clientID = Common.ConvertToInt(Request["ClientID"].ToString());

            BLClientSiteDevice clientSiteDeviceBL = new BLClientSiteDevice();
            List<tblClientSiteDevice> lstClientSiteDevices = clientSiteDeviceBL.GetAllClientSiteDevice(clientID, param.iDisplayStart, param.iDisplayLength, sortColumnIndex, sortDirection, param.sSearch, ref totalRecords);

            var result = from c in lstClientSiteDevices
                         let DeviceTypeName = c.DeviceType.Name
                         let AccessPolicyName = c.IsAccessPolicy.Name
                         let MaintenancePolicyName = c.IsMaintenancePolicy.Name
                         let PatchingPolicyName = c.IsPatchingPolicy.Name
                         let AntiVirusPolicyName = c.IsAntiVirus.Name
                         let BackupPolicyName = c.IsBackUpPolicy.Name
                         let RMMToolName = c.IsRMMTool.Name
                         select new[] { c.DeviceIDFromRMMTool, DeviceTypeName, c.DeviceDescription, AccessPolicyName, MaintenancePolicyName,
                                       PatchingPolicyName , RMMToolName,c.MiscInfo,c.DeviceID.ToString() };

            return Json(new
            {
                sEcho = param.sEcho,
                iTotalRecords = totalRecords,
                iTotalDisplayRecords = totalRecords,
                aaData = result
            }, JsonRequestBehavior.AllowGet);
        }