Esempio n. 1
0
        public ActionResult GetShopInfo(int?shopId)
        {
            if (!shopId.HasValue)
            {
                return(new HttpStatusCodeResult(400));
            }
            Hmh.Core.Shop.Models.Shop shop = ShopContract.Shops.SingleOrDefault(s => s.Id == shopId.Value);
            if (shop == null)
            {
                return(new HttpStatusCodeResult(400));
            }

            var sp = new {
                shop.Name,
                shop.Region.Province,
                shop.Region.City,
                shop.Region.County,
                shop.HCoinLimit,
                ShopGoodsCategoryes = shop.ShopGoodsCategoryes.Select(sgc => new {
                    sgc.Id,
                    sgc.Name,
                    sgc.SortCode
                })
            };

            return(Json(sp, JsonRequestBehavior.AllowGet));
        }
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)));
                }
            }
        }