Esempio n. 1
0
        public ActionResult DelCollect(int?id)
        {
            OperationResult result = OperationResult.NoChanged;

            if (id.HasValue && id.Value > 0)
            {
                result = IdentityContract.DeleteCollects(id.Value);
            }
            return(Json(result.ToAjaxResult()));
        }
Esempio n. 2
0
        public ActionResult DoCollect(CollectViewModel model)
        {
            model.CheckNotNull(nameof(model));
            if (CurrentUser == null)
            {
                return(Json(new AjaxResult("未登录", AjaxResultType.Error)));
            }
            //获取收藏类型
            CollectType collectType = GetCollectType(model.Type);
            //检查收藏状态
            Collect collect = IdentityContract.Collects.SingleOrDefault(c => c.User.Id == CurrentUser.Id && c.AboutId == model.AboutId && c.Type == collectType);

            if (collect == null)
            {
                CollectInputDto dto = new CollectInputDto()
                {
                    UserId  = CurrentUser.Id,
                    AboutId = model.AboutId,
                    Pic     = "default",
                    Type    = collectType
                };

                if (collectType == CollectType.Goods)
                {
                    //检查商品
                    Hmh.Core.Goods.Models.Goods goods = GoodsContract.Goodss.SingleOrDefault(g => g.Id == model.AboutId);
                    if (goods == null)
                    {
                        return(Json(new AjaxResult("错误商品不存在", AjaxResultType.Error)));
                    }
                    dto.Name = goods.Name;
                }
                else
                {
                    //检查店铺
                    Hmh.Core.Shop.Models.Shop shop = ShopContract.Shops.SingleOrDefault(s => s.Id == model.AboutId);
                    if (shop == null)
                    {
                        return(Json(new AjaxResult("错误店铺不存在", AjaxResultType.Error)));
                    }
                    dto.Name = shop.Name;
                }

                OperationResult result = IdentityContract.AddCollects(dto);
                if (result.ResultType == OperationResultType.Success)
                {
                    return(Json(new AjaxResult("已收藏", AjaxResultType.Success)));
                }
                else
                {
                    return(Json(new AjaxResult("失败", AjaxResultType.Error)));
                }
            }
            else
            {
                OperationResult result = IdentityContract.DeleteCollects(collect.Id);
                if (result.ResultType == OperationResultType.Success)
                {
                    return(Json(new AjaxResult("收藏", AjaxResultType.Success)));
                }
                else
                {
                    return(Json(new AjaxResult("失败", AjaxResultType.Error)));
                }
            }
        }