public ActionResult Create(Vehicle vehicle) { try { sqlconn.Open(); var r = VehicleLogic.Create(sqlconn, vehicle, vehicle.VehicleTypeId.Value, vehicle.VehicleBrandId.Value, 4, 1); if (r == -1) { sqlconn.Close(); TempData["SuccessMessage"] = "VIN už v DB existuje."; return(View()); } sqlconn.Close(); return(RedirectToAction(nameof(Index))); } catch { sqlconn.Close(); TempData["SuccessMessage"] = "Chyba při ukládání vozidla do DB."; return(View()); } }
private void Button_Click(object sender, RoutedEventArgs e) { var typeId = cbType.SelectedValue; var brandId = cbBrand.SelectedValue; Vehicle vm = new Vehicle() { Id = -1, LicensePlate = tbLicensePlate.Text, Price = Convert.ToDecimal(tbPrice.Text), PurchasedOn = Convert.ToDateTime(datePicker.Text), Title = tbTitle.Text, VehicleBrand = null, VehicleType = null, Vin = tbVin.Text, Vintage = Convert.ToInt16(tbVintage.Text) }; var result = VehicleLogic.Create(_sqlConn, vm, Convert.ToInt32(typeId), Convert.ToInt32(brandId), 4, 1); if (result == -1) { MessageBox.Show($"VIN již v DB existuje.", "Stop", MessageBoxButton.OK, MessageBoxImage.Stop); } else if (result == 0) { MessageBox.Show($"Vozidlo bylo uloženo.", "Info", MessageBoxButton.OK, MessageBoxImage.Information); Refresh(); } }