public int UpdateGoods(T_Goods model) { using (IDbConnection conn = DapperAdapter.MySQLOpenConnection(ConfigurationHelper.MySQLConnectionStr)) { string updateSql = "UPDATE T_Goods SET parentID=@parentID,img=@img,GoodsName=@GoodsName,Price=@Price,status=@status,GoodsInfo=@GoodsInfo,updateTime=@updateTime WHERE id=@id;"; return(conn.Execute(updateSql, model)); } }
public int SaveGoods(T_Goods model) { using (IDbConnection conn = DapperAdapter.MySQLOpenConnection(ConfigurationHelper.MySQLConnectionStr)) { string addSQL = @"INSERT INTO T_Goods (parentID,img,GoodsName,Price,status,GoodsInfo,updateTime,createTime) VALUES(@parentID,@img,@GoodsName,@Price,@status,@GoodsInfo,@updateTime,@createTime);"; return(conn.Execute(addSQL, model)); } }
public JsonResult GetGoodsById(int goodsId) { T_GoodsDAO goodsDao = new T_GoodsDAO(); T_Goods goods = goodsDao.GetById(goodsId); if (goods == null) { goods = new T_Goods(); } return(Json(goods)); }
public JsonResult EditGoods(T_Goods goods) { T_GoodsDAO dao = new T_GoodsDAO(); if (dao.GetById(goods.id) == null) { dao.Add(goods); } else { dao.Update(goods); } return(Json("success")); }
public ActionResult Show(int goodsId) { T_CommentDAO dao = new T_CommentDAO(); T_GoodsDAO goodsDao = new T_GoodsDAO(); List <T_Comment> list = dao.getByGoodsId(goodsId).ToList(); T_Goods goods = goodsDao.GetById(goodsId); ViewBag.commentList = list; ViewBag.goods = goods; ViewData["Title"] = "查看商品"; ViewData["username"] = HttpContext.Session.GetString("username"); return(View()); }
public ActionResult GetGoodsPage(string pagination, string pid, string keyword) { Pagination paginationobj = pagination.ToObject <Pagination>(); T_Goods goods = new T_Goods(); goods.pageIndex = paginationobj.page; goods.pageSize = paginationobj.rows; goods.totalCount = paginationobj.total; goods.orderBy = paginationobj.sidx + " " + paginationobj.sord; goods.parentID = pid.ToInt(); goods.GoodsName = keyword; List <T_Goods> list = this._goods.GetGoodsPage(goods); List <int> ids = new List <int>(); WebSecurityHelper.CommonController comm = new WebSecurityHelper.CommonController(); foreach (var item in list) { if (!string.IsNullOrWhiteSpace(item.img)) { item.img = comm.GetURL("/Content/img/") + item.img; } ids.Add(item.id); } List <T_RelateLable> relates = this._letale.GetRelateLables(string.Join(",", ids)); foreach (var item in list) { IEnumerable <T_RelateLable> items = relates.Where(w => w.fromID == item.id); string html = ""; foreach (var lable in items) { html += "<span class='label label-primary'>" + lable.lableName + "</span> "; } item.lables = html; } var jsonData = new { rows = list, total = list.Count > 0 ? list[0].total : 0, page = paginationobj.page, records = list.Count > 0 ? list[0].totalCount : 0 }; return(Success(jsonData)); }
public ActionResult SaveGoodsTea(T_Goods model) { int result = 0; if (!string.IsNullOrEmpty(model.img)) { LogHelper.Info("img is exist and length" + model.img.Length); } if (model.id == 0) { model.updateTime = model.createTime = DateTime.Now; model.status = 1; string path = Server.MapPath("~/Content/img/"); string imgPath = Common.ImgBase64.Base64StringToImage(model.img, path); model.img = imgPath; result = this._goods.SaveGoods(model); } else { T_Goods oldData = this._goods.GetGoodsData(model.id); if (oldData.img != model.img) { if (model.img.Contains(oldData.img)) { model.img = oldData.img; } else { string path = Server.MapPath("~/Content/img/"); string imgPath = Common.ImgBase64.Base64StringToImage(model.img, path); model.img = imgPath; LogHelper.Info("img is exist and path:" + imgPath); } } model.updateTime = DateTime.Now; result = this._goods.UpdateGoods(model); } return(Response(result)); }
public ActionResult EditGoods(int id, int pid) { T_Goods goods = this._goods.GetGoodsData(id); if (null == goods) { goods = new T_Goods(); goods.parentID = pid; } else { if (!string.IsNullOrWhiteSpace(goods.img)) { goods.img = new WebSecurityHelper.CommonController().GetURL("/Content/img/") + goods.img; } } return(View(goods)); }
public List <T_Goods> GetGoodsPage(T_Goods model) { using (IDbConnection conn = DapperAdapter.MySQLOpenConnection(ConfigurationHelper.MySQLConnectionStr)) { DynamicParameters param = new DynamicParameters(); StringBuilder sb = new StringBuilder(); sb.AppendLine("SELECT * FROM T_Goods WHERE 1=1 "); if (model.parentID > 0) { sb.AppendLine(" AND parentID=@parentID "); param.Add("@parentID", model.parentID); } if (!string.IsNullOrWhiteSpace(model.GoodsName)) { sb.AppendLine(" AND GoodsName LIKE @GoodsName"); param.Add("@GoodsName", "%" + model.GoodsName.Trim() + "%"); } sb.AppendLine(" ORDER BY " + model.orderBy); string sqlCount = sb.ToString().Replace("SELECT * ", " SELECT count(1) totalCount "); //分页记录列表 var list = conn.Query <T_Goods>(sb.ToString(), param).ToList(); if (list != null && list.Count() > 0) { //总记录数列表 dynamic identity = conn.Query(sqlCount, param).Single(); list[0].totalCount = Convert.ToInt64(identity.totalCount); list[0].pageIndex = model.pageIndex; list[0].pageSize = model.pageSize; } return(list); } }