/// <summary> /// 详情 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Info(int id) { E_Theme model = new E_Theme(); model.themeid = id; ViewBag.Info = dal.GetInfoById(model); return(View()); }
/// <summary> /// 保存 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Save(E_Theme model) { if (model != null && model.themeid > 0) { return(dal.Update(model)); } return(dal.Add(model)); }
/// <summary> /// 查询 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> /// <returns></returns> public E_Theme GetInfoById(E_Theme model) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from dp_theme where themeid=@themeid"); using (IDbConnection conn = new SqlConnection(DapperHelper.GetConStr())) { model = conn.Query <E_Theme>(strSql.ToString(), model)?.FirstOrDefault(); } return(model); }
/// <summary> /// 添加 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Add(E_Theme model) { string sql = "INSERT INTO dp_theme([themename]) VALUES (@themename)"; 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 Update(E_Theme model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update dp_theme set themename=@themename where themeid=@themeid "); 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"></param> /// <returns></returns> public bool Delete(E_Theme model) { return(dal.DeleteById(model)); }