public HttpResponseMessage getAccessibleApps(postmethod pm) { getConfigurationDetails gc = new getConfigurationDetails(); getAccessibleApps gaa = new getAccessibleApps(); List <application> ga = new List <application>(); string qry = "select * from MDM_DeviceMaster where DeviceID='" + pm.uuid + "'"; dr = databaseHelper.getDataReader(qry); if (dr.Read()) { string UserId = dr["UserId"] != DBNull.Value ? dr["UserId"].ToString().ToUpper() : null; 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 ApplicationName,ApplicationPackage,UserId,UserDesignation from MDM_AccessibleApplication"; dtable = databaseHelper.getDataTable(qry); if (dtable.Rows.Count > 0) { 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 { ga.Add(new application { applicationName = (drow["ApplicationName"] == DBNull.Value) ? "" : drow["ApplicationName"].ToString(), applicationPackage = (drow["ApplicationPackage"] == DBNull.Value) ? "" : drow["ApplicationPackage"].ToString() }); //linfo.LogFile(enLogType.INFO, "UserID,UserDesignation are null. ApplicationName = " + drow["ApplicationName"] + " ApplicationPackage = "+drow["ApplicationPackage"]+"", "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. { ga.Add(new application { applicationName = (drow["ApplicationName"] == DBNull.Value) ? "" : drow["ApplicationName"].ToString(), applicationPackage = (drow["ApplicationPackage"] == DBNull.Value) ? "" : drow["ApplicationPackage"].ToString() }); //linfo.LogFile(enLogType.INFO, "Userid and UserDesignation are not null . drow[UserId] = " + drow["UserId"] + " and Userid=" + UserId + ". drow[UserDesignation] = " + drow["UserDesignation"] + " and Designation = " + Designation + " ApplicationName = " + drow["ApplicationName"] + " ApplicationPackage = " + drow["ApplicationPackage"] + "", "rizwan"); } else if (drow["UserId"] != DBNull.Value && drow["UserDesignation"] == DBNull.Value && drow["UserID"].ToString().Length > 0 && drow["UserID"].ToString().Split(',').Contains(UserId))// Application Valid only to specific user. { ga.Add(new application { applicationName = (drow["ApplicationName"] == DBNull.Value) ? "" : drow["ApplicationName"].ToString(), applicationPackage = (drow["ApplicationPackage"] == DBNull.Value) ? "" : drow["ApplicationPackage"].ToString() }); //linfo.LogFile(enLogType.INFO, "Userid is not null. drow[UserId] = " + drow["UserId"] + " and Userid=" + UserId + ". drow[UserDesignation] = " + drow["UserDesignation"] + " and Designation = " + Designation + " ApplicationName = " + drow["ApplicationName"] + " ApplicationPackage = " + drow["ApplicationPackage"] + "", "rizwan"); } else if (drow["UserDesignation"] != DBNull.Value && drow["UserId"] == DBNull.Value && drow["UserDesignation"].ToString().Length > 0 && drow["UserDesignation"].ToString().Split(',').Contains(Designation)) //application valid only to specific designation (multiple user can come to same designation) { ga.Add(new application { applicationName = (drow["ApplicationName"] == DBNull.Value) ? "" : drow["ApplicationName"].ToString(), applicationPackage = (drow["ApplicationPackage"] == DBNull.Value) ? "" : drow["ApplicationPackage"].ToString() }); //linfo.LogFile(enLogType.INFO, "UserDesignation is not null. drow[UserId] = " + drow["UserId"] + " and Userid=" + UserId + ". drow[UserDesignation] = " + drow["UserDesignation"] + " and Designation = " + Designation + " ApplicationName = " + drow["ApplicationName"] + " ApplicationPackage = " + drow["ApplicationPackage"] + "", "rizwan"); } } } gaa.applications = ga; #region Website list qry = "Select WebsiteName from MDM_AccessibleWebsite"; dtable = databaseHelper.getDataTable(qry); List <weblist> website = new List <weblist>(); foreach (DataRow drow in dtable.Rows) { website.Add(new weblist { WebsiteName = (drow["WebsiteName"] == DBNull.Value) ? "" : drow["WebsiteName"].ToString() }); } gaa.websiteurl = website; #endregion gaa.response = true; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, gaa); qry = "delete from MDM_PushNotification where DeviceID='" + pm.uuid + "' and Command='Get Accessible Apps'"; 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); } }
public HttpResponseMessage getAccessibleApps(postmethod pm) { getConfigurationDetails gc = new getConfigurationDetails(); getAccessibleApps gaa = new getAccessibleApps(); List<application> ga = new List<application>(); string qry = "select * from MDM_DeviceMaster where DeviceID='" + pm.uuid + "'"; dr = databaseHelper.getDataReader(qry); if (dr.Read()) { string UserId = dr["UserId"] != DBNull.Value ? dr["UserId"].ToString().ToUpper() : null; 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 ApplicationName,ApplicationPackage,UserId,UserDesignation from MDM_AccessibleApplication"; dtable = databaseHelper.getDataTable(qry); if (dtable.Rows.Count > 0) { 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 { ga.Add(new application { applicationName = (drow["ApplicationName"] == DBNull.Value) ? "" : drow["ApplicationName"].ToString(), applicationPackage = (drow["ApplicationPackage"] == DBNull.Value) ? "" : drow["ApplicationPackage"].ToString() }); //linfo.LogFile(enLogType.INFO, "UserID,UserDesignation are null. ApplicationName = " + drow["ApplicationName"] + " ApplicationPackage = "+drow["ApplicationPackage"]+"", "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. { ga.Add(new application { applicationName = (drow["ApplicationName"] == DBNull.Value) ? "" : drow["ApplicationName"].ToString(), applicationPackage = (drow["ApplicationPackage"] == DBNull.Value) ? "" : drow["ApplicationPackage"].ToString() }); //linfo.LogFile(enLogType.INFO, "Userid and UserDesignation are not null . drow[UserId] = " + drow["UserId"] + " and Userid=" + UserId + ". drow[UserDesignation] = " + drow["UserDesignation"] + " and Designation = " + Designation + " ApplicationName = " + drow["ApplicationName"] + " ApplicationPackage = " + drow["ApplicationPackage"] + "", "rizwan"); } else if (drow["UserId"] != DBNull.Value && drow["UserDesignation"] == DBNull.Value && drow["UserID"].ToString().Length > 0 && drow["UserID"].ToString().Split(',').Contains(UserId))// Application Valid only to specific user. { ga.Add(new application { applicationName = (drow["ApplicationName"] == DBNull.Value) ? "" : drow["ApplicationName"].ToString(), applicationPackage = (drow["ApplicationPackage"] == DBNull.Value) ? "" : drow["ApplicationPackage"].ToString() }); //linfo.LogFile(enLogType.INFO, "Userid is not null. drow[UserId] = " + drow["UserId"] + " and Userid=" + UserId + ". drow[UserDesignation] = " + drow["UserDesignation"] + " and Designation = " + Designation + " ApplicationName = " + drow["ApplicationName"] + " ApplicationPackage = " + drow["ApplicationPackage"] + "", "rizwan"); } else if (drow["UserDesignation"] != DBNull.Value && drow["UserId"] == DBNull.Value && drow["UserDesignation"].ToString().Length > 0 && drow["UserDesignation"].ToString().Split(',').Contains(Designation)) //application valid only to specific designation (multiple user can come to same designation) { ga.Add(new application { applicationName = (drow["ApplicationName"] == DBNull.Value) ? "" : drow["ApplicationName"].ToString(), applicationPackage = (drow["ApplicationPackage"] == DBNull.Value) ? "" : drow["ApplicationPackage"].ToString() }); //linfo.LogFile(enLogType.INFO, "UserDesignation is not null. drow[UserId] = " + drow["UserId"] + " and Userid=" + UserId + ". drow[UserDesignation] = " + drow["UserDesignation"] + " and Designation = " + Designation + " ApplicationName = " + drow["ApplicationName"] + " ApplicationPackage = " + drow["ApplicationPackage"] + "", "rizwan"); } } } gaa.applications = ga; #region Website list qry = "Select WebsiteName from MDM_AccessibleWebsite"; dtable = databaseHelper.getDataTable(qry); List<weblist> website = new List<weblist>(); foreach (DataRow drow in dtable.Rows) { website.Add(new weblist { WebsiteName = (drow["WebsiteName"] == DBNull.Value) ? "" : drow["WebsiteName"].ToString() }); } gaa.websiteurl = website; #endregion gaa.response = true; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, gaa); qry = "delete from MDM_PushNotification where DeviceID='" + pm.uuid + "' and Command='Get Accessible Apps'"; 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; } }