Exemple #1
0
        public static IList <CustomerHistoryData> ToJavaScriptCustomerHistory(IList <StoredEvent> storedEvents)
        {
            HistoryData = new List <CustomerHistoryData>();
            CustomerHistoryDeserializer(storedEvents);

            var sorted = HistoryData.OrderBy(c => c.When);
            var list   = new List <CustomerHistoryData>();
            var last   = new CustomerHistoryData();

            foreach (var change in sorted)
            {
                var jsSlot = new CustomerHistoryData
                {
                    Id = change.Id == Guid.Empty.ToString() || change.Id == last.Id
                        ? ""
                        : change.Id,
                    Name = string.IsNullOrWhiteSpace(change.Name) || change.Name == last.Name
                        ? ""
                        : change.Name,
                    Email = string.IsNullOrWhiteSpace(change.Email) || change.Email == last.Email
                        ? ""
                        : change.Email,
                    BirthDate = string.IsNullOrWhiteSpace(change.BirthDate) || change.BirthDate == last.BirthDate
                        ? ""
                        : change.BirthDate.Substring(0, 10),
                    Action = string.IsNullOrWhiteSpace(change.Action) ? "" : change.Action,
                    When   = change.When,
                    Who    = change.Who
                };

                list.Add(jsSlot);
                last = change;
            }
            return(list);
        }
Exemple #2
0
        public static IList <CustomerHistoryData> ToJavaScriptCustomerHistory(IList <StoredEvent> storedEvents)
        {
            HistoryData = new List <CustomerHistoryData>();
            CustomerHistoryDeserializer(storedEvents);

            var sorted = HistoryData.OrderBy(c => c.Timestamp);
            var list   = new List <CustomerHistoryData>();
            var last   = new CustomerHistoryData();

            foreach (var change in sorted)
            {
                var jsSlot = new CustomerHistoryData
                {
                    Id = change.Id == Guid.Empty.ToString() || change.Id == last.Id
                        ? ""
                        : change.Id,
                    NameModel = string.IsNullOrWhiteSpace(change.NameModel) || change.NameModel == last.NameModel
                        ? ""
                        : change.NameModel,
                    ModelYear = change.ModelYear > 0 || change.ModelYear == last.ModelYear
                        ? 0
                        : change.ModelYear,
                    ManifacturingYear = change.ManifacturingYear > 0 || change.ManifacturingYear == last.ManifacturingYear
                        ? 0
                        : change.ManifacturingYear,
                    Action    = string.IsNullOrWhiteSpace(change.Action) ? "" : change.Action,
                    Timestamp = change.Timestamp,
                    Who       = change.Who
                };

                list.Add(jsSlot);
                last = change;
            }
            return(list);
        }
Exemple #3
0
        private static void CustomerHistoryDeserializer(IEnumerable <StoredEvent> storedEvents)
        {
            foreach (var e in storedEvents)
            {
                var     slot = new CustomerHistoryData();
                dynamic values;

                switch (e.MessageType)
                {
                case "CustomerRegisteredEvent":
                    values         = JsonConvert.DeserializeObject <dynamic>(e.Data);
                    slot.BirthDate = values["BirthDate"];
                    slot.Email     = values["Email"];
                    slot.Name      = values["Name"];
                    slot.Action    = "Registered";
                    slot.When      = values["Timestamp"];
                    slot.Id        = values["Id"];
                    slot.Who       = e.User;
                    break;

                case "CustomerUpdatedEvent":
                    values         = JsonConvert.DeserializeObject <dynamic>(e.Data);
                    slot.BirthDate = values["BirthDate"];
                    slot.Email     = values["Email"];
                    slot.Name      = values["Name"];
                    slot.Action    = "Updated";
                    slot.When      = values["Timestamp"];
                    slot.Id        = values["Id"];
                    slot.Who       = e.User;
                    break;

                case "CustomerRemovedEvent":
                    values      = JsonConvert.DeserializeObject <dynamic>(e.Data);
                    slot.Action = "Removed";
                    slot.When   = "asd";
                    slot.When   = values["Timestamp"];
                    slot.Id     = values["Id"];
                    slot.Who    = e.User;
                    break;
                }
                HistoryData.Add(slot);
            }
        }