public ActionResult AssetReport(string startDate, string endDate, string[] companyIDs, string[] propertyIDs, string[] statusIDs) { StringBuilder sbOperation = new StringBuilder(); StringBuilder whereClause = new StringBuilder(); List <Property> allProperty = new List <Property>(); sbOperation.Append("select tblProperty.*, mCompanyProperty.CompanyID from tblProperty "); sbOperation.Append(" INNER JOIN mCompanyProperty on mCompanyProperty.PropertyID = tblProperty.PropertyID "); // Add modality id to the where clause if appropriate if (companyIDs != null && companyIDs.Count() > 0 && !string.IsNullOrEmpty(companyIDs[0])) { whereClause.Append(" AND mCompanyProperty.CompanyID IN (" + String.Join(",", companyIDs) + ")"); } else { //get the companys only the owner can access whereClause.Append(" AND mCompanyProperty.CompanyID IN (" + Helpers.Helpers.GetUserManagedCompanyString(Session["UserID"].ToString()) + ")"); } // Add modality id to the where clause if appropriate if (propertyIDs != null && propertyIDs.Count() > 0 && !string.IsNullOrEmpty(propertyIDs[0])) { whereClause.Append(" AND tblProperty.PropertyID IN (" + String.Join(",", propertyIDs) + ")"); } // Add modality id to the where clause if appropriate if (statusIDs != null && statusIDs.Count() > 0 && !string.IsNullOrEmpty(statusIDs[0])) { whereClause.Append(" AND tblProperty.StatusID IN (" + String.Join(",", statusIDs) + ")"); } sbOperation.Append(whereClause.Remove(0, 4).Insert(0, " where ")); sbOperation.Append(" Order by Address"); using (SqlDataAdapter adapter = new SqlDataAdapter(sbOperation.ToString(), Helpers.Helpers.GetAppConnectionString())) { DataSet ds = new DataSet(); adapter.Fill(ds); DataTable tb = (DataTable)ds.Tables[0]; if (tb != null && tb.Rows.Count > 0) { for (int i = 0; i < tb.Rows.Count; i++) { DataRow dr = tb.Rows[i]; Property property = PropertyManager.FillInPropertyWithData(dr); allProperty.Add(property); } } } return(PartialView("AssetReport", allProperty)); }