I need to select Quarter and Year
then on submit those two values should be passed to my stored proc "SummaryProc"
and after executing it will pass the rows for ID..... Please guide me if the code i have written is fine. I am missing out on the link as I am unable to understand how to link all these. The working app will be "Enter Quarter & Year in _Summary.cshtml -> Pass values to Controller -> Execution in Repository code -> rows returned from stored proc to be displayed in SummaryTable.cshtml"
_Summary.cshtml
<div class="form-group">
<label class="control-label col-lg-4">Period:</label>
<div class="col-lg-8">
@Html.DropDownList("Quarter", new SelectListItem[] { (new SelectListItem() { Text = "Q1", Value = "1" }), (new SelectListItem() { Text = "Q2", Value = "2" }), (new SelectListItem() { Text = "Q3", Value = "3" }), (new SelectListItem() { Text = "Q4", Value = "4" }) }, "--Select Quarter--", new { @class = "form-control", id = "Quarter" })
<br />
@Html.DropDownList("Year", new SelectListItem[] { (new SelectListItem() { Text = "2016", Value = "2016" }), (new SelectListItem() { Text = "2017", Value = "2017" }) }, "--Select Year--", new { @class = "form-control", id = "Year" })
</div>
</div>
<div class="row">
<div class="col-lg-offset-4" style="padding: 10px 0px 0px 0px;">
<input type="submit" id="submit" value="Submit" class="btn btn-lg btn-success" />
</div>
</div>
Controller code:
[ActionName("_Summary")]
[HttpPost]
public ActionResult _Summary(FloorPlanViewModel model, FormCollection form)
{
SummaryConfiguration sumConfig = new SummaryConfiguration();
sumConfig.Quarter = Convert.ToInt32(form["Quarter"]);
sumConfig.Year = Convert.ToInt32(form["Year"]);
var details = floorService.SummaryProc(sumConfig.Quarter, sumConfig.Year);
return PartialView("SummaryTable", details);
}
Code to execute stored procedure:
public IEnumerable<SummaryConfiguration> SummaryProc(int Quarter, int Year)
{
var model = new List<SummaryConfiguration>();
using (var dbCmd = defaultDB.GetStoredProcCommand("dbo.SummaryProc"))
{
defaultDB.AddInParameter(dbCmd, "Quarter", System.Data.DbType.Int32, Quarter);
defaultDB.AddInParameter(dbCmd, "Year", System.Data.DbType.Int32, Year);
var varCmd = defaultDB.ExecuteReader(dbCmd);
while (varCmd.Read())
{
// add items in the list
model.Add(new SummaryConfiguration()
{
ID = Convert.ToString(varCmd["ID"]),
//rest of the code
});
}
}
return model;
}