/// <summary> /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <int> InsertAsync(PresentBuyLogEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "insert into PresentBuyLog (" + "ProductID," + "UserID," + "Msg," + "IsSuccess," + "NeedS," + "UpdateTime," + "BuyCounts) " + "values(" + "@ProductID," + "@UserID," + "@Msg," + "@IsSuccess," + "@NeedS," + "@UpdateTime," + "@BuyCounts)"; return(await Task.Run(() => _DB.ReturnID(strSQL, dict))); }
/// <summary> /// 增加一条记录 /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual bool Add(PresentBuyLogEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "insert into PresentBuyLog (" + "ProductID," + "UserID," + "Msg," + "IsSuccess," + "NeedS," + "UpdateTime," + "BuyCounts) " + "values(" + "@ProductID," + "@UserID," + "@Msg," + "@IsSuccess," + "@NeedS," + "@UpdateTime," + "@BuyCounts)"; return(_DB.ExeSQLResult(strSQL, dict)); }
/// <summary> /// 把实体类转换成键/值对集合 /// </summary> /// <param name="entity"></param> /// <param name="dict"></param> private static void GetParameters(PresentBuyLogEntity entity, Dictionary <string, object> dict) { dict.Add("LogID", entity.LogID); dict.Add("ProductID", entity.ProductID); dict.Add("UserID", entity.UserID); dict.Add("Msg", entity.Msg); dict.Add("IsSuccess", entity.IsSuccess); dict.Add("NeedS", entity.NeedS); dict.Add("UpdateTime", entity.UpdateTime); dict.Add("BuyCounts", entity.BuyCounts); }
/// <summary> /// 通过数据读取器生成实体类 /// </summary> /// <param name="rdr"></param> /// <returns></returns> private static PresentBuyLogEntity GetEntityFromrdr(NullableDataReader rdr) { PresentBuyLogEntity info = new PresentBuyLogEntity(); info.LogID = rdr.GetInt32("LogID"); info.ProductID = rdr.GetInt32("ProductID"); info.UserID = rdr.GetInt32("UserID"); info.Msg = rdr.GetString("Msg"); info.IsSuccess = rdr.GetBoolean("IsSuccess"); info.NeedS = rdr.GetInt32("NeedS"); info.UpdateTime = rdr.GetNullableDateTime("UpdateTime"); info.BuyCounts = rdr.GetInt32("BuyCounts"); return(info); }
/// <summary> /// 获取实体(异步方式) /// </summary> /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param> /// <param name="dict">参数的名/值集合</param> /// <returns></returns> public virtual async Task <PresentBuyLogEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null) { PresentBuyLogEntity obj = null; string strSQL = "select top 1 * from PresentBuyLog where 1=1 " + strWhere; using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict))) { if (reader.Read()) { obj = GetEntityFromrdr(reader); } } return(obj); }
/// <summary> /// 更新一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <bool> UpdateAsync(PresentBuyLogEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "Update PresentBuyLog SET " + "ProductID = @ProductID," + "UserID = @UserID," + "Msg = @Msg," + "IsSuccess = @IsSuccess," + "NeedS = @NeedS," + "UpdateTime = @UpdateTime," + "BuyCounts = @BuyCounts" + " WHERE " + "LogID = @LogID"; return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict))); }
/// <summary> /// 增加或更新一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <param name="IsSave">是否增加</param> /// <returns></returns> public virtual async Task <bool> AddOrUpdateAsync(PresentBuyLogEntity entity, bool IsSave) { return(IsSave ? await AddAsync(entity) : await UpdateAsync(entity)); }
/// <summary> /// 增加或更新一条记录 /// </summary> /// <param name="entity">实体模型</param> /// <param name="IsSave">是否增加</param> /// <returns></returns> public virtual bool AddOrUpdate(PresentBuyLogEntity entity, bool IsSave) { return(IsSave ? Add(entity) : Update(entity)); }