///<summary> ///向数据库中添加一条记录 ///</summary> ///<param name="model">要添加的实体</param> public bool Insert(WithdrawalsDetails model) { const string sql = @"INSERT INTO [dbo].[WithdrawalsDetails] (objectId,createdAt,updatedAt,userId,type,number,before,after,change,state) VALUES (@objectId,@createdAt,@updatedAt,@userId,@type,@number,@before,@after,@change,@state)"; int res = SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@objectId", model.objectId.ToDBValue()), new SqlParameter("@createdAt", model.createdAt.ToDBValue()), new SqlParameter("@updatedAt", model.updatedAt.ToDBValue()), new SqlParameter("@userId", model.userId.ToDBValue()), new SqlParameter("@type", model.type.ToDBValue()), new SqlParameter("@number", model.number.ToDBValue()), new SqlParameter("@before", model.before.ToDBValue()), new SqlParameter("@after", model.after.ToDBValue()), new SqlParameter("@change", model.change.ToDBValue()), new SqlParameter("@state", model.state.ToDBValue())); return(res > 0); }
public IHttpActionResult PostWithdrawalsDetail(string v1, string password, [FromBody] WithdrawalsDetails withdrawalsHistory) { try { if (withdrawalsHistory.change <= 0) { return(notFound("必须为非空整数")); } string objectId = HttpContext.Current.Request.Headers["objectId"]; _UserBLL userModel = new _UserBLL(); var usermodel = userModel.QuerySingleById(objectId); if (!usermodel.transaction_password.Equals((password + objectId).Md5())) { return(notFound("密码错误")); } if (usermodel.overage < withdrawalsHistory.change) { return(notFound("余额不足")); } withdrawalsHistory.createdAt = DateTime.Now; withdrawalsHistory.updatedAt = DateTime.Now; withdrawalsHistory.before = usermodel.overage; withdrawalsHistory.after = usermodel.overage - withdrawalsHistory.change; withdrawalsHistory.objectId = Guid.NewGuid().ToString(); withdrawalsHistory.state = "未完成"; if (bll.saveDetail(withdrawalsHistory, objectId)) { return(ok(withdrawalsHistory.objectId)); } return(notFound("失败")); } catch (Exception e) { return(execept(e.Message)); } }
///<summary> ///向数据库中添加一条记录 ///</summary> ///<param name="model">要添加的实体</param> public bool saveDetail(WithdrawalsDetails model, string userId) { const string sql = @"INSERT INTO [dbo].[WithdrawalsDetails] (objectId,createdAt,updatedAt,userId,type,number,before,after,change,state) VALUES (@objectId,@createdAt,@updatedAt,@userId,@type,@number,@before,@after,@change,@state)"; SqlParameter[] pams = new SqlParameter[] { new SqlParameter("@objectId", model.objectId.ToDBValue()), new SqlParameter("@createdAt", model.createdAt.ToDBValue()), new SqlParameter("@updatedAt", model.updatedAt.ToDBValue()), new SqlParameter("@userId", model.userId.ToDBValue()), new SqlParameter("@type", model.type.ToDBValue()), new SqlParameter("@number", model.number.ToDBValue()), new SqlParameter("@before", model.before.ToDBValue()), new SqlParameter("@after", model.after.ToDBValue()), new SqlParameter("@change", model.change.ToDBValue()), new SqlParameter("@state", model.state.ToDBValue()) }; const string sql1 = @"UPDATE [dbo].[_User] SET overage=overage-@change WHERE [objectId] = @objectId"; SqlParameter[] pams1 = { new SqlParameter("@objectId", userId), new SqlParameter("@change", model.change) }; int res = SqlHelper.ExecuteNonQuerysTransaction(sql, pams, sql1, pams1); return(res > 0); }
/// <summary> /// 查询单个模型实体 /// </summary> /// <param name="id">objectId</param>); /// <returns>实体</returns>); public WithdrawalsDetails QuerySingleById(string objectId) { const string sql = "SELECT TOP 1 objectId,createdAt,updatedAt,userId,type,number,before,after,change,state from WithdrawalsDetails WHERE [objectId] = @objectId"; using (var reader = SqlHelper.ExecuteReader(sql, new SqlParameter("@objectId", objectId))) { if (reader.HasRows) { reader.Read(); WithdrawalsDetails model = SqlHelper.MapEntity <WithdrawalsDetails>(reader); return(model); } else { return(null); } } }
///<summary> ///分页查询一个集合 ///</summary> ///<param name="index">页码</param> ///<param name="size">页大小</param> ///<param name="wheres">条件匿名类</param> ///<param name="orderField">排序字段</param> ///<param name="isDesc">是否降序排序</param> ///<returns>实体集合</returns> public IEnumerable <WithdrawalsDetails> QueryList(int index, int size, object wheres = null, string orderField = "objectId", bool isDesc = true) { List <SqlParameter> list = null; string where = wheres.parseWheres(out list); orderField = string.IsNullOrEmpty(orderField) ? "objectId" : orderField; var sql = SqlHelper.GenerateQuerySql("WithdrawalsDetails", new string[] { "objectId", "createdAt", "updatedAt", "userId", "type", "number", "before", "after", "change", "state" }, index, size, where, orderField, isDesc); using (var reader = SqlHelper.ExecuteReader(sql, list.ToArray())) { if (reader.HasRows) { while (reader.Read()) { WithdrawalsDetails model = SqlHelper.MapEntity <WithdrawalsDetails>(reader); yield return(model); } } } }
/// <summary> /// 根据主键更新一条记录 /// </summary> /// <param name="model">更新后的实体</param> /// <returns>是否成功</returns> public bool Update(WithdrawalsDetails model) { const string sql = @"UPDATE [dbo].[WithdrawalsDetails] SET createdAt=@createdAt,updatedAt=@updatedAt,userId=@userId,type=@type,number=@number,before=@before,after=@after,change=@change,state=@state WHERE [objectId] = @objectId"; return(SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@objectId", model.objectId.ToDBValue()), new SqlParameter("@createdAt", model.createdAt.ToDBValue()), new SqlParameter("@updatedAt", model.updatedAt.ToDBValue()), new SqlParameter("@userId", model.userId.ToDBValue()), new SqlParameter("@type", model.type.ToDBValue()), new SqlParameter("@number", model.number.ToDBValue()), new SqlParameter("@before", model.before.ToDBValue()), new SqlParameter("@after", model.after.ToDBValue()), new SqlParameter("@change", model.change.ToDBValue()), new SqlParameter("@state", model.state.ToDBValue())) > 0); }
/// <summary> /// 根据主键更新一条记录 /// </summary> /// <param name="model">更新后的实体</param> /// <returns>执行结果受影响行数</returns> public bool Update(WithdrawalsDetails model) { return(_dao.Update(model)); }
/// <summary> /// 向数据库中添加一条记录 /// </summary> /// <param name="model">要添加的实体</param> /// <returns>是否成功</returns> public bool Insert(WithdrawalsDetails model) { return(_dao.Insert(model)); }
///<summary> ///向数据库中添加一条记录 ///</summary> ///<param name="model">要添加的实体</param> public bool saveDetail(WithdrawalsDetails model, string userId) { return(_dao.saveDetail(model, userId)); }