public void Handle()
        {
            using (var context = new PlanningPokerDbContext())
            {
                var eventRecord = new EventRecord(modelEvent);

                context.EventRecords.Add(eventRecord);

                context.SaveChanges();

                modelEvent.id = eventRecord.Id;

                var model = new ModelQuery().Execute();

                var snapshot = new Snapshot
                {
                    Id          = modelEvent.id.Value,
                    Data        = model.ToJson(),
                    EventRecord = eventRecord
                };

                context.Snapshots.Add(snapshot);

                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        private static void PopulateDatabaseWithExampleValues()
        {
            using (var context = new PlanningPokerDbContext())
            {
                context.Database.ExecuteSqlCommand("DELETE FROM [EventRecord]");
                context.Database.ExecuteSqlCommand("DELETE FROM [Snapshot]");
            }

            var events = ExampleEvents.Get();

            foreach (var modelEvent in events)
            {
                new AddEventCommand(modelEvent).Handle();
            }
        }
Exemplo n.º 3
0
        public IEnumerable <ModelEvent> Execute()
        {
            using (var context = new PlanningPokerDbContext())
            {
                var events = context
                             .EventRecords
                             .OrderBy(r => r.Id)
                             .Select(r => new { r.Id, r.Data })
                             .ToArray()
                             .Select(r =>
                {
                    var modelEvent = JsonConvert.DeserializeObject <ModelEvent>(r.Data);
                    modelEvent.id  = r.Id;
                    return(modelEvent);
                })
                             .ToArray();

                return(events);
            }
        }