/// <summary> /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <int> InsertAsync(PointLogEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "insert into PointLog (" + "UserName," + "ModuleType," + "InfoID," + "Point," + "LogTime," + "Times," + "IncomePayOut," + "Remark," + "IP," + "Inputer," + "Memo) " + "values(" + "@UserName," + "@ModuleType," + "@InfoID," + "@Point," + "@LogTime," + "@Times," + "@IncomePayOut," + "@Remark," + "@IP," + "@Inputer," + "@Memo)"; return(await Task.Run(() => _DB.ReturnID(strSQL, dict))); }
/// <summary> /// 增加一条记录 /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual bool Add(PointLogEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "insert into PointLog (" + "UserName," + "ModuleType," + "InfoID," + "Point," + "LogTime," + "Times," + "IncomePayOut," + "Remark," + "IP," + "Inputer," + "Memo) " + "values(" + "@UserName," + "@ModuleType," + "@InfoID," + "@Point," + "@LogTime," + "@Times," + "@IncomePayOut," + "@Remark," + "@IP," + "@Inputer," + "@Memo)"; return(_DB.ExeSQLResult(strSQL, dict)); }
/// <summary> /// 获取实体(异步方式) /// </summary> /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param> /// <param name="dict">参数的名/值集合</param> /// <returns></returns> public virtual async Task <PointLogEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null) { PointLogEntity obj = null; string strSQL = "select top 1 * from PointLog 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> /// <param name="dict"></param> private static void GetParameters(PointLogEntity entity, Dictionary <string, object> dict) { dict.Add("LogID", entity.LogID); dict.Add("UserName", entity.UserName); dict.Add("ModuleType", entity.ModuleType); dict.Add("InfoID", entity.InfoID); dict.Add("Point", entity.Point); dict.Add("LogTime", entity.LogTime); dict.Add("Times", entity.Times); dict.Add("IncomePayOut", entity.IncomePayOut); dict.Add("Remark", entity.Remark); dict.Add("IP", entity.IP); dict.Add("Inputer", entity.Inputer); dict.Add("Memo", entity.Memo); }
/// <summary> /// 通过数据读取器生成实体类 /// </summary> /// <param name="rdr"></param> /// <returns></returns> private static PointLogEntity GetEntityFromrdr(NullableDataReader rdr) { PointLogEntity info = new PointLogEntity(); info.LogID = rdr.GetInt32("LogID"); info.UserName = rdr.GetString("UserName"); info.ModuleType = rdr.GetInt32("ModuleType"); info.InfoID = rdr.GetInt32("InfoID"); info.Point = rdr.GetInt32("Point"); info.LogTime = rdr.GetNullableDateTime("LogTime"); info.Times = rdr.GetInt32("Times"); info.IncomePayOut = rdr.GetInt32("IncomePayOut"); info.Remark = rdr.GetString("Remark"); info.IP = rdr.GetString("IP"); info.Inputer = rdr.GetString("Inputer"); info.Memo = rdr.GetString("Memo"); return(info); }
public JsonResult GetPoint() { var result = new ReturnMessage(false) { Message = "获取用户积分信息失败!" }; try { decimal CurrentPoint = 0; int TodayPoint = 0; int TotalPoint = 0; var account = MemberBLL.Instance.GetEntity(LoginUser.UserId); if (account != null && account.Point != null) { CurrentPoint = account.Point ?? 0; } PointLogEntity para = new PointLogEntity(); para.MemberId = LoginUser.UserId; para.sidx = "AddTime"; para.sord = "desc"; var pointList = PointLogBLL.Instance.GetList(para); if (pointList != null) { TodayPoint = pointList.Where(o => o.Operate == (int)QX360.Model.Enums.PointOperateType.增加 && DateTime.Parse(o.AddTime.ToString()).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")).Sum((detail) => { return(detail.Point ?? 0); }); TotalPoint = pointList.Where(o => o.Operate == (int)QX360.Model.Enums.PointOperateType.增加).Sum((detail) => { return(detail.Point ?? 0); }); } result.IsSuccess = true; result.ResultData["CurrentPoint"] = CurrentPoint; result.ResultData["TodayPoint"] = TodayPoint; result.ResultData["TotalPoint"] = TotalPoint; result.ResultData["List"] = pointList; result.Message = "获取成功!"; } catch (Exception ex) { ex.Data["Method"] = "AccountController>>GetUserDetail"; new ExceptionHelper().LogException(ex); } return(Json(result)); }
/// <summary> /// 更新一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <bool> UpdateAsync(PointLogEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "Update PointLog SET " + "UserName = @UserName," + "ModuleType = @ModuleType," + "InfoID = @InfoID," + "Point = @Point," + "LogTime = @LogTime," + "Times = @Times," + "IncomePayOut = @IncomePayOut," + "Remark = @Remark," + "IP = @IP," + "Inputer = @Inputer," + "Memo = @Memo" + " 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(PointLogEntity 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(PointLogEntity entity, bool IsSave) { return(IsSave ? Add(entity) : Update(entity)); }