当前位置: 首页>>代码示例>>C#>>正文


C# ItemInfo.IncrementDislikes方法代码示例

本文整理汇总了C#中ItemInfo.IncrementDislikes方法的典型用法代码示例。如果您正苦于以下问题:C# ItemInfo.IncrementDislikes方法的具体用法?C# ItemInfo.IncrementDislikes怎么用?C# ItemInfo.IncrementDislikes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ItemInfo的用法示例。


在下文中一共展示了ItemInfo.IncrementDislikes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LikeItem

        /// <summary>
        /// 
        /// </summary>
        /// <param name="core"></param>
        /// <param name="itemType"></param>
        /// <param name="itemId"></param>
        /// <param name="rating"></param>
        /// <remarks>ItemRated should implement a transaction.</remarks>
        public static void LikeItem(Core core, ItemKey itemKey, LikeType like)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            if (itemKey.Id < 1)
            {
                throw new InvalidItemException();
            }

            if (like < LikeType.Dislike || like > LikeType.Like)
            {
                throw new InvalidLikeException();
            }

            /* after 7 days release the IP for dynamics ip fairness */
            SelectQuery query = Like.GetSelectQueryStub(core, typeof(Like));
            query.AddCondition("like_item_id", itemKey.Id);
            query.AddCondition("like_item_type_id", itemKey.TypeId);
            QueryCondition qc1 = query.AddCondition("user_id", core.LoggedInMemberId);
            QueryCondition qc2 = qc1.AddCondition(ConditionRelations.Or, "like_ip", core.Session.IPAddress.ToString());
            qc2.AddCondition("like_time_ut", ConditionEquality.GreaterThan, UnixTime.UnixTimeStamp() - 60 * 60 * 24 * 7);

            /*DataTable ratingsTable = db.Query(string.Format("SELECT user_id FROM ratings WHERE rate_item_id = {0} AND rate_item_type = '{1}' AND (user_id = {2} OR (rate_ip = '{3}' AND rate_time_ut > UNIX_TIMESTAMP() - (60 * 60 * 24 * 7)))",
                itemId, Mysql.Escape(itemType), loggedInMember.UserId, session.IPAddress.ToString()));*/

            DataTable likesTable = core.Db.Query(query);

            ItemInfo ii = null;

            try
            {
                ii = new ItemInfo(core, itemKey);
            }
            catch (InvalidIteminfoException)
            {
                ii = ItemInfo.Create(core, itemKey);
            }

            if (likesTable.Rows.Count > 0)
            {
                Like liked = new Like(core, likesTable.Rows[0]);

                if (liked.Liking == like)
                {
                    throw new AlreadyLikedException();
                }

                switch (like)
                {
                    case LikeType.Like:
                        ii.DecrementDislikes();
                        ii.IncrementLikes();
                        break;
                    case LikeType.Dislike:
                        ii.DecrementLikes();
                        ii.IncrementDislikes();
                        break;
                }

                UpdateQuery uQuery = new UpdateQuery("likes");
                uQuery.AddField("like_time_ut", UnixTime.UnixTimeStamp());
                uQuery.AddField("like_liking", (sbyte)like);
                uQuery.AddField("like_ip", core.Session.IPAddress.ToString());
                uQuery.AddCondition("user_id", core.LoggedInMemberId);
                uQuery.AddCondition("like_item_id", itemKey.Id);
                uQuery.AddCondition("like_item_type_id", itemKey.TypeId);

                // commit the transaction
                core.Db.Query(uQuery);

            }
            else
            {
                switch (like)
                {
                    case LikeType.Like:
                        ii.IncrementLikes();
                        break;
                    case LikeType.Dislike:
                        ii.IncrementDislikes();
                        break;
                }

                InsertQuery iQuery = new InsertQuery("likes");
                iQuery.AddField("like_item_id", itemKey.Id);
                iQuery.AddField("like_item_type_id", itemKey.TypeId);
                iQuery.AddField("user_id", core.LoggedInMemberId);
                iQuery.AddField("like_time_ut", UnixTime.UnixTimeStamp());
                iQuery.AddField("like_liking", (sbyte)like);
//.........这里部分代码省略.........
开发者ID:smithydll,项目名称:boxsocial,代码行数:101,代码来源:Like.cs


注:本文中的ItemInfo.IncrementDislikes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。