public JsonResult updateProduct(products product) { string res = "false"; try { if (product != null && product.productId != 0) { products DBProduct = ProductsBiz.CreateNew().getProductById(product.productId); if (product.status != null) { DBProduct.status = product.status; } var DBres = ProductsBiz.CreateNew().updateProductById(DBProduct); if (DBres) { res = "success"; CacheHelper.RemoveAllCache(); } } } catch (Exception e) { _Apilog.WriteLog("更新产品信息异常: " + e.Message); } return(Json(res)); }
public ActionResult product(string searchString, int searchStatus = 99) { AdminProductViewModels adminproduct = new AdminProductViewModels(); ProductsBiz Pbiz = ProductsBiz.CreateNew(); var ProductList = Pbiz.getProductList(); //根据名称或备注搜索产品信息 if (!string.IsNullOrEmpty(searchString)) { ProductList = ProductList.Where(w => (!string.IsNullOrEmpty(w.remark) && w.remark.Contains(searchString)) || w.productName.Contains(searchString)).ToList(); } //根据状态搜索产品 if (searchStatus != 99) { ProductList = ProductList.Where(w => w.status.Equals(searchStatus)).ToList(); } adminproduct.productList = ProductList; //页面产品标签绑定 var tablist = Pbiz.getAllTab(); List <CheckBoxListInfo> infos = new List <CheckBoxListInfo>(); foreach (tablist item in tablist) { infos.Add(new CheckBoxListInfo(item.tabId.ToString(), item.typeName, false)); } //ViewData["CheckBoxListOfTablist"] = infos; adminproduct.checkBoxList = infos; return(View(adminproduct)); }
/// <summary> /// 我的 页面 /// </summary> /// <returns></returns> public ActionResult UserHome(string code, string ignoreRegister) { #region 用户关注部分 try { _Apilog.WriteLog("begin code: " + code); Tuple <string, users> result = base.getUserInfoByAuthorize(code); ViewBag.headImg = "../images/noavatar.png";//缺省图片 if (!string.IsNullOrEmpty(result.Item1)) { _Apilog.WriteLog("redirectURL: " + result.Item1); return(Redirect(result.Item1)); } else if (result.Item2 != null) { ViewBag.userName = result.Item2.nickname; ViewBag.headImg = result.Item2.headimgurl; } } catch (Exception e) { _Apilog.WriteLog("exception:" + e.Message); } var res = base.getUserInfoByAuthorize(code); #endregion #region 绑定手机部分 //用户未点击跳过注册 并且电话为空 if (string.IsNullOrEmpty(ignoreRegister) && string.IsNullOrEmpty(res.Item2.phone)) { return(RedirectToAction("Register", "User", new { needRegister = "0", fromUrl = Request.RawUrl }));//跳转到注册页面,但不是必须注册 } #endregion #region 热销推荐部分 List <ProductsAndSalesNum> productsAndSalesNumList; var resCache = CacheHelper.GetCache("productsAndSalesNumList"); if (resCache != null) { productsAndSalesNumList = (List <ProductsAndSalesNum>)resCache; } else { productsAndSalesNumList = ProductsBiz.CreateNew().getAllProductsAndSalesNum(); if (productsAndSalesNumList != null) { var start = DateTime.Now; var expiredDate = start.AddHours(1); TimeSpan ts = expiredDate - start; CacheHelper.SetCache("productsAndSalesNumList", productsAndSalesNumList, ts); } } productsAndSalesNumList = productsAndSalesNumList.OrderByDescending(s => s.soldNum).Take(4).ToList(); ViewBag.ProjectUrl = base.projectURL; return(View(productsAndSalesNumList)); #endregion }
// GET: Products public ActionResult Index(int id, string code) { #region 用户信息部分 string userOpenId = string.Empty; Tuple <string, string> result = base.getUserOpenId(code); if (!string.IsNullOrEmpty(result.Item1)) { userOpenId = result.Item1; } else if (!string.IsNullOrEmpty(result.Item2)) { return(Redirect(result.Item2)); } ViewBag.userOpenId = userOpenId; ViewBag.userShopcartNum = ShopCartBiz.CreateNew().getUserCartsNum(userOpenId).ToString();//获取用户购物车数量 #endregion #region 产品信息部分 products products = new products(); var resCache = CacheHelper.GetCache("product_" + id.ToString()); if (resCache != null) { products = (products)resCache; } else { products = ProductsBiz.CreateNew().getProductById(id); if (products != null) { var start = DateTime.Now; var expiredDate = start.AddDays(1); TimeSpan ts = expiredDate - start; CacheHelper.SetCache("product_" + id.ToString(), products, ts); } else { return(RedirectToAction("Category")); } } ViewBag.PageName = "商品详情"; ViewBag.ProjectUrl = base.projectURL; #endregion //微信分享 ViewBag.appId = base.wechatAppid; ViewBag.appSecret = base.wechatAppSecret; ViewBag.timestamp = DateTime.Now.Ticks.ToString().Substring(0, 10); ViewBag.nonceStr = Guid.NewGuid().ToString().Substring(0, 16); ViewBag.url = Request.Url.ToString(); string jsapi_ticket = WeiXinSDK.WeiXinJSSDK.GetJsapiTicket(ViewBag.appId, ViewBag.appSecret); ViewBag.signature = WeiXinSDK.WeiXinJSSDK.GetJsSdkSignature(ViewBag.nonceStr, jsapi_ticket, ViewBag.timestamp.ToString(), ViewBag.url); ViewBag.shareImg = string.Concat(base.projectURL, products.pic1).Replace("/img/", "/Thumbnail/"); return(View(products)); }
public void ShowAllProducts(IProductListView view) { ProductsBiz biz = new ProductsBiz(); IList <Product> products = new List <Product> (); VoteDAL votedal = new VoteDAL(); foreach (var t in biz.ListAll()) { products.Add(new Product() { Id = t.Id, Title = t.Title, Pic = t.PicSource.Replace("~", "."), VoteCount = votedal.Count(t.Id) }); } view.Show(products); }
public JsonResult GetProd2tabs(int productId) { string tabs = string.Empty; var products2Tab = ProductsBiz.CreateNew().getProduct2Tabs(productId); if (products2Tab != null) { foreach (var item in products2Tab) { if (item.status == 1) { tabs += item.tabId + ","; } } } return(Json(tabs)); }
public void ShowPdf(int productId, IProductDetailView view) { ProductsBiz biz = new ProductsBiz(); var product = biz.Detail(productId); if (product != null) { view.Show(new ProductView() { PdfSource = product.PDFSource.Replace("~", "."), Title = product.Title }); } else { view.ShowNotFound(); } }
public JsonResult GetProdInfo(int productId) { products products = new products(); var resCache = CacheHelper.GetCache("product_" + productId.ToString()); if (resCache != null) { products = (products)resCache; } else { products = ProductsBiz.CreateNew().getProductById(productId, false); if (products != null) { var start = DateTime.Now; var expiredDate = start.AddDays(1); TimeSpan ts = expiredDate - start; CacheHelper.SetCache("product_" + productId.ToString(), products, ts); } } return(Json(products)); }
// GET: Index public ActionResult Index() { ViewBag.PageType = "ProductsPage"; ViewBag.ProjectUrl = base.projectURL; List <products2Tab> products2TabList = new List <products2Tab>(); var resCache = CacheHelper.GetCache("homepageProductList"); if (resCache != null) { products2TabList = (List <products2Tab>)resCache; } else { products2TabList = ProductsBiz.CreateNew().getHomePageShowProducts2Tab(); if (products2TabList != null) { var start = DateTime.Now; var expiredDate = start.AddDays(1); TimeSpan ts = expiredDate - start; CacheHelper.SetCache("homepageProductList", products2TabList, ts); } } return(View(products2TabList)); }
public JsonResult CreateOrUploadProds(FormCollection collection) { string r_productId = collection["r_productId"]; //编号 string r_product = collection["r_product"]; //产品名称 string r_size = collection["r_size"]; //规格 string r_price = collection["r_price"]; //原价 string r_oPrice = collection["r_oPrice"]; //折后价 string r_cost = collection["r_cost"]; //成本价 string r_APN = collection["r_APN"]; //产地 string r_weight = collection["r_weight"]; //净重 string r_condition = collection["r_condition"]; //存放条件 string r_remark = collection["r_remark"]; //产品描述 string main_pic = "pic1"; // Request.Params["main_pic"];//主图图片 string tablist = Request.Params["tablist"]; products prod = new products(); ProductsBiz productBiz = ProductsBiz.CreateNew(); if (!string.IsNullOrEmpty(r_productId)) { prod = productBiz.getProductById(Convert.ToInt32(r_productId), false); } prod.productName = r_product.Trim(); prod.specs = r_size.Trim(); prod.originalPrice = Convert.ToDecimal(r_price.Trim()); prod.discountedPrice = Convert.ToDecimal(r_oPrice.Trim()); if (!string.IsNullOrEmpty(r_cost)) { prod.cost = Convert.ToDecimal(r_cost.Trim()); } prod.origin = r_APN.Trim(); prod.nw = r_weight.Trim(); prod.storageCondition = r_condition.Trim(); prod.remark = r_remark.Trim(); prod.showPic = main_pic.Trim(); HttpPostedFileBase file1 = Request.Files["file1"]; string res1 = savefiles(file1, r_product); if (!string.IsNullOrEmpty(res1)) { this.saveThumbnail(file1, res1); prod.pic1 = "/img/" + res1; } HttpPostedFileBase file2 = Request.Files["file2"]; string res2 = savefiles(file2, r_product); if (!string.IsNullOrEmpty(res2)) { prod.pic2 = "/img/" + res2; } HttpPostedFileBase file3 = Request.Files["file3"]; string res3 = savefiles(file3, r_product); if (!string.IsNullOrEmpty(res3)) { prod.pic3 = "/img/" + res3; } HttpPostedFileBase file4 = Request.Files["file4"]; string res4 = savefiles(file4, r_product); if (!string.IsNullOrEmpty(res4)) { prod.pic4 = "/img/" + res4; } HttpPostedFileBase file5 = Request.Files["file5"]; string res5 = savefiles(file5, r_product); if (!string.IsNullOrEmpty(res5)) { prod.pic5 = "/img/" + res5; } HttpPostedFileBase filePicDetail1 = Request.Files["picDetail1"]; string picDetail1 = savefiles(filePicDetail1, r_product); if (!string.IsNullOrEmpty(picDetail1)) { prod.picDetail1 = "/img/" + picDetail1; } HttpPostedFileBase filePicDetail2 = Request.Files["picDetail2"]; string picDetail2 = savefiles(filePicDetail2, r_product); if (!string.IsNullOrEmpty(picDetail2)) { prod.picDetail2 = "/img/" + picDetail2; } HttpPostedFileBase filePicDetail3 = Request.Files["picDetail3"]; string picDetail3 = savefiles(filePicDetail3, r_product); if (!string.IsNullOrEmpty(picDetail3)) { prod.picDetail3 = "/img/" + picDetail3; } HttpPostedFileBase filePicDetail4 = Request.Files["picDetail4"]; string picDetail4 = savefiles(filePicDetail4, r_product); if (!string.IsNullOrEmpty(picDetail4)) { prod.picDetail4 = "/img/" + picDetail4; } try { //新增 if (string.IsNullOrEmpty(r_productId)) { r_productId = productBiz.insertProduct(prod, tablist); } else { productBiz.updateProductById(prod, tablist); } var prodInfo = productBiz.getProductById(Convert.ToInt32(r_productId), false); productchangelog changelog = new productchangelog(); if (HttpContext.Session["LoginedUserName"] != null) { changelog.Operator = HttpContext.Session["LoginedUserName"].ToString(); } changelog.LogTime = System.DateTime.Now; changelog.productId = prodInfo.productId; changelog.productName = prodInfo.productName; changelog.specs = prodInfo.specs; changelog.originalPrice = prodInfo.originalPrice; changelog.discountedPrice = prodInfo.discountedPrice; changelog.discountedExpiredDate = prodInfo.discountedExpiredDate; changelog.cost = prodInfo.cost; changelog.pic1 = prodInfo.pic1; changelog.pic2 = prodInfo.pic2; changelog.pic3 = prodInfo.pic3; changelog.pic4 = prodInfo.pic4; changelog.pic5 = prodInfo.pic5; changelog.picDetail1 = prodInfo.picDetail1; changelog.picDetail2 = prodInfo.picDetail2; changelog.picDetail3 = prodInfo.picDetail3; changelog.picDetail4 = prodInfo.picDetail4; changelog.showPic = prodInfo.showPic; changelog.origin = prodInfo.origin; changelog.nw = prodInfo.nw; changelog.storageCondition = prodInfo.storageCondition; changelog.remark = prodInfo.remark; changelog.createDate = prodInfo.createDate; changelog.status = prodInfo.status; changelog.column1 = prodInfo.column1; changelog.column2 = prodInfo.column2; productBiz.insertProductChangeLog(changelog); CacheHelper.RemoveAllCache(); return(new JsonResult { Data = new { _code = 100, _msg = "上传成功" }, JsonRequestBehavior = JsonRequestBehavior.DenyGet }); } catch (Exception e) { _Apilog.WriteLog("新增或更新产品信息异常: " + e.Message); return(new JsonResult { Data = new { _code = 200, _msg = "上传失败" }, JsonRequestBehavior = JsonRequestBehavior.DenyGet }); } }
public ActionResult Category(string sortOrder, string searchString, string typeName) { List <ProductsAndSalesNum> productsAndSalesNumList; var resCache = CacheHelper.GetCache("productsAndSalesNumList"); if (resCache != null) { productsAndSalesNumList = (List <ProductsAndSalesNum>)resCache; } else { productsAndSalesNumList = ProductsBiz.CreateNew().getAllProductsAndSalesNum(); if (productsAndSalesNumList != null) { var start = DateTime.Now; var expiredDate = start.AddHours(1); TimeSpan ts = expiredDate - start; //CacheHelper.SetCache("productsAndSalesNumList", productsAndSalesNumList, ts); } } ViewBag.TypeName = string.IsNullOrEmpty(typeName) ? "all" : typeName; ViewBag.SortMethod = "defaultSort"; ViewBag.ReleaseDateSortParm = sortOrder == "date" ? "date_desc" : "date"; ViewBag.SalesSortParm = sortOrder == "sales" ? "sales_desc" : "sales"; ViewBag.PriceSortParm = sortOrder == "price" ? "price_desc" : "price"; sortOrder = string.IsNullOrEmpty(sortOrder) ? "defaultSort" : sortOrder; ViewBag.SortClass = sortOrder.IndexOf("desc") > 0 ? "icon_sort_down" : "icon_sort_up"; if (!string.IsNullOrEmpty(searchString)) { productsAndSalesNumList = productsAndSalesNumList.Where(w => (!string.IsNullOrEmpty(w.remark) && w.remark.Contains(searchString)) || w.productName.Contains(searchString)).ToList(); } //过滤类型 if (!string.IsNullOrEmpty(typeName) && typeName.ToLower() != "all") { productsAndSalesNumList = productsAndSalesNumList.Where(w => (!string.IsNullOrEmpty(w.typeName) && w.typeName.Equals(typeName))).ToList(); } else { productsAndSalesNumList.ForEach(w => w.typeName = ""); productsAndSalesNumList.Distinct().ToList(); } switch (sortOrder) { case "date": productsAndSalesNumList = productsAndSalesNumList.OrderBy(s => s.createDate).ToList(); ViewBag.SortMethod = "date"; break; case "date_desc": productsAndSalesNumList = productsAndSalesNumList.OrderByDescending(s => s.createDate).ToList(); ViewBag.SortMethod = "date"; break; case "sales": productsAndSalesNumList = productsAndSalesNumList.OrderBy(s => s.soldNum).ToList(); ViewBag.SortMethod = "sales"; break; case "sales_desc": productsAndSalesNumList = productsAndSalesNumList.OrderByDescending(s => s.soldNum).ToList(); ViewBag.SortMethod = "sales"; break; case "price": productsAndSalesNumList = productsAndSalesNumList.OrderBy(s => s.discountedPrice).ToList(); ViewBag.SortMethod = "price"; break; case "price_desc": productsAndSalesNumList = productsAndSalesNumList.OrderByDescending(s => s.discountedPrice).ToList(); ViewBag.SortMethod = "price"; break; case "defaultSort": productsAndSalesNumList = productsAndSalesNumList.OrderByDescending(s => s.productId).ToList(); break; default: productsAndSalesNumList = productsAndSalesNumList.OrderByDescending(s => s.productId).ToList(); break; } ViewBag.PageType = "ProductsPage"; ViewBag.PageName = "产品列表"; CategoryViewModel viewModel = new CategoryViewModel(); viewModel.productsAndSalesNum = productsAndSalesNumList; viewModel.tabList = ProductsBiz.CreateNew().getAllTabList(); ViewBag.ProjectUrl = base.projectURL; return(View(viewModel)); }