/// <summary> /// 得到一个对象实体 /// </summary> public Comment DataRowToModel(DataRow row) { Comment model=new Comment(); if (row != null) { if(row["Id"]!=null && row["Id"].ToString()!="") { model.Id=long.Parse(row["Id"].ToString()); } if(row["TravelPartId"]!=null && row["TravelPartId"].ToString()!="") { model.TravelPartId=int.Parse(row["TravelPartId"].ToString()); } if(row["UserId"]!=null && row["UserId"].ToString()!="") { model.UserId=int.Parse(row["UserId"].ToString()); } if(row["Content"]!=null) { model.Content=row["Content"].ToString(); } if(row["ToUserId"]!=null && row["ToUserId"].ToString()!="") { model.ToUserId=int.Parse(row["ToUserId"].ToString()); } if(row["CreateTime"]!=null && row["CreateTime"].ToString()!="") { model.CreateTime=DateTime.Parse(row["CreateTime"].ToString()); } } return model; }
/// <summary> /// 增加一条数据 /// </summary> public long Add(Comment model) { StringBuilder strSql=new StringBuilder(); strSql.Append("insert into Comment("); strSql.Append("TravelPartId,UserId,Content,ToUserId,CreateTime)"); strSql.Append(" values ("); strSql.Append("@TravelPartId,@UserId,@Content,@ToUserId,@CreateTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@TravelPartId", SqlDbType.Int,4), new SqlParameter("@UserId", SqlDbType.Int,4), new SqlParameter("@Content", SqlDbType.NVarChar,200), new SqlParameter("@ToUserId", SqlDbType.Int,4), new SqlParameter("@CreateTime", SqlDbType.DateTime)}; parameters[0].Value = model.TravelPartId; parameters[1].Value = model.UserId; parameters[2].Value = model.Content; parameters[3].Value = model.ToUserId; parameters[4].Value = model.CreateTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters); if (obj == null) { return 0; } else { return Convert.ToInt64(obj); } }
// // GET: /Comment/Create public string Create(int travelPartId,int userId,int ? toUserId,string content) { if (travelPartId<=0||userId<=0||string.IsNullOrEmpty(content)) { return HttpRequestResult.StateNotNull; } var model = new Comment { TravelPartId = travelPartId, UserId = userId, Content = content, CreateTime = DateTime.Now }; if (toUserId!=null&&toUserId>0) { model.ToUserId = toUserId; } var result = _commentBll.Add(model); if (result>0) { return HttpRequestResult.StateOk; } return HttpRequestResult.StateError; }
/// <summary> /// 增加一条数据 /// </summary> public long Add(Comment model) { return dal.Add(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Comment model) { return dal.Update(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Comment model) { StringBuilder strSql=new StringBuilder(); strSql.Append("update Comment set "); strSql.Append("TravelPartId=@TravelPartId,"); strSql.Append("UserId=@UserId,"); strSql.Append("Content=@Content,"); strSql.Append("ToUserId=@ToUserId,"); strSql.Append("CreateTime=@CreateTime"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@TravelPartId", SqlDbType.Int,4), new SqlParameter("@UserId", SqlDbType.Int,4), new SqlParameter("@Content", SqlDbType.NVarChar,200), new SqlParameter("@ToUserId", SqlDbType.Int,4), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@Id", SqlDbType.BigInt,8)}; parameters[0].Value = model.TravelPartId; parameters[1].Value = model.UserId; parameters[2].Value = model.Content; parameters[3].Value = model.ToUserId; parameters[4].Value = model.CreateTime; parameters[5].Value = model.Id; int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 得到一个对象实体 /// </summary> public Comment GetModel(long Id) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 Id,TravelPartId,UserId,Content,ToUserId,CreateTime from Comment "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.BigInt) }; parameters[0].Value = Id; Comment model=new Comment(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }