/// <summary> /// edit data with expression /// </summary> /// <param name="modifyExpression">modify expression</param> /// <param name="query">Query object</param> /// <returns>ICommand object</returns> public ICommand Modify(IModify modifyExpression, IQuery query) { Dictionary <string, IModifyValue> fieldAndValues = modifyExpression.GetModifyValues(); if (fieldAndValues == null || fieldAndValues.Count <= 0) { return(null); } #region control version string versionFieldName = EntityManager.GetVersionField(typeof(TEntity)); if (!string.IsNullOrWhiteSpace(versionFieldName)) { if (!fieldAndValues.ContainsKey(versionFieldName)) { fieldAndValues.Add(versionFieldName, new CalculateModifyValue(CalculateOperator.Add, 1)); } } #endregion #region update date string refreshFieldName = EntityManager.GetRefreshDateField(typeof(TEntity)); if (!string.IsNullOrWhiteSpace(refreshFieldName)) { if (!fieldAndValues.ContainsKey(refreshFieldName)) { fieldAndValues.Add(refreshFieldName, new FixedModifyValue(DateTimeOffset.Now)); } } #endregion var command = ExecuteModifyExpression(fieldAndValues, query); //publish modify expression event DataAccessEventBus.PublishModifyExpressionEvent <TEntity>(fieldAndValues, query); return(command); }
/// <summary> /// Modify data /// </summary> /// <param name="data">Data</param> /// <param name="modify">Modify expression</param> void ModifyData(TEntity data, IModify modify) { if (data == null || modify == null) { return; } var modifyValues = modify.GetModifyValues() ?? new Dictionary <string, IModifyValue>(0); if (modifyValues.Count < 1) { return; } foreach (var mv in modifyValues) { var nowValue = data.GetPropertyValue(mv.Key); var modifyValue = mv.Value; var newValue = modifyValue.GetModifyValue(nowValue); data.SetPropertyValue(mv.Key, newValue); } }
/// <summary> /// edit data with expression /// </summary> /// <param name="modifyExpression">modify expression</param> /// <param name="query">query object</param> /// <returns>ICommand object</returns> public virtual ICommand Modify(IModify modifyExpression, IQuery query) { Dictionary <string, dynamic> fieldAndValues = modifyExpression.GetModifyValues(); if (fieldAndValues == null || fieldAndValues.Count <= 0) { return(null); } #region 版本控制 string versionFieldName = QueryConfig.GetVersionField(typeof(T)); if (!string.IsNullOrWhiteSpace(versionFieldName)) { if (!fieldAndValues.ContainsKey(versionFieldName)) { fieldAndValues.Add(versionFieldName, new CalculateModify() { Calculate = CalculateOperator.Add, Value = 1 }); } } #endregion #region 更新时间 string refreshFieldName = QueryConfig.GetRefreshDateField(typeof(T)); if (!string.IsNullOrWhiteSpace(refreshFieldName)) { if (!fieldAndValues.ContainsKey(refreshFieldName)) { fieldAndValues.Add(refreshFieldName, DateTime.Now); } } #endregion return(Update(fieldAndValues.Keys, fieldAndValues, query)); }
/// <summary> /// edit data with expression /// </summary> /// <param name="modifyExpression">modify expression</param> /// <param name="query">query object</param> /// <returns>ICommand object</returns> public virtual async Task <ICommand> ModifyAsync(IModify modifyExpression, IQuery query) { Dictionary <string, dynamic> fieldAndValues = modifyExpression.GetModifyValues(); if (fieldAndValues == null || fieldAndValues.Count <= 0) { return(null); } #region control version string versionFieldName = QueryConfig.GetVersionField(typeof(T)); if (!string.IsNullOrWhiteSpace(versionFieldName)) { if (!fieldAndValues.ContainsKey(versionFieldName)) { fieldAndValues.Add(versionFieldName, new CalculateModify() { Calculate = CalculateOperator.Add, Value = 1 }); } } #endregion #region update date string refreshFieldName = QueryConfig.GetRefreshDateField(typeof(T)); if (!string.IsNullOrWhiteSpace(refreshFieldName)) { if (!fieldAndValues.ContainsKey(refreshFieldName)) { fieldAndValues.Add(refreshFieldName, DateTime.Now); } } #endregion return(await UpdateAsync(fieldAndValues.Keys, fieldAndValues, query).ConfigureAwait(false)); }