Skip to content

Instantly share code, notes, and snippets.

@rionmonster
Last active March 18, 2017 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rionmonster/8ddc3f6a82f3fadebd3e4c48c04f82eb to your computer and use it in GitHub Desktop.
Save rionmonster/8ddc3f6a82f3fadebd3e4c48c04f82eb to your computer and use it in GitHub Desktop.
Changes
// Index route, which I added route parameter to include ID
[HttpGet("estimate/{project_ID}")]
public IActionResult Index(int project_ID)
{
// Any specific reason for the Session? Could
// this be resolved from the current user / claims?
if(HttpContext.Session.GetInt32("userID") == null)
{
return RedirectToAction("Index", "User");
}
// ViewBag.sessionUID = HttpContext.Session.GetInt32("userID");
ViewBag.Materials = materialFactory.FindAll();
ViewBag.EstimateMaterials = estimateFactory.ShowEstimateTable();
ViewBag.EstimateTotals = estimateFactory.ShowEstimateTotals();
// use .First() to store the first entry in the Enumerbal as this method
// only returns one row from projects
ViewBag.ProjectInfo = projectFactory.GetProjectInfo(project_ID).First();
return View();
}
// form with asp-action
<form asp-action="AddProjectRentalRate" asp-controller="Estimate" method="post">
<label>Rental Rate</label>
<input type="number" step=".01" name="rental_rate">
<input type="hidden" name="project_ID" value="@ViewBag.ProjectInfo.projectID">
<input type="submit" name="submit">
</form>
// Upon form submission, error received:
// No webpage was found for the web address: http://localhost:5000/estimate/1
// If I hit refresh, the page is loaded, but no changes have been made to the db.
[HttpPost("add_project_rental_rate")]
public IActionResult AddProjectRentalRate(Decimal rental_rate, int project_ID)
{
if(HttpContext.Session.GetInt32("userID") == null)
{
return RedirectToAction("Index");
}
int UserID = (int)HttpContext.Session.GetInt32("userID");
projectFactory.EditRentalRate(rental_rate, project_ID);
return RedirectToAction("Index", new {project_ID = project_ID});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment