// GET: Vehicles/Delete/5 public ActionResult Delete(int id) { sqlconn.Open(); var vehicle = VehicleLogic.Delete(sqlconn, 1, id); sqlconn.Close(); if (!vehicle) { return(View(@"<script language='javascript'>alert('Nemáte oprávnění smazat vozidlo.');</script>")); } return(RedirectToAction(nameof(Index))); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { var mb = MessageBox.Show($"Přejete si opravdu smazat vozdilo?", "Smazání vozidla", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (mb == MessageBoxResult.No) { return; } VehicleLogic.Delete(_sqlConn, 2, _vehicle.Id); _parent.Refresh(); Close(); }
public ActionResult Delete(int id, Vehicle vehicle) { try { sqlconn.Open(); List <Inspection> inspections = InspectionLogic.FindAllByVehicleId(sqlconn, id); sqlconn.Close(); if (inspections.Count > 0) { return(View("<script>alert('Nemůžete smazat vozidlo, které obsahuje prohlídky.');</script>")); } sqlconn.Open(); VehicleLogic.Delete(sqlconn, 1, vehicle.Id); sqlconn.Close(); return(RedirectToAction(nameof(Index))); } catch { return(View(vehicle)); } }