public async Task <IActionResult> Create([Bind("Make,Model,VehicleTypeId,VehicleAlias,OwnerName")] Vehicle vehicle) { if (ModelState.IsValid) { await _service.AddAsync(vehicle); return(RedirectToAction(nameof(Index))); } ViewData["VehicleTypeId"] = new SelectList(_context.VehicleTypes, "Id", "Description", vehicle.VehicleTypeId); return(View(vehicle)); }
public async override void Display() { base.Display(); Output.WriteLine(""); Vehicle vehicle = new Vehicle(); try { string chassi = Input.ReadString("Informe o chassi:"); vehicle.Chassis = chassi; string cor = Input.ReadString("Informe a cor :"); vehicle.Color = cor; Type typeVehicle = Input.ReadEnum <Type>("Informe o tipo :"); vehicle.Type = typeVehicle.ToString(); Vehicle result = await service.GetByChassisAsync(chassi); if (result != null) { Output.WriteLine(""); Output.WriteLine(ConsoleColor.Red, $"Não é possível finalizar o cadastro pois já existe um veículo cadastrado com o chassi: {chassi}"); } else { await service.AddAsync(vehicle); Output.WriteLine(""); Output.WriteLine(ConsoleColor.Green, "Cadastro realizado com sucesso."); } } catch (Exception ex) { Output.WriteLine(""); Output.WriteLine($"Erro: {ex.Message}"); Output.WriteLine($"InnerException: {ex.InnerException}"); } Output.WriteLine(""); Input.ReadString("Pressione [Enter] para voltar para o Menu Principal"); Program.NavigateHome(); }