Exemple #1
0
        public ActionResult SetRecommend(string goodsCode)
        {
            // 先判断传递的参数是否为空
            if (string.IsNullOrEmpty(goodsCode))
            {
                return(Json("NullParam", JsonRequestBehavior.AllowGet));
            }
            // 再用 Code 来获取 goods 对象
            Goods goods = _goodsBLL.GetGoodsByCode(goodsCode);

            if (goods == null)
            {
                return(Json("ErrorParam", JsonRequestBehavior.AllowGet));
            }

            // 判断是否已经是推荐商品了
            // 如果是 则删掉它
            if (_recommendBLL.IsRecommend(goods.Id))
            {
                if (_recommendBLL.Remove(goods.Id))
                {
                    return(Json("True", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json("False", JsonRequestBehavior.AllowGet));
                }
            }
            // 不是 则新加
            else
            {
                ReCommend rec = new ReCommend();
                rec.Id          = Guid.NewGuid();
                rec.IsDeleted   = false;
                rec.GoodsId     = goods.Id;
                rec.DeletedTime = DateTime.MinValue.AddHours(8);
                rec.CreatedTime = DateTime.Now.Date;

                if (_recommendBLL.Add(rec))
                {
                    return(Json("True", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json("False", JsonRequestBehavior.AllowGet));
                }
            }
        }
Exemple #2
0
 public bool Add(ReCommend commend)
 {
     return(_recommendDAL.Insert(commend));
 }