Пример #1
0
        /// <summary>
        /// 添加到收藏列表
        /// </summary>
        /// <param name="favorite">收藏的物品对象</param>
        /// <param name="treasureUID">收藏物品的UID</param>
        /// <param name="returnUrl">返回的Url</param>
        /// <returns>重定向浏览器,浏览一个新的URL</returns>
        public RedirectToRouteResult AddToFavorite(Favorite favorite, Guid treasureUID, string returnUrl)
        {
            //获取当前UID的物品对象
            Treasure treasure = repository.Treasures.FirstOrDefault(t => t.TreasureUID == treasureUID);

            //如果物品对象存在,则添加收藏
            if (treasure != null)
            {
                favorite.AddItem(treasure, 1);
            }
            return(RedirectToAction(
                       actionName: "Index",
                       routeValues: new
            {
                returnUrl
            }
                       ));
        }