コード例 #1
0
        /// <summary>
        /// 记录【新增】操作日志
        /// </summary>
        /// <param name="user"></param>
        /// <param name="module"></param>
        /// <param name="objId"></param>
        /// <param name="obj"></param>
        public void WriteInsertOperateLog(KeyValuePair <string, string> user, string applicationId, object objId, object obj)
        {
            var groupId  = Guid.NewGuid().ToString();
            var type     = obj.GetType();
            var module   = type.GetCustomAttribute <DisplayNameAttribute>();
            var propList = type.GetProperties();

            foreach (var prop in propList)
            {
                var displayName = prop.GetCustomAttribute <DisplayNameAttribute>();
                if (displayName != null)
                {
                    var value = prop.GetValue(obj);
                    var log   = new RightOperateLog
                    {
                        ApplicationId    = applicationId,
                        Module           = module.DisplayName,
                        ObjId            = objId.ToString(),
                        GroupId          = groupId,
                        OperateType      = OperateTypeEnum.增加,
                        OperateBy        = user.Key,
                        OperateByName    = user.Value,
                        OperateOn        = DateTime.Now,
                        FieldName        = prop.Name,
                        FieldDisplayName = displayName.DisplayName,
                        NewValue         = value == null ? null : value.ToString()
                    };
                    db.Insert(log);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 记录【删除】操作日志
        /// </summary>
        /// <param name="user"></param>
        /// <param name="module"></param>
        /// <param name="objId"></param>
        /// <param name="obj"></param>
        public void WriteDeleteOperateLog(KeyValuePair <string, string> user, string applicationId, object objId, object obj, string desc = null)
        {
            var groupId = Guid.NewGuid().ToString();
            var type    = obj.GetType();
            var module  = type.GetCustomAttribute <DisplayNameAttribute>();
            var log     = new RightOperateLog
            {
                ApplicationId = applicationId,
                Module        = module.DisplayName,
                ObjId         = objId.ToString(),
                GroupId       = groupId,
                OperateType   = OperateTypeEnum.修改,
                OperateBy     = user.Key,
                OperateByName = user.Value,
                OperateOn     = DateTime.Now,
                NewValue      = desc
            };

            db.Insert(log);
        }