// Umbraco.Code.MapAll -UserAvatars -UserName private void Map(IAuditItem source, AuditLog target, MapperContext context) { target.UserId = source.UserId; target.NodeId = source.Id; target.Timestamp = source.CreateDate; target.LogType = source.AuditType.ToString(); target.EntityType = source.EntityType; target.Comment = source.Comment; target.Parameters = source.Parameters; }
public virtual void AddBusinessEntity(IAuditItem beheerContextEntity) { // <pex> if (beheerContextEntity == null) throw new ArgumentNullException("beheerContextEntity"); // </pex> if (beheerContextEntity.DataKeyValue.Equals("1")) throw new BusinessLayerException("duplicate"); beheerContextEntity.Id = m_Id; m_BusinessEntities.Add(beheerContextEntity as AuditItem); if (beheerContextEntity.Parent != null) { //Deze entity heeft een parent. //Voeg de detail toe aan de master. if (m_QueueMasters != null && m_QueueMasters.Count > 0 && beheerContextEntity.Parent != null) m_QueueMasters[beheerContextEntity.Parent.Id].Details. Add(beheerContextEntity as AuditItem); } m_Id++; }
public virtual void UpdateBusinessEntity(IAuditItem beheerContextEntity) { // <pex> if (beheerContextEntity == null) throw new ArgumentNullException("beheerContextEntity"); // </pex> AuditItem found = FindBusinessEntity(m_BusinessEntities, beheerContextEntity as AuditItem); if (found != null) { found.DataKeyValue = beheerContextEntity.DataKeyValue; found.Master = beheerContextEntity.Master; if (beheerContextEntity.Details.Count > 0) { //Voeg details toe die nieuw zijn. int count = beheerContextEntity.Details.Count; for (int i = 0; i < count; i++) { AuditItem detail = beheerContextEntity.Details[i]; if (detail.Id == -3 ) { detail.Id = m_Id++; found.Details.Add(detail); } } //bijwerk de id's, waarvan de details updates zijn. found.Details. Where(detail => detail.Id == -1 || !detail.DataKeyValue.Equals(" ")). Update(x => { x.Id = m_Id++; //x.DataKeyValue = beheerContextEntity.DataKeyValue; }); } AuditItem master; int idMaster = beheerContextEntity.Parent.Id; m_QueueMasters.TryGetValue(idMaster, out master); if (master!=null) { //het is een master.Wijzig de master met nieuwe waarden. m_QueueMasters[idMaster].DataKeyValue = beheerContextEntity.Parent.DataKeyValue; //update elke detail met veranderde master waarden. m_BusinessEntities. Where(detail => detail.Parent.Id == idMaster). Update(x => { x.Master = beheerContextEntity.Parent.DataKeyValue; //x.DataKeyValue = beheerContextEntity.DataKeyValue; }); } if (beheerContextEntity.Parent != null) { //het is een detail. if (m_QueueMasters != null && m_QueueMasters.Count > 0 && beheerContextEntity.Parent!=null) m_QueueMasters[beheerContextEntity.Parent.Id].Details. Where(detail => detail.Id == found.Id). Update(detail=> detail.DataKeyValue = found.DataKeyValue); } } }
public virtual void DeleteBusinessEntity(IAuditItem beheerContextEntity) { IAuditItem found = FindBusinessEntity(m_BusinessEntities, beheerContextEntity as AuditItem); if (found != null) { m_BusinessEntities.Remove(found as AuditItem); //SelectedMaster.Details.Remove(found as AuditItem); if (beheerContextEntity.Parent != null) { if (m_QueueMasters != null && m_QueueMasters.Count > 0 && beheerContextEntity.Parent != null) m_QueueMasters[beheerContextEntity.Parent.Id].Details. Remove(beheerContextEntity as AuditItem); } } }
private void PrepareChanges(IAuditContext ac) { foreach (var item in Changes.Where(x => x.State == EntityState.Added)) { Type type = item.Entity.GetType(); List <string> keyValues = new List <string>(); foreach (var k in type.GetEntityProperties(true)) { var key = k.GetValue(item.Entity); var pv = item.Values.FirstOrDefault(x => x.Name == k.Name); if (pv == null) { pv = new CFieldValue { Name = k.Name }; item.Values.Add(pv); } pv.NewValue = key; keyValues.Add(key.ToString()); } item.Key = string.Join(",", keyValues); } List <CLinkValue> links = new List <CLinkValue>(); foreach (var change in Changes) { foreach (var item in change.Values) { foreach (var fk in item.Property.FKProperties) { CLinkValue v = new CLinkValue(); v.ObjectName = fk.EntityName; var v1 = item.NewValue ?? item.OldValue; if (v1 == null) { continue; } v.Key = v1.ToString(); if (string.IsNullOrWhiteSpace(v.Key)) { continue; } v.ChildObject = item.Property.Property.DeclaringType.Name; v.ChildKey = change.Key; v.Operation = change.State.ToString(); links.Add(v); } } } foreach (var item in links.GroupBy(x => x.ObjectName)) { string name = item.Key; foreach (var k in item.GroupBy(x => x.Key).ToList()) { string key = k.Key; Change c = Changes.FirstOrDefault(x => x.ObjectName == name && x.Key == key); if (c != null) { c.Links.AddRange(k); } else { c = new Change(EntityState.Modified); c.ObjectName = name; c.Key = key; c.Links.AddRange(k); Changes.Add(c); } } } JavaScriptSerializer sr = new JavaScriptSerializer(); foreach (var change in Changes) { if (change.Entity is IAuditIgnore) { continue; } IAuditItem item = ac.CreateNew(); item.Action = change.State.ToString(); item.AuditTime = DateTime.UtcNow; //item.IPAddress = ac.GetIPAddress(); //item.Username = ac.GetUsername(); item.TableKey = change.Key; item.TableName = change.ObjectName; item.Fields = sr.Serialize(change.Values); item.Links = sr.Serialize(change.Links); //ac.AddAudit(item); } }