/* * private string FreeHearse(DateTime start, DateTime end) * { * using (SqlConnection connection = new SqlConnection(ConnectionString)) * { * SqlCommand command = new SqlCommand("EXEC dbo.GET_HEARSE", connection); * connection.Open(); * SqlDataReader HearseID = command.ExecuteReader(); * List<int> plateStrings = new List<int>(); * while (HearseID.Read()) * { * plateStrings.Add((int)HearseID[0]); * } * HearseID.Close(); * * command.CommandText = "EXEC dbo.free_at @PRIORITY_"; * SqlDataReader times; * * foreach (int item in plateStrings) * { * command.Parameters.AddWithValue("@PRIORITY_", item); * times = command.ExecuteReader(); * bool isFree = true; * while (times.Read()) * { * DateTime startTime = (DateTime)times["START_AT"]; * DateTime endTime = (DateTime)times["END_AT"]; * * if (!(start > endTime || end < startTime)) * { * isFree = false; * } * } * times.Close(); * if (isFree) * { * return item.ToString(); * } * command.Parameters.Clear(); * } * } * throw new FileNotFoundException("Ingen rustvogn ledig"); * } */ public bool Update(CalendarEntryRepository eventRepository, HearseRepository rustvognReposetory) { foreach (Hearse item in rustvognReposetory.GetCopyHearses()) { } foreach (CalendarEntry item in eventRepository.GetCopyEvents()) { if (item.Status == status.Changed) { AlterEvent(item); item.Status = status.UnChanged; } else if (item.Status == status.Deleted) { DeleteEvent(item.Key); } else if (item.Status == status.NewlyMade) { CreateEvent(item); item.Status = status.UnChanged; } else if (item.Status == status.UnChanged) { continue; } else { throw new InvalidDataException("Ukendt status enum. Fil: 'DatabaseController.Update'"); } } return(true); }
public Controller() { DC = new DatabaseController(); hearseRepository = new HearseRepository(); eventRepository = new CalendarEntryRepository(hearseRepository); }