/// <summary> /// 保存对象实例。 /// </summary> /// <param name="model">模型实例对象。</param> /// <returns>返回保存结果。</returns> /// <param name="cancellationToken">取消标识。</param> public virtual async Task <DataResult> SaveAsync(TModel model, CancellationToken cancellationToken = default) { if (await IsDuplicatedAsync(model, cancellationToken)) { return(DataAction.Duplicate); } if (Context.Any(model.Id)) { return(DataResult.FromResult(await Context.UpdateAsync(model, cancellationToken), DataAction.Updated)); } return(DataResult.FromResult(await Context.CreateAsync(model, cancellationToken), DataAction.Created)); }
/// <summary> /// 保存对象实例。 /// </summary> /// <param name="model">模型实例对象。</param> /// <returns>返回保存结果。</returns> public virtual DataResult Save(TModel model) { if (IsDuplicated(model)) { return(DataAction.Duplicate); } if (Context.Any(model.Id)) { return(DataResult.FromResult(Context.Update(model), DataAction.Updated)); } return(DataResult.FromResult(Context.Create(model), DataAction.Created)); }
/// <summary> /// 保存实例。 /// </summary> /// <param name="model">模型实例对象。</param> /// <returns>返回执行结果。</returns> public virtual DataResult Save(TModel model) { if (IsDulicate(model)) { return(DataAction.Duplicate); } if (model.Id > 0) { model.UpdatedDate = DateTime.Now; return(DataResult.FromResult(Database.Update(model), DataAction.Updated)); } return(DataResult.FromResult(Database.Create(model), DataAction.Created)); }
/// <summary> /// 通过唯一Id删除对象实例。 /// </summary> /// <param name="id">唯一Id。</param> /// <returns>返回删除结果。</returns> public virtual DataResult Delete(TKey id) { return(DataResult.FromResult(Context.Delete(id), DataAction.Deleted)); }
/// <summary> /// 根据条件删除实例。 /// </summary> /// <param name="expression">条件表达式。</param> /// <returns>返回删除结果。</returns> public virtual DataResult Delete(Expression <Predicate <TModel> > expression) { return(DataResult.FromResult(Context.Delete(expression), DataAction.Deleted)); }
/// <summary> /// 根据条件更新特定的实例。 /// </summary> /// <param name="expression">条件表达式。</param> /// <param name="satement">更新对象。</param> /// <returns>返回更新结果。</returns> public virtual DataResult Update(Expression <Predicate <TModel> > expression, object satement) { return(DataResult.FromResult(Context.Update(expression, satement), DataAction.Updated)); }
/// <summary> /// 根据条件更新特定的实例。 /// </summary> /// <param name="id">唯一Id。</param> /// <param name="satement">更新对象。</param> /// <returns>返回更新结果。</returns> public virtual DataResult Update(TKey id, object satement) { return(DataResult.FromResult(Context.Update(id, satement), DataAction.Updated)); }
/// <summary> /// 通过唯一Id删除对象实例。 /// </summary> /// <param name="id">唯一Id。</param> /// <param name="cancellationToken">取消标识。</param> /// <returns>返回删除结果。</returns> public virtual async Task <DataResult> DeleteAsync(TKey id, CancellationToken cancellationToken = default) { return(DataResult.FromResult(await Context.DeleteAsync(id, cancellationToken), DataAction.Deleted)); }
/// <summary> /// 根据条件删除实例。 /// </summary> /// <param name="expression">条件表达式。</param> /// <param name="cancellationToken">取消标识。</param> /// <returns>返回删除结果。</returns> public virtual async Task <DataResult> DeleteAsync(Expression <Predicate <TModel> > expression, CancellationToken cancellationToken = default) { return(DataResult.FromResult(await Context.DeleteAsync(expression, cancellationToken), DataAction.Deleted)); }
/// <summary> /// 通过唯一Id删除对象实例。 /// </summary> /// <param name="ids">唯一Id集合。</param> /// <param name="cancellationToken">取消标识。</param> /// <returns>返回删除结果。</returns> public virtual async Task <DataResult> DeleteAsync(IEnumerable <TKey> ids, CancellationToken cancellationToken = default) { return(DataResult.FromResult(await Context.DeleteAsync(x => x.Id.Included(ids), cancellationToken), DataAction.Deleted)); }
/// <summary> /// 通过唯一Id删除对象实例。 /// </summary> /// <param name="ids">唯一Id集合。</param> /// <returns>返回删除结果。</returns> public virtual DataResult Delete(IEnumerable <TKey> ids) { return(DataResult.FromResult(Context.Delete(x => x.Id.Included(ids)), DataAction.Deleted)); }
/// <summary> /// 根据条件更新特定的实例。 /// </summary> /// <param name="expression">条件表达式。</param> /// <param name="satement">更新对象。</param> /// <param name="cancellationToken">取消标识。</param> /// <returns>返回更新结果。</returns> public virtual async Task <DataResult> UpdateAsync(Expression <Predicate <TModel> > expression, object satement, CancellationToken cancellationToken = default) { return(DataResult.FromResult(await Context.UpdateAsync(expression, satement, cancellationToken), DataAction.Updated)); }
/// <summary> /// 根据条件更新特定的实例。 /// </summary> /// <param name="id">唯一Id。</param> /// <param name="satement">更新对象。</param> /// <param name="cancellationToken">取消标识。</param> /// <returns>返回更新结果。</returns> public virtual async Task <DataResult> UpdateAsync(TKey id, object satement, CancellationToken cancellationToken = default) { return(DataResult.FromResult(await Context.UpdateAsync(id, satement, cancellationToken), DataAction.Updated)); }
/// <summary> /// 删除实例对象。 /// </summary> /// <param name="ids">Id集合。</param> /// <returns>返回删除结果。</returns> public virtual DataResult Delete(int[] ids) { return(DataResult.FromResult(Database.Delete(x => x.Id.Included(ids)), DataAction.Deleted)); }
/// <summary> /// 删除实例对象。 /// </summary> /// <param name="id">Id。</param> /// <returns>返回删除结果。</returns> public virtual DataResult Delete(int id) { return(DataResult.FromResult(Database.Delete(x => x.Id == id), DataAction.Deleted)); }