public ActionResult AuditEntities(long auditTrailId, DataSourceRequest command, IEnumerable <Sort> sort = null)
        {
            var audiTrail = _auditTrailRepository.GetById(auditTrailId);

            string logXml        = audiTrail.LogXml;
            var    auditLog      = AuditLog.FromXml(logXml);
            var    auditEntities = auditLog.Entities;
            var    models        = new List <AuditEntityModel>();

            foreach (var auditEntity in auditEntities)
            {
                var model = new AuditEntityModel();
                model.AuditTrailId = audiTrail.Id;
                model.Action       = auditEntity.Action.ToString();
                model.EntityType   = auditEntity.Type.ToString();
                model.Key          = auditEntity.Keys[0].Name;
                model.Value        = auditEntity.Keys[0].Value.ToString();
                models.Add(model);
            }
            var gridModel = new DataSourceResult
            {
                Data  = models.PagedForCommand(command),
                Total = models.Count()
            };

            return(new JsonResult
            {
                Data = gridModel
            });
        }
        public ActionResult List(DataSourceRequest command, string searchValues, IEnumerable <Sort> sort = null)
        {
            var model = _httpContext.Session[SessionKey.AuditTrailSearchModel] as SearchModel;

            if (model == null)
            {
                model = BuildSearchModel();
            }
            else
            {
                model.ClearValues();
            }
            //validate
            var errorFilters = model.Validate(searchValues);

            foreach (var filter in errorFilters)
            {
                ModelState.AddModelError(filter.Name, _localizationService.GetResource(filter.ResourceKey + ".Required"));
            }
            if (ModelState.IsValid)
            {
                //session update
                model.Update(searchValues);
                _httpContext.Session[SessionKey.AuditTrailSearchModel] = model;

                PagedResult <AuditTrail> auditTrails = _auditTrailService.GetAuditTrails(model.ToExpression(), model.ToParameters(), command.Page - 1, command.PageSize, sort);
                var result = auditTrails.Result.ToList();

                var auditTrailModels = new List <AuditTrailModel>();
                foreach (var auditrail in result)
                {
                    var    auditTrailModel = auditrail.ToModel();
                    string logXml          = auditrail.LogXml;
                    var    auditLog        = AuditLog.FromXml(logXml);
                    auditTrailModel.UserName = auditLog.Username;
                    auditTrailModel.Date     = auditLog.Date;
                    auditTrailModels.Add(auditTrailModel);
                }

                var gridModel = new DataSourceResult
                {
                    Data  = auditTrailModels,
                    Total = auditTrails.TotalCount
                };
                return(new JsonResult
                {
                    Data = gridModel
                });
            }
            return(Json(new { Errors = ModelState.SerializeErrors() }));
        }
        public ActionResult AuditProperties(long auditTrailId, DataSourceRequest command, IEnumerable <Sort> sort = null)
        {
            var audiTrail       = _auditTrailRepository.GetById(auditTrailId);
            var auditTrailModel = audiTrail.ToModel();

            string logXml   = audiTrail.LogXml;
            var    auditLog = AuditLog.FromXml(logXml);

            var auditEntities = auditLog.Entities;
            var models        = new List <AuditPropertyModel>();

            foreach (var auditEntity in auditEntities)
            {
                var properties = auditEntity.Properties.ToList();
                foreach (var property in properties)
                {
                    var model = new AuditPropertyModel();
                    model.Name = property.Name;
                    model.Type = property.Type;
                    if (property.Type.Equals(PropertyType.SystemByte))
                    {
                        model.Original = property.Original != null?System.Text.Encoding.UTF8.GetString((byte[])property.Original) : "";

                        model.Current = property.Current != null?System.Text.Encoding.UTF8.GetString((byte[])property.Current) : "";
                    }
                    else
                    {
                        model.Original = property.Original != null?property.Original.ToString() : "";

                        model.Current = property.Current != null?property.Current.ToString() : "";
                    }
                    models.Add(model);
                }
            }

            var gridModel = new DataSourceResult
            {
                Data  = models.PagedForCommand(command),
                Total = models.Count()
            };

            return(new JsonResult
            {
                Data = gridModel
            });
        }