/// <summary> /// 详情 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Info(int id) { E_CommentItem model = new E_CommentItem(); model.commentitemid = id; ViewBag.Info = dal.GetInfoById(model); return(View()); }
/// <summary> /// 保存 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Save(E_CommentItem model) { if (model != null && model.commentitemid > 0) { return(dal.Update(model)); } return(dal.Add(model)); }
/// <summary> /// 查询 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> /// <returns></returns> public E_CommentItem GetInfoById(E_CommentItem model) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from dp_commentitem where commentitemid=@commentitemid"); using (IDbConnection conn = new SqlConnection(DapperHelper.GetConStr())) { model = conn.Query <E_CommentItem>(strSql.ToString(), model)?.FirstOrDefault(); } return(model); }
/// <summary> /// 添加 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Add(E_CommentItem model) { string sql = "INSERT INTO dp_commentitem(commenttypeid,[title]) VALUES (@commenttypeid,@title)"; using (IDbConnection conn = new SqlConnection(DapperHelper.GetConStr())) { int count = conn.Execute(sql, model); if (count > 0)//如果更新失败 { return(true); } else { return(false); } } }
/// <summary> /// 删除 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool DeleteById(E_CommentItem model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update dp_commentitem set isdelete=1 where commentitemid=@commentitemid "); using (IDbConnection conn = new SqlConnection(DapperHelper.GetConStr())) { int count = conn.Execute(strSql.ToString(), model); if (count > 0)//如果更新失败 { return(true); } else { return(false); } } }
/// <summary> /// 查询 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> /// <returns></returns> public List <E_CommentItem> GetList(E_CommentItem model) { List <E_CommentItem> list; StringBuilder strSql = new StringBuilder(); StringBuilder whereSql = new StringBuilder(" where isdelete=0 "); strSql.Append("select * from dp_commentitem "); if (model.commenttypeid > 0) { whereSql.Append(" and commenttypeid=@commenttypeid"); } strSql.Append(whereSql); using (IDbConnection conn = new SqlConnection(DapperHelper.GetConStr())) { list = conn.Query <E_CommentItem>(strSql.ToString(), model)?.ToList(); } return(list); }
/// <summary> /// 删除 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Delete(E_CommentItem model) { return(dal.DeleteById(model)); }
public ActionResult List(E_CommentItem model) { ViewBag.list = dal.GetList(model); return(View()); }