private void SpawnPrenotationView() { IPrenotationCoordinator pCoord = CoordinatorManager.Instance.CoordinatorOfType <IPrenotationCoordinator>(); IUserCoordinator uCoord = CoordinatorManager.Instance.CoordinatorOfType <IUserCoordinator>(); PrenotationView prenotationView = new PrenotationView(); AddInformation(prenotationView); Func <string, ReadOnlyCollection <IPrenotation> > prenotationRetriever = (str) => new ReadOnlyCollection <IPrenotation>((from p in pCoord.Prenotations where p.Client.FiscalCode == str select p).ToList()); Func <string, ICustomer> customerRetrieverByUsername = (str) => (from u in uCoord.RegisteredUsers where u is ICustomer && u.Username == str select u as ICustomer).FirstOrDefault(); Func <string, IEnumerable <ICustomer> > customerRetrieverByLastName = (str) => (from c in uCoord.Customers where c.LastName.Contains(str) select c); new PrenotationPresenter(prenotationView, prenotationRetriever, customerRetrieverByUsername, customerRetrieverByLastName); prenotationView.Show(); }
public PrenotationPresenter(PrenotationView view, Func <string, ReadOnlyCollection <IPrenotation> > prenotationRetrieverByFiscaleCode, Func <string, ICustomer> customerRetrieverByUsername, Func <string, IEnumerable <ICustomer> > customerRetrieverByLastName) { #region Precondizioni if (view == null) { throw new ArgumentNullException("view null"); } if (prenotationRetrieverByFiscaleCode == null) { throw new ArgumentNullException("prenotation Retriever null"); } if (customerRetrieverByUsername == null) { throw new ArgumentNullException("customer username Retriever null"); } if (customerRetrieverByLastName == null) { throw new ArgumentNullException("customer lastname Retriever null"); } #endregion _prenotationRetriever = prenotationRetrieverByFiscaleCode; _customerRetrieverByUsername = customerRetrieverByUsername; _customerRetrieverByLastName = customerRetrieverByLastName; _customersBox = view.CustomerBox; _prenotationControl = view.TabControl; AuthorizationLevel authLevel = view.RetrieveTagInformation <AuthorizationLevel>("authorizationLevel"); if (authLevel == AuthorizationLevel.GUEST) { throw new InvalidOperationException("I Guest non possono utilizzare questa view"); } if (authLevel == AuthorizationLevel.CUSTOMER) { view.SearchPanel.Enabled = false; view.SearchPanel.Visible = false; string fiscalCode = view.RetrieveTagInformation <string>("fiscalCode"); if (fiscalCode == null) { throw new InvalidOperationException("Il cliente che ha aperto la view non ha un codice fiscale"); } ReadOnlyCollection <IPrenotation> prenotations = RetrievePrenotation(fiscalCode); if (prenotations.Count <= 0) { MessageBox.Show("Non risultano attive prenotazioni a tuo nome"); } else { view.TabControl.Populate(prenotations); } // Ripopolo la view in caso di cambiamenti foreach (IPrenotation p in prenotations) { p.PrenotationChanged += (sender, pea) => view.TabControl.Populate(prenotations); } } else { MessageBox.Show("Inserisci l'username o un il " + "cognome di un cliente per visualizzare le prenotazioni"); _customersBox.DropDownStyle = ComboBoxStyle.DropDownList; _customersBox.DisplayMember = "DisplayInfo"; _customersBox.SelectedIndexChanged += CustomerSelectedHandler; view.SearchBox.TextChanged += SearchBoxChanged; } }