using Microsoft.AspNetCore.Mvc;

using MVCWebApp.Models;

using System.Data;

using System.Data.SqlClient;

using System.Drawing;

using System.Reflection;

using Utilities;

 

namespace MVCWebApp.Controllers

{

    public class CarsController : Controller

    {

        //[HttpGet("Cars/ViewCarDetails/{vin}")]            // route: Cars/ViewCarDetails/vin

        public IActionResult ViewCarDetails(string vin)     // route: route?vin=value

        {

            Car car = new Car();

 

            DBConnect objDB = new DBConnect();

            SqlCommand command = new SqlCommand();

            command.CommandType = CommandType.StoredProcedure;

            command.CommandText = "GetCarsByVIN";

 

            command.Parameters.AddWithValue("@theVIN", vin);

 

            DataSet ds = objDB.GetDataSet(command);

 

            if (ds.Tables[0].Rows.Count > 0)

            {

                DataRow record = ds.Tables[0].Rows[0];

                car.Make = record["Make"].ToString();

                car.Model = record["Model"].ToString();

                car.Year = int.Parse(record["Year"].ToString());

                car.Color = record["Color"].ToString();

                car.Value = double.Parse(record["Value"].ToString());

                car.ImageUrl = record["ImageUrl"].ToString();

                car.VIN = record["VIN"].ToString();

            }

 

            // Return the Razor View "ViewCarDetails.cshtml"
            // and delivers a Car as the View's Model

            return View(car);

        }

    }

}