/// <summary> /// 根据typeid查询商品信息的分布视图 /// </summary> /// <param name="pageindex">当前页</param> /// <returns></returns> public ActionResult Show_typeid(int?pageindex, int?typeid) { ViewBag.GoodsPhoto = GoodsPhotoBll.SelectAllGoodsPhoto(); List <GoodsTable> list = null; if (typeid == null) { list = Session["Goods_typeid"] as List <GoodsTable>; ViewBag.count = Math.Ceiling(list.Count() / 12.0); } else { list = GoodsBll.SelectTypeidGoods(typeid ?? 0); if (list == null) { ViewBag.isnull = true; return(PartialView("Show", null)); } else { ViewBag.count = Math.Ceiling(list.Count() / 12.0); } } ViewBag.pageindex = pageindex; return(PartialView("Show", list.Skip(((pageindex ?? 1) - 1) * 12).Take(12).ToList())); }
/// <summary> /// 新增商品 /// </summary> /// <param name="Arr">图片数组</param> /// <param name="GoodsPrice">现价</param> /// <param name="GoodsName">名称</param> /// <param name="OldGoodsPrice">原价</param> /// <param name="GoodsInventory">库存</param> /// <param name="TID">分类id</param> /// <param name="GoodsDescribe">描述</param> /// <returns></returns> public JsonResult AddGoodsAjax() { GoodsTable good = new GoodsTable() { GoodsName = Request.Form["goodsname"], GoodsPrice = Convert.ToDecimal(Request.Form["goodsprice"]), OldGoodsPrice = Convert.ToDecimal(Request.Form["oldgoodsprice"]), TID = Convert.ToInt32(Request.Form["tid"]), GoodsInventory = Convert.ToInt32(Request.Form["goodsinventory"]), GoodsDescribe = Request.Form["goodsdescribe"] }; List <string> list = new List <string>(); for (int i = 0; i < Request.Files.Count; i++) { list.Add(Path.GetFileName(Request.Files[i].FileName)); } //调用新增方法 if (GoodsBll.AddGoods(good)) { //查询最后一条商品 GoodsTable lastgood = GoodsBll.SelectAllGoods().LastOrDefault(); //调用新增商品图片方法 if (GoodsPhotoBll.AddGoodsPhoto(lastgood.GoodsID, list)) { //保存图片 for (int i = 0; i < Request.Files.Count; i++) { Request.Files[i].SaveAs(Server.MapPath("~/Content/GoodImgs/" + Request.Files[i].FileName)); } return(Json(1, JsonRequestBehavior.AllowGet)); } } return(Json(0, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 修改商品信息 /// </summary> /// <param name="goodsfile">商品图片(多选)</param> /// <param name="good">商品对象</param> /// <param name="pageindex">当前页</param> /// <param name="typeid">分类id</param> /// <param name="text">查询内容</param> /// <returns></returns> public ActionResult GoodsUpdate(GoodsTable good, int?pageindex, int typeid, string text = "") { //添加商品图片 if (Request.Files.Count > 0) { string[] fileTypeStr = { "image/gif", "image/png", "image/jpeg", "image/jpg", "image/bmp" }; List <string> strlist = new List <string>(); for (int i = 0; i < Request.Files.Count; i++) { if (fileTypeStr.Contains(Request.Files[i].ContentType)) { string fileName = Path.GetFileName(Request.Files[i].FileName); strlist.Add(fileName); } } if (GoodsPhotoBll.AddGoodsPhoto(good.GoodsID, strlist)) { //保存文件 //应用程序需要有服务器UploadFile文件夹的读写权限 for (int i = 0; i < Request.Files.Count; i++) { Request.Files[i].SaveAs(Server.MapPath("~/Content/GoodImgs/" + Request.Files[i].FileName)); } } } //修改商品信息 GoodsBll.UpdateGoods(good); return(RedirectToAction("GoodsIndexPartial", "BacksTage", new { pageindex = pageindex, text = text, typeid = typeid })); }
// GET: Goods public ActionResult GoodsIndex(int?tid_1, int?typeid_1, int?typeid_2, string txt = "") { //清空session数据 Session.Remove("Goods"); Session.Remove("Goods_tid"); Session.Remove("Goods_typeid"); //获得所有分类数据 ViewBag.Type = TypeTableBll.SelectAllType(); ViewBag.GoodsPhoto = GoodsPhotoBll.SelectAllGoodsPhoto(); if (tid_1 != null) { //根据tid查询 Session["Goods_tid"] = GoodsBll.SelectTidGoods(tid_1 ?? 0); //ViewBag.tid = tid_1 ?? 0; } else if (typeid_1 != null) { //根据tiyeid查询 Session["Goods_typeid"] = GoodsBll.SelectTypeidGoods(typeid_1 ?? 0); } else if (typeid_2 != null) { Session["Goods_typeid_2"] = GoodsBll.SelectType1Goods(typeid_2 ?? 0); } else { Session["Goods"] = GoodsBll.SelectAllGoods().Where(p => p.GoodsName.Contains(txt) && p.IsDelte == 0).OrderBy(p => p.GoodsHot).ToList(); } return(View()); }
/// <summary> /// 查询商品订单信息 /// </summary> /// <param name="OrderId">订单id</param> /// <returns></returns> public JsonResult AjaxSelect(string OrderId) { OrderTable ord = OrderBll.SelectOneOrder(Convert.ToInt32(OrderId)); //获取图片路径 string filename = GoodsPhotoBll.SelectAllGoodsPhoto().FirstOrDefault(p => p.GoodsID == ord.GoodsID).PhotoPath; return(Json(new { oid = OrderId, gid = ord.GoodsID, gname = ord.GoodsTable.GoodsName, gimg = filename }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 根据tid查询商品信息的分布视图 /// </summary> /// <param name="pageindex">当前页</param> /// <returns></returns> public ActionResult Show_tid(int?pageindex) { ViewBag.GoodsPhoto = GoodsPhotoBll.SelectAllGoodsPhoto(); List <GoodsTable> list = Session["Goods_tid"] as List <GoodsTable>; ViewBag.count = Math.Ceiling(list.Count() / 12.0); ViewBag.pageindex = pageindex; return(PartialView("Show", list.Skip(((pageindex ?? 1) - 1) * 12).Take(12).ToList())); }
/// <summary> /// 查询所有商品信息的分布视图 /// </summary> /// <param name="pageindex"></param> /// <returns></returns> public ActionResult Show(int?pageindex) { ViewBag.GoodsPhoto = GoodsPhotoBll.SelectAllGoodsPhoto(); List <GoodsTable> list = GoodsBll.SelectAllGoods().Where(p => p.IsDelte == 0).ToList(); ViewBag.count = Math.Ceiling(list.Count() / 12.0); ViewBag.pageindex = pageindex; return(PartialView("Show", list.Skip(((pageindex ?? 1) - 1) * 12).Take(12).ToList())); }
// GET: 购物车首页 public ActionResult ShopCarIndex() { //商品图片 ViewBag.GoodsPhoto = GoodsPhotoBll.SelectAllGoodsPhoto(); //查询当前用户与购物车中的商品的收藏关系 ViewBag.UserCollection = CollectionBll.SelectUserCollection(Convert.ToInt32(Session["userid"])); //查询当前用户所有购物车信息 return(View(ShopingCarBll.SelectAllShopCar(Convert.ToInt32(Session["userid"])))); }
/// <summary> /// 查询一个商品的详情 /// </summary> /// <param name="GoodsID">商品id</param> /// <returns></returns> public JsonResult GoodsDesc(string GoodsID) { //查询商品的信息 GoodsTable good = GoodsBll.SelectAllGoods().SingleOrDefault(p => p.GoodsID == Convert.ToInt32(GoodsID)); //查询商品对应的所有图片 var goodsphoto = GoodsPhotoBll.SelectAllGoodsPhoto().Where(p => p.GoodsID == Convert.ToInt32(GoodsID)).Select(p => new { RID = p.RID, GoodsID = p.GoodsID, PhotoPath = p.PhotoPath }).ToList(); //查询所有最小的分类 var typelist = TypeTableBll.SelectSmallType().Select(p => new { typeid = p.TypeID, typename = p.TypeName }); JsonSerializerSettings jsonstring = new JsonSerializerSettings(); jsonstring.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; string list_1 = JsonConvert.SerializeObject(good, jsonstring); string list_2 = JsonConvert.SerializeObject(goodsphoto, jsonstring); string list_3 = JsonConvert.SerializeObject(typelist, jsonstring); return(Json(new { Good = list_1, GoodPhoto = list_2, GoodType = list_3 }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 商城首页 /// </summary> /// <returns></returns> public ActionResult Index() { //获取导航栏的分类数据 Session["Type"] = TypeTableBll.SelectTypeTable(); //获得所有分类数据 ViewBag.Type = TypeTableBll.SelectAllType(); //获取图片 ViewBag.GoodsPhoto = GoodsPhotoBll.SelectAllGoodsPhoto(); ViewBag.goods_1 = GoodsBll.SelectType1Goods(1).OrderBy(p => p.GoodsHot).Take(8); ViewBag.goods_2 = GoodsBll.SelectType1Goods(2).OrderBy(p => p.GoodsHot).Take(8); ViewBag.goods_3 = GoodsBll.SelectType1Goods(3).OrderBy(p => p.GoodsHot).Take(8); ViewBag.goods_4 = GoodsBll.SelectType1Goods(4).OrderBy(p => p.GoodsHot).Take(8); if (Session["userid"] != null) { Session["carcount"] = ShopingCarBll.SelectAllShopCar(Convert.ToInt32(Session["userid"])).Count(); } return(View(GoodsBll.SelectAllGoods().Where(p => p.IsDelte == 0).ToList())); }
// GET: User public ActionResult UserIndex() { //查询用户的订单 Session["userorder"] = OrderBll.SelectUserOrder(Convert.ToInt32(Session["userid"])); //获取所有图片 Session["goodphotos"] = GoodsPhotoBll.SelectAllGoodsPhoto(); //获得用户未查看的消息 try { ViewBag.nolook = NoticeBll.SelectUserNotice(Convert.ToInt32(Session["userid"])).Where(p => p.IsLook == 0).ToList(); } catch (Exception) { ViewBag.nolook = null; } return(View(UserInfoBll.SelectUser(Convert.ToInt32(Session["userid"])))); }
/// <summary> /// 后台商品管理 /// </summary> /// <returns></returns> public ActionResult BackGoodsIndex() { Session["li_1"] = 1; Session["li_2"] = 0; //商品的图片 Session["GoodsPhoto"] = GoodsPhotoBll.SelectAllGoodsPhoto(); //查询所有商品 List <GoodsTable> list = GoodsBll.SelectAllGoods(); if (list != null && list.Count() > 0) { Session["goodscount"] = list.Count(); } else { Session["goodscount"] = 0; } Session["goodpagecount"] = Math.Ceiling(list.Count() / 8.0); Session["allgoods"] = list.Take(8).ToList(); return(View()); }
/// <summary> /// 后台评论界面 /// </summary> /// <returns></returns> public ActionResult BackCommentIndex() { Session["li_1"] = 5; Session["li_2"] = 0; //查询所有评论 List <CommentTable> list = CommentBll.SelectAllComment().OrderByDescending(p => p.IsTop).ToList(); if (list != null && list.Count() > 0) { Session["plcount"] = list.Count(); } else { Session["plcount"] = 0; } ViewBag.SelectType = 0; Session["plpagecount"] = Math.Ceiling(list.Count() / 10.0); Session["allpl"] = list.Take(10).ToList(); //商品图片 Session["GoodsPhoto"] = GoodsPhotoBll.SelectAllGoodsPhoto(); return(View()); }
/// <summary> /// 商品详情 /// </summary> /// <param name="goodsid">商品id</param> /// <returns></returns> public ActionResult GoodsDesc(int goodsid) { //商品图片 ViewBag.GoodsPhoto = GoodsPhotoBll.SelectAllGoodsPhoto().Where(p => p.GoodsID == goodsid).ToList(); //商品的所有评价(置顶排序) List <CommentTable> list = CommentBll.SelectGoodsComment(goodsid).OrderByDescending(p => p.IsTop).ToList(); Session["GoodsComment"] = list; //用户是否收藏商品 ViewBag.iscollection = CollectionBll.SelectOneCollection(Convert.ToInt32(Session["userid"]), goodsid); //加载或更新用户购物车数量 if (Session["userid"] != null) { Session["carcount"] = ShopingCarBll.SelectAllShopCar(Convert.ToInt32(Session["userid"])).Count(); } //获取到的该商品的信息 GoodsTable good = GoodsBll.SelectGoodsIdGoods(goodsid); //相关商品的推荐(3条) ViewBag.GetGoods = GoodsBll.SelectGetGoods(good.TID ?? 0).Where(p => p.GoodsID != good.GoodsID).OrderBy(p => Guid.NewGuid()).Take(3).ToList(); Session["GoodsPhoto"] = GoodsPhotoBll.SelectAllGoodsPhoto(); return(View(good)); }
/// <summary> /// 商品图片删除 /// </summary> /// <param name="RID"></param> /// <returns></returns> public JsonResult GoodsImgDel(string RID) { return(Json(GoodsPhotoBll.GoodsPhotoDel(Convert.ToInt32(RID)), JsonRequestBehavior.AllowGet)); }