Idea of the project: if someone wants to order a project development, here you can send an application.
Imports Newtonsoft.Json
Imports VehicleMaintenance.Core
Imports VehicleMaintenance.Web.Controllers
Public Class VehicleController
Inherits BaseController
Function CreateVehicle() As ActionResult
Return View("EditVehicle")
End Function
<HttpPost()>
Function CreateVehicle(vehicleModel As VehicleViewModel) As ActionResult
Dim number As String = Request.Form("Number")
If String.IsNullOrWhiteSpace(number) Then
ModelState.AddModelError("Number", "Enter plate number.")
Return View("EditVehicle", vehicleModel)
Else
If Not VehicleService.IsVehicleExists(number)
Dim vehicleInfo As New VehicleInfo
vehicleInfo.Number = number
vehicleInfo.VIN = Request.Form("VIN")
VehicleService.CreateVehicle(vehicleInfo)
TempData("Message") = "New vehicle created successfully."
Else
ModelState.AddModelError("Number", $"Vehicle with plate number {number} already exists.")
Return View("EditVehicle", vehicleModel)
End If
Return RedirectToAction("Index", "Home")
End If
End Function
Function GetVehicleInfo() As JsonResult
Dim number As String = Request.QueryString("Number")
' validation not implemented
Dim vehicleData As String = VehicleService.ReadVehicleData(number)
Dim jsonStr As Dictionary(Of String, String) = JsonConvert.DeserializeObject(Of Dictionary(Of String, String))(vehicleData)
Return Json(jsonStr, JsonRequestBehavior.AllowGet)
End Function
End Class