public bool addfollow([FromBody] JObject json) { string token = HttpContext.Current.Request.Headers["Authorization"].ToString(); if (new Cook.BLL.users().addfollow(common.getIdByToken(token))) { //添加到about string[] info = new Cook.BLL.users().getuserinfo(token); Cook.Model.aboutMe_ model = new Cook.Model.aboutMe_(); model.sourceId = Convert.ToInt32(info[0]); model.sourceName = info[1]; model.time = json["time"].ToString(); string id = json["id"].ToString(); new Cook.BLL.follow_().addfoll(model, id); //改follow Cook.Model.follow_ collect = new Cook.Model.follow_(); collect.id = Convert.ToInt32(json["id"]); collect.time = json["time"].ToString(); return(new Cook.BLL.follow_().add(collect, token)); } else { return(false); } }
/// <summary> /// 更新一条数据 /// </summary> public override bool Update(Cook.Model.follow_ model, string tableid) { StringBuilder strSql = new StringBuilder(); strSql.Append("update follow_" + tableid + " set "); strSql.Append("id=@id,"); strSql.Append("time=@time"); strSql.Append(" where "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@time", SqlDbType.VarChar, 12) }; parameters[0].Value = model.id; parameters[1].Value = model.time; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public override bool Add(Cook.Model.follow_ model, string tableid) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into follow_" + tableid + "("); strSql.Append("id,time)"); strSql.Append(" values ("); strSql.Append("@id,@time)"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@time", SqlDbType.VarChar, 12) }; parameters[0].Value = model.id; parameters[1].Value = model.time; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public override Cook.Model.follow_ GetModel(string oid, string tableid) { try { int id; Int32.TryParse(oid, out id); //该表无主键信息,请自定义主键/条件字段 StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,time from follow_" + tableid + " "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Cook.Model.follow_ model = new Cook.Model.follow_(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } } catch (Exception) { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public override Cook.Model.follow_ DataRowToModel(DataRow row) { Cook.Model.follow_ model = new Cook.Model.follow_(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["time"] != null) { model.time = row["time"].ToString(); } } return(model); }
//根据token返回和id 添加 public bool add(Cook.Model.follow_ model, string token) { string tableid = new Cook.DAL.load().GetIdByToken(token); return(Add(model, tableid)); }