public void GestisciConsegna(Libro libro, Persona persona) { #region Precondizioni Debug.Assert(libro != null); Debug.Assert(persona != null); Debug.Assert(Prestiti.ContainsKey(libro)); Debug.Assert(persona == PossessoreLibro(libro)); #if DEBUG int previousPrestitiCount = Prestiti.Count; #endif #endregion Console.WriteLine(persona.Nome + " consegna \"" + libro.Titolo + "\""); Prestito prestito = Prestiti[libro]; Persona richiedente = prestito.PrendiPrimoRichiedente(); if (richiedente != null) { Console.WriteLine(richiedente.Nome + " prende in prestito \"" + libro.Titolo + "\""); prestito.Possessore = richiedente; } else { Prestiti.Remove(libro); } #region Postcondizioni Debug.Assert(Prestiti.Count == previousPrestitiCount || Prestiti.Count == previousPrestitiCount - 1); #endregion }
public void GestisciRichiesta(Libro libro, Persona persona) { #region Precondizioni Debug.Assert(libro != null, "libro != null"); Debug.Assert(persona != null, "persona != null"); #if DEBUG int previousPrestitiCount = Prestiti.Count; #endif #endregion if (IsLibroDisponibile(libro)) { // La richiesta può essere soddisfatta: viene creato un nuovo prestito Console.WriteLine(persona.Nome + " prende in prestito \"" + libro.Titolo + "\""); Prestiti.Add(libro, new Prestito(libro, persona)); } else { // La richiesta non può essere soddisfatta: il richiedente viene aggiunto alla coda dei richiedenti Console.WriteLine(persona.Nome + " vorrebbe prendere in prestito \"" + libro.Titolo + "\""); Prestito prestito = Prestiti[libro]; prestito.AggiungiRichiedente(persona); } #region Postcondizioni Debug.Assert(Prestiti.Count == previousPrestitiCount || Prestiti.Count == previousPrestitiCount + 1); #endregion }