/// <summary> /// Convert the Microsoft.Crm.Sdk.Messages.AttributeAuditDetail to custom VinnyB.EasyHistory.Models.AuditDetailModel /// </summary> /// <param name="_this">AttributeAuditDetail</param> /// <returns>AuditDetailModel</returns> public static AuditDetailModel ToEasyHistoryComponent(this AttributeAuditDetail _this, string _attributeLogicalName) { EntityReference user = _this.AuditRecord.GetAttributeValue <EntityReference>("userid"); if (user == null || String.IsNullOrEmpty(user.Name)) { user = new EntityReference(); user.Name = "N/A"; } DateTime date = _this.AuditRecord.GetAttributeValue <DateTime>("createdon"); string value = string.Empty; Type attributeType = null; if (_this.OldValue.Contains(_attributeLogicalName) && _this.OldValue.Attributes[_attributeLogicalName] != null) { attributeType = _this.OldValue.Attributes[_attributeLogicalName].GetType(); value = RetrieveAttributeValue(attributeType, _this.OldValue, _attributeLogicalName); } else { value = string.Empty; } AuditDetailModel auditDetailModel = new AuditDetailModel(user.Name, date.ToString("MM-dd-yyyy hh:mm tt"), value, attributeType != null ? attributeType.Name : string.Empty); return(auditDetailModel); }
public static void GetMissingEntityRecordIdFromDetails(this AuditModel audit) { if (audit.EntityRecordId == null && audit.EntityName != null) { AuditDetailModel logDetail = audit.AuditDetails.Where(ad => ad.EntityName == audit.EntityName).FirstOrDefault(); if (logDetail != null) { audit.EntityRecordId = logDetail.RecordId; } } }
private static AuditDetail CreateAuditDetail(AuditDetailModel model) { return(new AuditDetail() { AuditDetailType = model.AuditDetailTypeString, EntityName = model.EntityName, RecordId = model.RecordId, PropertyName = model.PropertyName, OriginalValue = model.OriginalValue, NewValue = model.NewValue, OriginalValueDescription = model.OriginalValueDescription, NewValueDescription = model.NewValueDescription, }); }