public CqrsReader(IDatabaseApi api, CrudModels <M> crudModels) { this.api = api; this.crudModels = crudModels; // Subscribing to event handler CqrsEventHandler <M> .Subscribe(cqrsEvent => { if (cqrsEvent.EventType.Equals(ECqrsEventType.CreateEvent)) { // When the CqrsWriter has added a model through THEIR database, we add it in OUR database. api.OpenConnection(); api.Create(new List <M>() { (M)cqrsEvent.Model }, crudModels.CreateModel); api.CloseConnection(); } else if (cqrsEvent.EventType.Equals(ECqrsEventType.DeleteEvent)) { // When the CqrsWriter has removed a model from THEIR database, we remove it from OUR database. api.OpenConnection(); api.Delete <M>(new List <M>() { (M)cqrsEvent.Model }, crudModels.DeleteModel); api.CloseConnection(); } }); }
public void Create(List <M> newModels) { api.Create(newModels, crudModels.CreateModel); foreach (var newModel in newModels) { var eventForNewModel = new CqrsEvent <M>(ECqrsEventType.CreateEvent, newModel); CqrsEventHandler <M> .AddEvent(eventForNewModel); } }
public void Create(bool throwIfExists = true) { databaseApi.Create(throwIfExists).WaitForResult(); }