示例#1
0
        /// <summary>
        /// 添加会员商品收藏.
        /// </summary>
        /// <param name="productId">
        /// The product id.
        /// </param>
        /// <returns>
        /// The <see cref="JsonResult"/>.
        /// </returns>
        public JsonResult AddCollect(string productId)
        {
            try
            {
                var userID = this.GetUserID();
                if (userID == 0)
                {
                    return this.Json(new AjaxResponse(3, "未登录"));
                }

                var userCollectRecordService = new UserCollectRecordService();
                var userCollectRecord = userCollectRecordService.QueryRow(userID, int.Parse(productId));
                if (userCollectRecord != null)
                {
                    return this.Json(new AjaxResponse(2, "已收藏过"));
                }

                userCollectRecord = new User_CollectRecord { UserID = userID, ProductID = int.Parse(productId) };
                userCollectRecordService.Add(userCollectRecord);
                return this.Json(new AjaxResponse(1, "收藏成功"));
            }
            catch (Exception exception)
            {
                return this.Json(new AjaxResponse(0, "收藏失败!:" + exception.Message));
            }
        }