Question: Below are all my controllers: HomeController.cs using Microsoft.AspNetCore.Mvc; using POEPART 1 . Models; using System.Diagnostics; namespace POEPART 1 . Controllers { public class HomeController :
Below are all my controllers:
HomeController.cs
using Microsoft.AspNetCore.Mvc;
using POEPARTModels;
using System.Diagnostics;
namespace POEPARTControllers
public class HomeController : Controller
private readonly ILogger logger;
public HomeControllerILogger logger
logger logger;
public IActionResult Login
return View;
public IActionResult MyProduct
return View;
public IActionResult AddWork
return View;
public IActionResult Index
return View;
public IActionResult MyWork
return View;
public IActionResult AboutUs
return View;
public IActionResult ContactUs
return View;
ResponseCacheDuration Location ResponseCacheLocation.None, NoStore true
public IActionResult Error
return Viewnew ErrorViewModel RequestId Activity.Current?.Id HttpContext.TraceIdentifier ;
LoginController.cs
using Microsoft.AspNetCore.Mvc;
using POEPARTModels;
namespace POEPARTControllers
public class LoginController : Controller
private readonly LoginModel login;
public LoginController
login new LoginModel;
HttpPost
public ActionResult Loginstring email, string name
var loginModel new LoginModel;
int userID loginModelSelectUseremail name;
if userID
User found, proceed with login logic eg set authentication cookie
For demonstration, redirecting to a dummy page
return RedirectToActionIndex "Home", new userID userID ;
else
User not found, handle accordingly eg show error message
return ViewLoginFailed;
ProductController.cs
using Microsoft.AspNetCore.Mvc;
using POEPARTModels;
namespace POEPARTControllers
public class ProductController : Controller
public productTable prodtbl new productTable;
HttpPost
public ActionResult AddWorkproductTable products
var result prodtbl.insertproductproducts;
return RedirectToActionIndex "Home";
HttpGet
public ActionResult AddWork
return Viewprodtbl;
ProductDisplayController.cs
using Microsoft.AspNetCore.Mvc;
using POEPARTModels;
namespace POEPARTControllers
public class ProductDisplayController : Controller
HttpGet
public IActionResult MyProduct
var products ProductDisplayModel.SelectProducts;
return Viewproducts;
TransactionController.cs
using Microsoft.AspNetCore.Mvc;
using POEPARTModels;
using System.Data.SqlClient;
namespace POEPARTControllers
public class TransactionController : Controller
HttpPost
public ActionResult PlaceOrderint userID, int productID
try
Create a new instance of SqlConnection using the connection string
using SqlConnection con new SqlConnectionproductTableconstring
Define the SQL query to insert a new record into the transactionTable
string sql "INSERT INTO transactionTable userID productID VALUES @UserID, @ProductID;
Create a new instance of SqlCommand with the SQL query and SqlConnection
using SqlCommand cmd new SqlCommandsql con
Add parameters to the SqlCommand for userID and productID
cmdParameters.AddWithValue@UserID", userID;
cmdParameters.AddWithValue@ProductID", productID;
Open the SqlConnection
con.Open;
Execute the SqlCommand to insert the record into the transactionTable
int rowsAffected cmdExecuteNonQuery;
Close the SqlConnection
con.Close;
Check if the insert operation was successful
if rowsAffected
R
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
