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 POEPART1.Models;
using System.Diagnostics;
namespace POEPART1.Controllers
{
public class HomeController : Controller
{
private readonly ILogger _logger;
public HomeController(ILogger 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();
}
[ResponseCache(Duration =0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
LoginController.cs
using Microsoft.AspNetCore.Mvc;
using POEPART1.Models;
namespace POEPART1.Controllers
{
public class LoginController : Controller
{
private readonly LoginModel login;
public LoginController()
{
login = new LoginModel();
}
[HttpPost]
public ActionResult Login(string email, string name)
{
var loginModel = new LoginModel();
int userID = loginModel.SelectUser(email, name);
if (userID !=-1)
{
// User found, proceed with login logic (e.g., set authentication cookie)
// For demonstration, redirecting to a dummy page
return RedirectToAction("Index", "Home", new { userID = userID });
}
else
{
// User not found, handle accordingly (e.g., show error message)
return View("LoginFailed");
}
}
}
}
ProductController.cs
using Microsoft.AspNetCore.Mvc;
using POEPART1.Models;
namespace POEPART1.Controllers
{
public class ProductController : Controller
{
public productTable prodtbl = new productTable();
[HttpPost]
public ActionResult AddWork(productTable products)
{
var result2= prodtbl.insert_product(products);
return RedirectToAction("Index", "Home");
}
[HttpGet]
public ActionResult AddWork()
{
return View(prodtbl);
}
}
}
ProductDisplayController.cs
using Microsoft.AspNetCore.Mvc;
using POEPART1.Models;
namespace POEPART1.Controllers
{
public class ProductDisplayController : Controller
{
[HttpGet]
public IActionResult MyProduct()
{
var products = ProductDisplayModel.SelectProducts();
return View(products);
}
}
}
TransactionController.cs
using Microsoft.AspNetCore.Mvc;
using POEPART1.Models;
using System.Data.SqlClient;
namespace POEPART1.Controllers
{
public class TransactionController : Controller
{
[HttpPost]
public ActionResult PlaceOrder(int userID, int productID)
{
try
{
// Create a new instance of SqlConnection using the connection string
using (SqlConnection con = new SqlConnection(productTable.con_string))
{
// 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 SqlCommand(sql, con))
{
// Add parameters to the SqlCommand for userID and productID
cmd.Parameters.AddWithValue("@UserID", userID);
cmd.Parameters.AddWithValue("@ProductID", productID);
// Open the SqlConnection
con.Open();
// Execute the SqlCommand to insert the record into the transactionTable
int rowsAffected = cmd.ExecuteNonQuery();
// Close the SqlConnection
con.Close();
// Check if the insert operation was successful
if (rowsAffected >0)
{
// R

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!