/// <summary>
    ///To Get all List of Applications From Device which are currently installed on device to Admin(Database)
    /// </summary>
    /// <param name="Ar"></param>
    /// <returns></returns>
    public HttpResponseMessage sendInstalledApps(SendInstalledApps SI)
    {
        ar = new WebApiResponse();
        try
        {
            string qry = "select * from MDM_DeviceMaster where DeviceID='" + SI.uuid + "'";
            dr = databaseHelper.getDataReader(qry);
            if (dr.Read())
            {
                InstalledApp IA = new InstalledApp();
                IA.Device    = dr["DeviceID"].ToString();
                IA.CreatedBy = 1;
                IA.UpdatedBy = 1;
                var list = SI.applications;
                if (!dr.IsClosed)
                {
                    dr.Close();
                }

                qry = "select * from MDM_InstalledApps where DeviceID='" + SI.uuid + "'";
                dr  = databaseHelper.getDataReader(qry);
                if (dr.Read())
                {
                    if (!dr.IsClosed)
                    {
                        dr.Close();
                    }

                    qry = "Delete from MDM_InstalledApps where DeviceID='" + SI.uuid + "'";

                    rcnt = databaseHelper.ExecuteQuery(qry);
                }

                if (!dr.IsClosed)
                {
                    dr.Close();
                }

                foreach (var c in list)
                {
                    //Check that application package exist in installed apps(accessible application db) if not then insert application details
                    #region Accessible Apps //Check Application Package in (Accessible Apps database)/Installed apps if not then Add

                    /*qry = "select * from MDM_AccessibleApplication where ApplicationPackage='"+c.applicationPackage+"'";
                     * dr = databaseHelper.getDataReader(qry);
                     * if (!dr.Read())
                     * {
                     * if (!dr.IsClosed)
                     *     dr.Close();
                     *
                     * qry = "insert into MDM_AccessibleApplication(ApplicationPackage,ApplicationName,CreatedDate)values('"+c.applicationPackage+"','"+c.applicationName+"','"+DateTime.Now+"')";
                     *
                     * rcnt = databaseHelper.ExecuteQuery(qry);
                     * }*/
                    #endregion
                    if (c.applicationName == null)//if application name recieved null then insert application package as name also
                    {
                        IA.ApplicationName = c.applicationPackage;
                    }
                    else
                    {
                        IA.ApplicationName = c.applicationName;
                    }

                    IA.ApplicationPackage = c.applicationPackage;
                    IA.CreatedDate        = c.installedOn;
                    IA.UpdatedDate        = DateTime.Now;
                    IA.isDownloaded       = c.isDownloaded;
                    IA.applicationVersion = c.applicationVersion;
                    IA.applicationSize    = c.applicationSize;
                    qry = "insert into MDM_InstalledApps(DeviceID,CreatedBy,UpdatedBy,ApplicationName,ApplicationPackage,CreatedDate,UpdatedDate,isDownloaded,ApplicationVersion,ApplicationSize) values('" + IA.Device + "'," + IA.CreatedBy + "," + IA.UpdatedBy + ",'" + IA.ApplicationName + "','" + IA.ApplicationPackage + "','" + IA.CreatedDate.ToString("yyyy-MM-dd HH:mm:ss") + "','" + IA.UpdatedDate.ToString("yyyy-MM-dd HH:mm:ss") + "'," + IA.isDownloaded + ",'" + IA.applicationVersion + "','" + IA.applicationSize + "')";

                    //linfo.LogFile(enLogType.INFO, qry, "rizwan");

                    rcnt = databaseHelper.ExecuteQuery(qry);

                    ar.errorCode += c.applicationPackage + " Added Successfully";
                }
                ar.response = true;
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, ar);

                qry  = "delete from MDM_PushNotification where DeviceID='" + SI.uuid + "' and Command='Update Application List'";
                rcnt = databaseHelper.ExecuteQuery(qry);

                return(response);
            }
            else
            {
                ar.errorCode = "Authentication Failed";
                ar.response  = false;
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.PartialContent, ar);
                return(response);
            }
        }
        catch (Exception ex)
        {
            linfo.LogFile(enLogType.EXCEPTION, ex.Message + "Problem in SendInstalledApp", null);
        }
        finally
        {
            if (dr != null && !dr.IsClosed)
            {
                dr.Close();
            }
        }
        return(null);
    }
    /// <summary>
    ///To Get all List of Applications From Device which are currently installed on device to Admin(Database)
    /// </summary>
    /// <param name="Ar"></param>
    /// <returns></returns>
    public HttpResponseMessage sendInstalledApps(SendInstalledApps SI)
    {
        ar = new WebApiResponse();        
        try
        {
            string qry = "select * from MDM_DeviceMaster where DeviceID='" + SI.uuid + "'";
            dr = databaseHelper.getDataReader(qry);
            if (dr.Read())
            {
                InstalledApp IA = new InstalledApp();
                IA.Device = dr["DeviceID"].ToString();
                IA.CreatedBy = 1;
                IA.UpdatedBy = 1;
                var list = SI.applications;
                if (!dr.IsClosed)
                    dr.Close();

                qry = "select * from MDM_InstalledApps where DeviceID='" + SI.uuid + "'";
                dr = databaseHelper.getDataReader(qry);
                if (dr.Read())
                {
                    if (!dr.IsClosed)
                        dr.Close();

                    qry = "Delete from MDM_InstalledApps where DeviceID='" + SI.uuid + "'";

                    rcnt = databaseHelper.ExecuteQuery(qry);

                }

                if (!dr.IsClosed)
                    dr.Close();

                foreach (var c in list)
                {
                    //Check that application package exist in installed apps(accessible application db) if not then insert application details
                    #region Accessible Apps //Check Application Package in (Accessible Apps database)/Installed apps if not then Add

                    /*qry = "select * from MDM_AccessibleApplication where ApplicationPackage='"+c.applicationPackage+"'";
                   dr = databaseHelper.getDataReader(qry);
                   if (!dr.Read())
                   {
                       if (!dr.IsClosed)
                           dr.Close();

                       qry = "insert into MDM_AccessibleApplication(ApplicationPackage,ApplicationName,CreatedDate)values('"+c.applicationPackage+"','"+c.applicationName+"','"+DateTime.Now+"')";

                       rcnt = databaseHelper.ExecuteQuery(qry);
                   }*/
                    #endregion
                    if (c.applicationName == null)//if application name recieved null then insert application package as name also
                    {
                        IA.ApplicationName = c.applicationPackage;
                    }
                    else
                    {
                        IA.ApplicationName = c.applicationName;
                    }

                    IA.ApplicationPackage = c.applicationPackage;
                    IA.CreatedDate = c.installedOn;
                    IA.UpdatedDate = DateTime.Now;
                    IA.isDownloaded = c.isDownloaded;
                    IA.applicationVersion = c.applicationVersion;
                    IA.applicationSize = c.applicationSize;
                    qry = "insert into MDM_InstalledApps(DeviceID,CreatedBy,UpdatedBy,ApplicationName,ApplicationPackage,CreatedDate,UpdatedDate,isDownloaded,ApplicationVersion,ApplicationSize) values('" + IA.Device + "'," + IA.CreatedBy + "," + IA.UpdatedBy + ",'" + IA.ApplicationName + "','" + IA.ApplicationPackage + "','" + IA.CreatedDate.ToString("yyyy-MM-dd HH:mm:ss") + "','" + IA.UpdatedDate.ToString("yyyy-MM-dd HH:mm:ss") + "'," + IA.isDownloaded + ",'" + IA.applicationVersion + "','" + IA.applicationSize + "')";

                    //linfo.LogFile(enLogType.INFO, qry, "rizwan");

                    rcnt = databaseHelper.ExecuteQuery(qry);

                    ar.errorCode += c.applicationPackage + " Added Successfully";
                }
                ar.response = true;
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, ar);

                qry = "delete from MDM_PushNotification where DeviceID='" + SI.uuid + "' and Command='Update Application List'";
                rcnt = databaseHelper.ExecuteQuery(qry);

                return response;
            }
            else
            {
                ar.errorCode = "Authentication Failed";
                ar.response = false;
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.PartialContent, ar);
                return response;
            }
        }
        catch (Exception ex)
        {
            linfo.LogFile(enLogType.EXCEPTION, ex.Message + "Problem in SendInstalledApp", null);                                    
        }
        finally
        {
            if (dr != null && !dr.IsClosed)
                dr.Close();
        }
        return null;
    }