public static bool AddTrain(TrainSet train) { try { Context.TrainSet.Add(train); Context.SaveChanges(); return true; } catch (Exception exception) { MessageBox.Show(exception.Message); return false; } }
public static bool EditTrain(int oldTrainId,TrainSet newTrain) { try { TrainSet original = Context.TrainSet.FirstOrDefault(x => x.Id == oldTrainId); if (original == null) { return false; } original.IsFree = newTrain.IsFree; original.Description = newTrain.Description; original.Seats = newTrain.Seats; Context.SaveChanges(); return true; } catch (Exception exception) { MessageBox.Show(exception.Message); return false; } }
public static bool DeleteTrain(TrainSet train) { try { //if (!Context.TrainSet.Contains(train)) //{ // throw new ArgumentException(string.Format(DbDoestNotContain + "train!")); //} Context.TrainSet.Remove(train); Context.SaveChanges(); return true; } catch (Exception exception) { MessageBox.Show(exception.Message); return false; } }