Esempio n. 1
0
        private void Apply(StaffChangedEvent staffChangedEvent)
        {
            var propertyName = staffChangedEvent.Property;
            var value        = staffChangedEvent.Value;

            if (_propertyCache == null)
            {
                _propertyCache =
                    GetType()
                    .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy)
                    .ToDictionary(pi => pi.Name);
            }
            var property = _propertyCache.ContainsKey(propertyName) ? _propertyCache[propertyName] : null;

            if (property == null)
            {
                throw new InvalidOperationException(string.Format("Invalid property name {0}", propertyName));
            }

            if (value != null && !property.PropertyType.IsInstanceOfType(value))
            {
                var convertToType = GetConvertToType(property.PropertyType);
                value = Convert.ChangeType(value, convertToType);
            }
            property.SetValue(this, value);
        }
Esempio n. 2
0
        /// <summary>Revises the npi.</summary>
        /// <param name="npi">The npi.</param>
        public virtual void ReviseNpi(string npi)
        {
            var staffChangedEvent = new StaffChangedEvent(Key, Version, p => p.NPI, npi);

            new RuleEngineExecutor <Staff> (this)
            .ForCallingMethodRuleSet()
            .WithContext(staffChangedEvent)
            .Execute(() => RaiseEvent(staffChangedEvent));
        }
Esempio n. 3
0
 /// <summary>
 /// Handles the specified message.
 /// </summary>
 /// <param name="message">The message.</param>
 public void Handle(StaffChangedEvent message)
 {
     if (message.Property == PropertyUtil.ExtractPropertyName <Staff, PersonName> (s => s.Name))
     {
         var name = message.Value as PersonName;
         using (var connection = _connectionFactory.CreateConnection())
         {
             connection.Execute(
                 "UPDATE OrganizationModule.TeamStaff SET FirstName = @FirstName, LastName = @LastName WHERE StaffKey = @StaffKey",
                 new
             {
                 StaffKey = message.Key,
                 name.FirstName,
                 name.LastName
             });
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Handles the specified message.
 /// </summary>
 /// <param name="message">The message.</param>
 public void Handle(StaffChangedEvent message)
 {
     if (message.Property == PropertyUtil.ExtractPropertyName <Staff, PersonName> (s => s.Name))
     {
         using (var connection = _connectionFactory.CreateConnection())
         {
             var name = (message.Value as PersonName);
             if (name != null)
             {
                 connection.Execute(
                     "UPDATE OrganizationModule.Staff SET FirstName = @FirstName, LastName = @LastName WHERE StaffKey = @StaffKey",
                     new { name.FirstName, name.LastName, StaffKey = message.Key });
             }
         }
     }
     if (message.Property == PropertyUtil.ExtractPropertyName <Staff, Email> (s => s.Email))
     {
         using (var connection = _connectionFactory.CreateConnection())
         {
             var email = (Email)message.Value;
             connection.Execute(
                 "UPDATE OrganizationModule.Staff SET Email = @Email WHERE StaffKey = @StaffKey",
                 new { Email = email == null ? (string)null : email.Address, StaffKey = message.Key });
         }
     }
     if (message.Property == PropertyUtil.ExtractPropertyName <Staff, string> (s => s.Location))
     {
         using (var connection = _connectionFactory.CreateConnection())
         {
             connection.Execute(
                 "UPDATE OrganizationModule.Staff SET Location = @Location WHERE StaffKey = @StaffKey",
                 new { Location = (string)message.Value, StaffKey = message.Key });
         }
     }
     if (message.Property == PropertyUtil.ExtractPropertyName <Staff, string> (s => s.NPI))
     {
         using (var connection = _connectionFactory.CreateConnection())
         {
             connection.Execute(
                 "UPDATE OrganizationModule.Staff SET NPI = @NPI WHERE StaffKey = @StaffKey",
                 new { NPI = (string)message.Value, StaffKey = message.Key });
         }
     }
 }