Example #1
0
        public virtual void AfterSave(bool isUpdate)
        {
            #region if critical entity, log it
            if (this is ICriticalEntity)
            {
                if (isUpdate)
                {
                    //Provider.Database.ClearEntityWebCache(this.GetType(), this.Id);
                    IDatabaseEntityMinimal originalEntity = Provider.Database.Read(this.GetType(), "Id={0}", this.Id);
                    string changes = originalEntity.CompareFields(this);

                    if (!string.IsNullOrWhiteSpace(changes))
                    {
                        EntityHistory eh = new EntityHistory()
                        {
                            EntityId   = this.Id,
                            EntityName = this.GetType().Name,
                            MemberId   = Provider.CurrentMember.Id,
                            Operation  = EntityOperation.Update
                        };
                        eh.Save();

                        EntityHistoryData ehd = new EntityHistoryData()
                        {
                            Changes         = changes,
                            EntityHistoryId = eh.Id
                        };
                        ehd.Save();
                    }
                }
                else
                {
                    EntityHistory eh = new EntityHistory()
                    {
                        EntityId   = this.Id,
                        EntityName = this.GetType().Name,
                        MemberId   = Provider.CurrentMember.Id,
                        Operation  = EntityOperation.Insert
                    };
                    eh.Save();
                }
            }
            #endregion
        }