public static bool AddTrip(ScheduleSet trip) { try { // TODO : check if C# joins correctly //if (!Context.TrainSet.Contains(trip.TrainSet)) //{ // throw new ArgumentException(string.Format(DbDoestNotContain + "train!")); //} // TODO : make trains not free only at the specified time, not all the time //var trainsWithSchedule = Context.ScheduleSet.Where(x => x.TrainId == trip.TrainId).Where(y => y.) //bool IsFree = true; //if (trainsWithSchedule.Count != 1) //{ // for (int i = 0; i < trainsWithSchedule.Count; i++) // { // trainsWithSchedule // } //} TrainSet train = DataAccess.GetAllTrains().FirstOrDefault(x => x.Id == trip.TrainId); //if (train.IsFree) //{ train.IsFree = false; Context.ScheduleSet.Add(trip); Context.SaveChanges(); return true; //} //throw new ArgumentException("Train is not free at the selected period"); } catch (Exception exception) { MessageBox.Show(exception.Message); return false; } }
public static bool DeleteTrip(ScheduleSet trip) { try { //if (!Context.ScheduleSet.Contains(trip)) //{ // throw new ArgumentException(string.Format(DbDoestNotContain + "trip")); //} RemoveCityStopsSet(trip.Id); Context.ScheduleSet.Remove(trip); Context.SaveChanges(); return true; } catch (Exception exception) { MessageBox.Show(exception.Message); return false; } }