/// <summary> /// 查询 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> /// <returns></returns> public List <E_Opinion> GetList(E_Opinion model, ref int total) { if (model.PageIndex <= 0) { model.PageIndex = 1; } List <E_Opinion> list; StringBuilder strSql = new StringBuilder(); StringBuilder whereSql = new StringBuilder(" where isdelete=0 "); strSql.Append(" select ROW_NUMBER() OVER ( ORDER BY opinionid desc) AS RID, * from dp_opinion "); if (model.opiniontypeid > 0) { whereSql.Append(" and opiniontypeid=@opiniontypeid"); } strSql.Append(whereSql); string CountSql = "SELECT COUNT(1) as RowsCount FROM (" + strSql.ToString() + ") AS CountList"; string pageSqlStr = "select * from ( " + strSql.ToString() + " ) as Temp_PageData where Temp_PageData.RID BETWEEN {0} AND {1}"; pageSqlStr = string.Format(pageSqlStr, (model.PageSize * (model.PageIndex - 1) + 1).ToString(), (model.PageSize * model.PageIndex).ToString()); using (IDbConnection conn = new SqlConnection(DapperHelper.GetConStr())) { list = conn.Query <E_Opinion>(pageSqlStr, model)?.ToList(); total = conn.ExecuteScalar <int>(CountSql, model); } return(list); }
/// <summary> /// 详情 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Info(int id) { E_Opinion model = new E_Opinion(); model.opinionid = id; ViewBag.Info = dal.GetInfoById(model); return(View()); }
/// <summary> /// 保存 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Save(E_Opinion model) { if (model != null && model.opinionid > 0) { return(dal.Update(model)); } return(dal.Add(model)); }
public ActionResult List(E_Opinion model) { model.PageIndex = Utils.GetInt(Request["page"]); int count = 0; ViewBag.list = dal.GetList(model, ref count); ViewBag.page = Utils.ShowPage(count, model.PageSize, model.PageIndex, 5); return(View()); }
/// <summary> /// 查询 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> /// <returns></returns> public E_Opinion GetInfoById(E_Opinion model) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from dp_opinion where opinionid=@opinionid"); using (IDbConnection conn = new SqlConnection(DapperHelper.GetConStr())) { model = conn.Query <E_Opinion>(strSql.ToString(), model)?.FirstOrDefault(); } return(model); }
/// <summary> /// 添加 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Add(E_Opinion model) { string sql = "INSERT INTO dp_opinion(opiniontypeid,[opinioncontent]) VALUES (@opiniontypeid,@opinioncontent)"; 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_Opinion model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update dp_opinion set isdelete=1 where opinionid=@opinionid "); using (IDbConnection conn = new SqlConnection(DapperHelper.GetConStr())) { int count = conn.Execute(strSql.ToString(), model); if (count > 0)//如果更新失败 { return(true); } else { return(false); } } }
/// <summary> /// 查询 /// </summary> /// <param name="model">model</param> /// <returns></returns> public List <E_Opinion> GetList(E_Opinion model) { if (model.PageIndex <= 0) { model.PageIndex = 1; } List <E_Opinion> list; StringBuilder strSql = new StringBuilder(); strSql.Append(@"select * from dp_themeopinion as A inner join dp_opinion as B on A.opinionid=B.opinionid where B.isdelete=0 and A.themeid=@themeid"); using (IDbConnection conn = new SqlConnection(DapperHelper.GetConStr())) { list = conn.Query <E_Opinion>(strSql.ToString(), model)?.ToList(); } return(list); }
/// <summary> /// 删除 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Delete(E_Opinion model) { return(dal.DeleteById(model)); }