/// <summary> /// 移到我的收藏 /// </summary> private void Collect() { string strCartId = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("StrProductId")); if (string.IsNullOrEmpty(strCartId)) { ResponseHelper.Write("error|请选择商品!"); ResponseHelper.End(); } if (base.UserId == 0) { ResponseHelper.Write("error|还未登录!"); ResponseHelper.End(); } int[] ids = Array.ConvertAll <string, int>(strCartId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k)); foreach (var id in ids) { if (ProductCollectBLL.Read(id, base.UserId).Id < 1) { ProductCollectInfo productCollect = new ProductCollectInfo(); productCollect.ProductId = id; productCollect.Tm = RequestHelper.DateNow; productCollect.UserId = base.UserId; ProductCollectBLL.Add(productCollect); } } ResponseHelper.Write("error|成功收藏!"); ResponseHelper.End(); }
/// <summary> /// 收藏产品 /// </summary> public void Collect() { string result = string.Empty; int productID = RequestHelper.GetQueryString <int>("ProductID"); if (productID > 0) { if (base.UserId == 0) { result = "还未登录"; } else { if (ProductCollectBLL.Read(productID, base.UserId).Id > 0) { result = "您已经收藏了该产品"; } else { ProductCollectInfo productCollect = new ProductCollectInfo(); productCollect.ProductId = productID; productCollect.Tm = RequestHelper.DateNow; productCollect.UserId = base.UserId; ProductCollectBLL.Add(productCollect); result = "成功收藏"; } } } else { result = "请选择产品"; } ResponseHelper.Write(result); ResponseHelper.End(); }
private void Collect() { string result = string.Empty; int productId = RequestHelper.GetQueryString <int>("id"); if (productId > 0) { if (base.UserId == 0) { result = "还未登录"; } else { var productCollect = ProductCollectBLL.Read(productId, base.UserId) ?? new ProductCollectInfo(); if (productCollect.Id > 0) { ProductCollectBLL.Delete(new int[] { productCollect.Id }, base.UserId); result = "已取消收藏"; } else { productCollect.ProductId = productId; productCollect.Tm = RequestHelper.DateNow; productCollect.UserId = base.UserId; ProductCollectBLL.Add(productCollect); result = "成功收藏"; } } } else { result = "请选择产品"; } ResponseHelper.Write(result); ResponseHelper.End(); }