private void SetProjectionListener(LoansRepository repository, IServiceCollection services) { var config = new RabbitMqConfig(); configuration.GetSection("RabbitMq").Bind(config); var logger = services.BuildServiceProvider().GetService <ILogger <RabbitMqPublisher> >(); var rabbitMq = new RabbitMqChannelFactory().CreateReadChannel <Models.Loan, string>(config, "LoansRead", logger); rabbitMq.Received += (sender, projection) => { if (projection.Upsert != null && projection.Upsert.Length > 0) { repository.Upsert(projection.Upsert); } if (projection.Upsert != null && projection.Upsert.Length == 0) { repository.Clear(); } if (projection.Remove != null) { repository.Remove(projection.Remove); } }; }
/* Remove */ private void Remove(object sender, EventArgs e) { if (!CheckForSelectedItem()) { return; } var removeConfirmation = MessageBox.Show($@"Are you sure you want to remove this entity?", @"Remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (removeConfirmation != DialogResult.Yes) { return; } switch (_option) { case 1: var removeDoubleConfirmationAuthor = MessageBox.Show($@"Removing this author will also remove all of his books and loans related to them!", @"Remove", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (removeDoubleConfirmationAuthor != DialogResult.OK) { return; } _authorsRepository.Remove(entitiesListBox.SelectedItem as Author); break; case 2: var removeDoubleConfirmationPublisher = MessageBox.Show($@"Removing this publisher will also remove all of his books and loans related to them!", @"Remove", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (removeDoubleConfirmationPublisher != DialogResult.OK) { return; } _publishersRepository.Remove(entitiesListBox.SelectedItem as Publisher); break; case 3: var removeDoubleConfirmationStudent = MessageBox.Show($@"Removing this student will also remove all related loans!", @"Remove", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (removeDoubleConfirmationStudent != DialogResult.OK) { return; } _studentsRepository.Remove(entitiesListBox.SelectedItem as Student); break; case 4: var removeDoubleConfirmationBook = MessageBox.Show($@"Removing this book will also remove all related loans!", @"Remove", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (removeDoubleConfirmationBook != DialogResult.OK) { return; } _booksRepository.Remove(entitiesListBox.SelectedItem as Book); break; case 5: _loansRepository.Remove(entitiesListBox.SelectedItem as Loan); break; default: CommonErrorMessage(); break; } RefreshList(); }