internal static string ToJsonAudit(this AgreementContactPhone entity) { var state = JsonConvert.SerializeObject(new { entity.Id, entity.OwnerId, entity.Type, entity.Value, }); return(state); }
public void Handle(CreateContactPhone command) { if (command == null) { throw new ArgumentNullException("command"); } var entity = new AgreementContactPhone { Type = command.Type, Value = command.Value, }; if (command.Contact != null) { entity.Owner = command.Contact; } else { entity.OwnerId = command.ContactId; } _entities.Create(entity); // log audit var audit = new CommandEvent { RaisedBy = command.Principal.Identity.Name, Name = command.GetType().FullName, Value = JsonConvert.SerializeObject(new { command.AgreementId, command.ContactId, command.Type, command.Value, }), NewState = entity.ToJsonAudit(), }; _entities.Create(audit); if (!command.NoCommit) { _unitOfWork.SaveChanges(); } command.CreatedContactPhone = entity; command.CreatedContactPhoneId = command.CreatedContactPhone.Id; }