I encountered a similar issue in the past, but the solution I used back then doesn't seem to work here. I am attempting to trigger an overloaded repository function to organize my view data based on the selected option from the dropdown menu.
I utilized the "onchange" event to run my JavaScript code, but I am struggling to call the repository function due to mismatched overloads and uncertainty about how to properly bind them together. Any assistance provided would be highly appreciated.
HTML View Code
<select id="sortSelect" onchange="CallChangeFunction()">
<option value="default">Default</option>
<option value="make">Make</option>
<option value="model">Model</option>
<option value="year">Year</option>
</select>
<script>
function CallChangeFunction(val) {
alert("Perform sorting action here!");
}
</script>
Listing Repository Code
IEnumerable<ListingStat> GetListingStats(int inCompanyID, int inMonth, int inYear);
public IEnumerable<ListingStat> GetListingStats(int inCompanyID, int inMonth, int inYear)
{
//var x = document.getElementById("sortSelect").value;
// Query might be optimized using Entity Framework.. However, there are no direct keys between listingstats and makemodel stats, and creating them solely for EF purposes is not ideal
var theSQL = "select d.DatePK, ls.*, " +
"mm.Make as MM_Make, mm.Model as MM_Model, mm.ListingsThatWereActive as MM_ListingCount, mm.MedianPriceExcludeZero as MM_MedianPrice, mm.PopularityRank as MM_PopularityRank, " +
"mm.PopularityMaxRank as MM_PopularityMaxRank, mm.AverageFavorites as MM_Favorites, mm.AverageSearchImpressions as MM_SearchImpressions, mm.AverageBuyerInquiries as MM_BuyerInquiries, mm.AveragePhoneInquiries as MM_PhoneInquiries, mm.AverageListingViews as MM_ListingViews, " +
"ymm.SupplyDemandIntegerPercentile as YMM_SupplyDemandPercentile, ymm.TotalListingViews as YMM_TotalListingViews " +
"from " +
"PerformanceDataMart.Dates d " +
"left outer join PerformanceDataMart.ListingStats ls on ls.DateFK = d.DatePK and ls.CompanyId = :CompanyID " +
"left outer join PerformanceDataMart.MakeModelStats mm on mm.DateFK = d.DatePK and mm.Make = ls.Make and mm.Model = ls.Model and mm.Year is null " +
"left outer join PerformanceDataMart.MakeModelStats ymm on ymm.DateFK = d.DatePK and ymm.Make = ls.Make and ymm.Model = ls.Model and ymm.Year = ls.Year " +
"where d.Month = :Month and d.Year = :Year";
var theDB = new CCDB();
List<ListingStat> theList = new List<ListingStat>();
using (IDataReader aDR = theDB.OpenDataReader(theSQL, inCompanyID, inMonth, inYear))
{
while(aDR.Read())
{
ListingStat theListingStat = new ListingStat();
theList.Add(theListingStat);
theListingStat.ListingId = As.Integer(aDR["ListingId"]);
theListingStat.Year = As.Integer(aDR["Year"]);
theListingStat.Make = As.String(aDR["MM_Make"]);
if (theListingStat.Make == "")
theListingStat.Make = As.String(aDR["Make"]);
theListingStat.Model = As.String(aDR["MM_Model"]);
if (theListingStat.Model == "")
theListingStat.Model = As.String(aDR["Model"]);
}
}
return theList;
}