public HttpResponseMessage getAccessibleWebsites(postmethod pm)
    {
        getAccessibleWebsites gaw = new getAccessibleWebsites();
        List <weblist>        wl  = new List <weblist>();

        try
        {
            string qry = "select * from MDM_DeviceMaster where DeviceID='" + pm.uuid + "'";
            dr = databaseHelper.getDataReader(qry);
            if (dr.Read())
            {
                string UserId = dr["UserId"].ToString().ToUpper();

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

                string Designation = null;

                qry = "select UserType from AppUsers where UserName='******'";
                dr  = databaseHelper.getDataReader(qry);
                if (dr.Read())
                {
                    Designation = dr["UserType"].ToString().ToUpper();
                }

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

                qry    = "Select WebsiteName,UserId,UserDesignation from MDM_AccessibleWebsite";
                dtable = databaseHelper.getDataTable(qry);
                List <weblist> website = new List <weblist>();
                foreach (DataRow drow in dtable.Rows)
                {
                    //linfo.LogFile(enLogType.QUERY, "drow[UserId] = " + drow["UserId"] + " drow[UserDesignation] = "+drow["UserDesignation"]+" UserId = "+UserId+". UserDesignation = "+Designation+"","rizwan");
                    if (drow["UserId"] == DBNull.Value && drow["UserDesignation"] == DBNull.Value) // Default Application
                    {
                        website.Add(new weblist
                        {
                            WebsiteName = (drow["WebsiteName"] == DBNull.Value) ? "" : drow["WebsiteName"].ToString()
                        });
                        //linfo.LogFile(enLogType.INFO, "UserID,UserDesignation are null. WebsiteName = " + drow["WebsiteName"] + "", "rizwan");
                    }
                    else if (drow["UserId"] != DBNull.Value && drow["UserDesignation"] != DBNull.Value && drow["UserId"].ToString().Length > 0 && drow["UserDesignation"].ToString().Length > 0 && drow["UserID"].ToString().Split(',').Contains(UserId) && drow["UserDesignation"].ToString().Split(',').Contains(UserId))// Application Valid only to specific user.
                    {
                        website.Add(new weblist
                        {
                            WebsiteName = (drow["WebsiteName"] == DBNull.Value) ? "" : drow["WebsiteName"].ToString()
                        });
                        //linfo.LogFile(enLogType.INFO, "UserId and UserDesignation are not null . drow[UserId] = " + drow["UserId"] + " drow[UserDesignation] = " + drow["UserDesignation"] + " UserId = " + UserId + ". UserDesignation = " + Designation + "", "rizwan");
                    }
                    else if (drow["UserId"] != DBNull.Value && drow["UserDesignation"] == DBNull.Value && drow["UserId"].ToString().Length > 0 && drow["UserId"].ToString().Split(',').Contains(UserId)) // Accessible to specific user.
                    {
                        website.Add(new weblist
                        {
                            WebsiteName = (drow["WebsiteName"] == DBNull.Value) ? "" : drow["WebsiteName"].ToString()
                        });
                        // linfo.LogFile(enLogType.INFO, "Userid is not null. drow[UserId] = "+drow["UserId"]+" and Userid="+UserId+". drow[UserDesignation] = "+drow["UserDesignation"]+" and Designation = "+Designation+" WebsiteName = " + drow["WebsiteName"] + "", "rizwan");
                    }
                    else if (drow["UserDesignation"] != DBNull.Value && drow["UserId"] == DBNull.Value && drow["UserDesignation"].ToString().Length > 0 && drow["UserDesignation"].ToString().Contains(Designation))//accessible to user of specific designation
                    {
                        website.Add(new weblist
                        {
                            WebsiteName = (drow["WebsiteName"] == DBNull.Value) ? "" : drow["WebsiteName"].ToString()
                        });

                        //linfo.LogFile(enLogType.INFO, "UserDesignation is not null. drow[UserId] = " + drow["UserId"] + " and Userid=" + UserId + ". drow[UserDesignation] = " + drow["UserDesignation"] + " and Designation = " + Designation + " WebsiteName = " + drow["WebsiteName"] + "", "rizwan");
                    }
                }

                gaw.websiteurl = website;
                gaw.response   = true;
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, gaw);

                qry  = "delete from MDM_PushNotification where DeviceID='" + pm.uuid + "' and Command='Get Accessible Website'";
                rcnt = databaseHelper.ExecuteQuery(qry);

                return(response);
            }
            else
            {
                ar           = new WebApiResponse();
                ar.errorCode = "Authentication failed";
                ar.response  = false;
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, ar);
                return(response);
            }
        }
        catch (Exception ex)
        {
            linfo.LogFile(enLogType.EXCEPTION, "Problem in getAccessibleWebsites function." + ex.Message + "", null);
        }
        finally
        {
            if (dr != null && !dr.IsClosed)
            {
                dr.Close();
            }
        }
        return(null);
    }
    public HttpResponseMessage getAccessibleWebsites(postmethod pm)
    {        
        getAccessibleWebsites gaw = new getAccessibleWebsites();
        List<weblist> wl = new List<weblist>();
        try
        {
            string qry = "select * from MDM_DeviceMaster where DeviceID='" + pm.uuid + "'";
            dr = databaseHelper.getDataReader(qry);
            if (dr.Read())
            {
                string UserId = dr["UserId"].ToString().ToUpper();

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

                string Designation = null;

                qry = "select UserType from AppUsers where UserName='******'";
                dr = databaseHelper.getDataReader(qry);
                if (dr.Read())
                {
                    Designation = dr["UserType"].ToString().ToUpper();
                }

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

                qry = "Select WebsiteName,UserId,UserDesignation from MDM_AccessibleWebsite";
                dtable = databaseHelper.getDataTable(qry);
                List<weblist> website = new List<weblist>();
                foreach (DataRow drow in dtable.Rows)
                {
                    //linfo.LogFile(enLogType.QUERY, "drow[UserId] = " + drow["UserId"] + " drow[UserDesignation] = "+drow["UserDesignation"]+" UserId = "+UserId+". UserDesignation = "+Designation+"","rizwan");
                    if (drow["UserId"] == DBNull.Value && drow["UserDesignation"] == DBNull.Value) // Default Application
                    {
                        website.Add(new weblist
                        {
                            WebsiteName = (drow["WebsiteName"] == DBNull.Value) ? "" : drow["WebsiteName"].ToString()
                        });
                        //linfo.LogFile(enLogType.INFO, "UserID,UserDesignation are null. WebsiteName = " + drow["WebsiteName"] + "", "rizwan");
                    }
                    else if (drow["UserId"] != DBNull.Value && drow["UserDesignation"] != DBNull.Value && drow["UserId"].ToString().Length > 0 && drow["UserDesignation"].ToString().Length > 0 && drow["UserID"].ToString().Split(',').Contains(UserId) && drow["UserDesignation"].ToString().Split(',').Contains(UserId))// Application Valid only to specific user.
                    {
                        website.Add(new weblist
                        {
                            WebsiteName = (drow["WebsiteName"] == DBNull.Value) ? "" : drow["WebsiteName"].ToString()
                        });
                        //linfo.LogFile(enLogType.INFO, "UserId and UserDesignation are not null . drow[UserId] = " + drow["UserId"] + " drow[UserDesignation] = " + drow["UserDesignation"] + " UserId = " + UserId + ". UserDesignation = " + Designation + "", "rizwan");
                    }
                    else if (drow["UserId"] != DBNull.Value && drow["UserDesignation"] == DBNull.Value && drow["UserId"].ToString().Length > 0 && drow["UserId"].ToString().Split(',').Contains(UserId)) // Accessible to specific user.
                    {
                        website.Add(new weblist
                        {
                            WebsiteName = (drow["WebsiteName"] == DBNull.Value) ? "" : drow["WebsiteName"].ToString()
                        });
                       // linfo.LogFile(enLogType.INFO, "Userid is not null. drow[UserId] = "+drow["UserId"]+" and Userid="+UserId+". drow[UserDesignation] = "+drow["UserDesignation"]+" and Designation = "+Designation+" WebsiteName = " + drow["WebsiteName"] + "", "rizwan");
                    }
                    else if (drow["UserDesignation"] != DBNull.Value && drow["UserId"] == DBNull.Value && drow["UserDesignation"].ToString().Length > 0 && drow["UserDesignation"].ToString().Contains(Designation))//accessible to user of specific designation
                    {
                        website.Add(new weblist
                        {
                            WebsiteName = (drow["WebsiteName"] == DBNull.Value) ? "" : drow["WebsiteName"].ToString()
                        });

                        //linfo.LogFile(enLogType.INFO, "UserDesignation is not null. drow[UserId] = " + drow["UserId"] + " and Userid=" + UserId + ". drow[UserDesignation] = " + drow["UserDesignation"] + " and Designation = " + Designation + " WebsiteName = " + drow["WebsiteName"] + "", "rizwan");
                    }
                }

                gaw.websiteurl = website;
                gaw.response = true;
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, gaw);

                qry = "delete from MDM_PushNotification where DeviceID='" + pm.uuid + "' and Command='Get Accessible Website'";
                rcnt = databaseHelper.ExecuteQuery(qry);

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