public IActionResult Create()
{
var typelistdocumentstatus = _context.DocumentStatus.ToList();
typelistdocumentstatus.Insert(0, new DocumentStatus { Id = -1, Status = "انتخاب کنید" });
ViewData["DocumentStatusId"] = new SelectList(typelistdocumentstatus, "Id", "Status");
var typelistoffice = _context.Office.ToList();
typelistoffice.Insert(0, new Office { Id = -1, Name = "انتخاب کنید" });
ViewData["OfficeId"] = new SelectList(typelistoffice, "Id", "Name");
var typelistunit = _context.Unit.ToList();
typelistunit.Insert(0, new Unit { Id = -1,UnitName = "انتخاب کنید" });
ViewData["UnitId"] = new SelectList(typelistunit, "Id", "UnitName");
var typelistsvehicletype = _context.VehicleType.ToList();
typelistsvehicletype.Insert(0, new VehicleType { Id = -1, TypeName = "انتخاب کنید" });
ViewData["VehicleTypeId"] = new SelectList(typelistsvehicletype, "Id", "TypeName");
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,VehicleTypeId,UnitId,VehicleColor,Vin,EngineNumber,NumberPlate,DocumentStatusId,OfficeId,OwnerStatus,OwnerName,Description")] VehicleInformation vehicleInformation)
{
if (ModelState.IsValid)
{
_context.Add(vehicleInformation);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
ViewData["DocumentStatusId"] = new SelectList(_context.DocumentStatus, "Id", "Status", vehicleInformation.DocumentStatusId);
ViewData["OfficeId"] = new SelectList(_context.Office, "Id", "Name", vehicleInformation.OfficeId);
ViewData["UnitId"] = new SelectList(_context.Unit, "Id", "UnitName", vehicleInformation.UnitId);
ViewData["VehicleTypeId"] = new SelectList(_context.VehicleType, "Id", "TypeName", vehicleInformation.VehicleTypeId);
return View(vehicleInformation);
}