Example #1
0
        private Dictionary <string, object> GetDynamicObj(ConvertDynamicType type)
        {
            var obj  = new Dictionary <string, object>();
            var t    = new T();
            var time = DateTime.Now;

            switch (type)
            {
            case ConvertDynamicType.Delete:
                if (IsPropertyExist(t, "UpdateTime"))
                {
                    obj.Add("UpdateTime", time);
                }
                if (IsPropertyExist(t, "UpdateUser"))
                {
                    obj.Add("UpdateUser", _userContext.UserId);
                }
                if (IsPropertyExist(t, "Marks"))
                {
                    obj.Add("Marks", false);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
            return(obj);
        }
Example #2
0
        private dynamic GetDynamicObj(T entity, ConvertDynamicType type)
        {
            dynamic obj  = entity;
            var     time = DateTime.Now;

            switch (type)
            {
            case ConvertDynamicType.Insert:
                if (IsPropertyExist(obj, "UpdateTime"))
                {
                    obj.UpdateTime = time;
                }
                if (IsPropertyExist(obj, "UpdateUser"))
                {
                    obj.UpdateUser = _userContext.UserId;
                }
                if (IsPropertyExist(obj, "AddTime"))
                {
                    obj.AddTime = time;
                }
                if (IsPropertyExist(obj, "AddUser"))
                {
                    obj.AddUser = _userContext.UserId;
                }
                if (IsPropertyExist(obj, "Marks"))
                {
                    obj.Marks = true;
                }
                break;

            case ConvertDynamicType.Update:
                if (IsPropertyExist(obj, "UpdateTime"))
                {
                    obj.UpdateTime = time;
                }
                if (IsPropertyExist(obj, "UpdateUser"))
                {
                    obj.UpdateUser = _userContext.UserId;
                }
                if (IsPropertyExist(obj, "Marks"))
                {
                    obj.Marks = true;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
            return(obj);
        }