Beispiel #1
0
        bool ICommon <CommentInfo> .Delete(string id)
        {
            Contract.Requires <ArgumentNullException>(!string.IsNullOrEmpty(id), "参数id:不能为空");
            bool          result          = false;
            List <string> sqls            = new List <string>();
            string        message         = string.Empty;
            string        message1        = string.Empty;
            string        message2        = string.Empty;
            string        message3        = string.Empty;
            IPublishInfo  IpublishInfo    = new PublishInfoDao();
            CommentInfo   tempCommentInfo = ((ICommon <CommentInfo>) this).GetInformation(id);

            if (tempCommentInfo == null)
            {
                throw new NoNullAllowedException("评论信息不能为空,请核查!");
            }
            PublishInfo tempPublishInfo = ((ICommon <PublishInfo>)IpublishInfo).GetInformation(tempCommentInfo.PublishID);

            if (tempPublishInfo == null)
            {
                throw new NoNullAllowedException("朋友圈发布信息不能为空,请核查!");
            }
            sqls.Add(DBService.DeleteSql(new CommentInfo()
            {
                ID = id
            }, out message1));
            sqls.Add(DBService.UpdateSql(new PublishInfo()
            {
                ID         = tempCommentInfo.PublishID,
                CommentNum = tempPublishInfo.CommentNum - 1
            }, out message2));

            //删除级联noticeInfo
            MiicConditionCollections noticeCondition    = new MiicConditionCollections(MiicDBLogicSetting.No);
            MiicCondition            commentIDCondition = new MiicCondition(Config.Attribute.GetSqlColumnNameByPropertyName <NoticeInfo, string>(o => o.CommentID),
                                                                            id,
                                                                            DbType.String,
                                                                            MiicDBOperatorSetting.Equal);

            noticeCondition.Add(new MiicConditionLeaf(MiicDBLogicSetting.No, commentIDCondition));
            MiicCondition readStatusCondition = new MiicCondition(Config.Attribute.GetSqlColumnNameByPropertyName <NoticeInfo, string>(o => o.ReadStatus),
                                                                  ((int)Miic.Base.Setting.MiicReadStatusSetting.UnRead).ToString(),
                                                                  DbType.String,
                                                                  MiicDBOperatorSetting.Equal);

            noticeCondition.Add(new MiicConditionLeaf(readStatusCondition));
            sqls.Add(DBService.DeleteConditionsSql <NoticeInfo>(noticeCondition, out message));

            MessageInfo messageInfo = new MessageInfo()
            {
                ID            = Guid.NewGuid().ToString(),
                PublisherID   = tempCommentInfo.FromCommenterID,
                PublisherName = tempCommentInfo.FromCommenterName,
                PublishTime   = tempCommentInfo.CommentTime,
                PublishID     = tempCommentInfo.PublishID,
                NoticerID     = tempPublishInfo.CreaterID,
                NoticerName   = tempPublishInfo.CreaterName,
                ReadStatus    = ((int)MiicReadStatusSetting.UnRead).ToString(),
                Source        = ((int)BusinessTypeSetting.Moments).ToString(),
                MessageType   = ((int)BehaviorTypeSetting.CancelComment).ToString()
            };

            if (tempCommentInfo.FromCommenterID != tempPublishInfo.CreaterID)
            {
                sqls.Add(DBService.InsertSql(messageInfo, out message3));
            }

            //积分
            sqls.Add(DBService.InsertSql <UserScopeHistory>(new UserScopeHistory()
            {
                ID         = Guid.NewGuid().ToString(),
                BusinessID = tempCommentInfo.ID,
                CreateTime = DateTime.Now,
                GetWay     = ((int)GetWayTypeSetting.Comment).ToString(),
                Score      = -1 * ScoreConfig.Score.CommentScore,
                ServiceID  = ScoreConfig.ServiceID,
                UserID     = tempCommentInfo.FromCommenterID,
                UserName   = tempCommentInfo.FromCommenterName
            }, out message));

            try
            {
                result = dbService.excuteSqls(sqls, out message);
            }
            catch (Exception ex)
            {
                Config.IlogicLogService.Write(new LogicLog()
                {
                    AppName       = Config.AppName,
                    ClassName     = ClassName,
                    NamespaceName = NamespaceName,
                    MethodName    = MethodBase.GetCurrentMethod().Name,
                    Message       = ex.Message,
                    Oper          = Config.Oper
                });
            }
            if (result == true)
            {
                DeleteCache(o => o.ID == id);
                if (tempCommentInfo.FromCommenterID != tempPublishInfo.CreaterID)
                {
                    MessageInfoDao.InsertCache(messageInfo);
                }
                lock (syncRoot)
                {
                    if (PublishInfoDao.items.Find(o => o.ID == tempCommentInfo.PublishID) != null)
                    {
                        PublishInfoDao.items.Find(o => o.ID == tempCommentInfo.PublishID).CommentNum = tempPublishInfo.CommentNum - 1;
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
        bool ICommon <CollectInfo> .Insert(CollectInfo collectInfo)
        {
            Contract.Requires <ArgumentNullException>(collectInfo != null, "参数collectInfo:不能为空!");
            Contract.Requires <ArgumentNullException>(!string.IsNullOrEmpty(collectInfo.ID), "参数collectInfo.ID:不能为空!");
            bool          result       = false;
            List <string> sqls         = new List <string>();
            string        message      = string.Empty;
            string        message1     = string.Empty;
            string        message2     = string.Empty;
            string        message3     = string.Empty;
            IPublishInfo  IpublishInfo = new PublishInfoDao();
            PublishInfo   temp         = ((ICommon <PublishInfo>)IpublishInfo).GetInformation(collectInfo.PublishID);

            if (temp == null)
            {
                throw new NoNullAllowedException("temp发布信息不能为空,请核查!");
            }
            sqls.Add(DBService.InsertSql(collectInfo, out message1));
            sqls.Add(DBService.UpdateSql(new PublishInfo()
            {
                ID         = collectInfo.PublishID,
                CollectNum = temp.CollectNum + 1
            }, out message2));
            MessageInfo messageInfo = new MessageInfo()
            {
                ID            = Guid.NewGuid().ToString(),
                PublisherID   = collectInfo.CollectorID,
                PublisherName = collectInfo.CollectorName,
                PublishTime   = collectInfo.CollectTime,
                PublishID     = collectInfo.PublishID,
                NoticerID     = temp.CreaterID,
                NoticerName   = temp.CreaterName,
                ReadStatus    = ((int)MiicReadStatusSetting.UnRead).ToString(),
                Source        = ((int)BusinessTypeSetting.Moments).ToString(),
                MessageType   = ((int)BehaviorTypeSetting.Collect).ToString()
            };

            if (collectInfo.CollectorID != temp.CreaterID)
            {
                sqls.Add(DBService.InsertSql(messageInfo, out message3));
            }

            //积分
            sqls.Add(DBService.InsertSql <UserScopeHistory>(new UserScopeHistory()
            {
                ID         = Guid.NewGuid().ToString(),
                BusinessID = collectInfo.ID,
                CreateTime = DateTime.Now,
                GetWay     = ((int)GetWayTypeSetting.Behavior).ToString(),
                Score      = ScoreConfig.Score.BehaviorScore,
                ServiceID  = ScoreConfig.ServiceID,
                UserID     = collectInfo.CollectorID,
                UserName   = collectInfo.CollectorName
            }, out message));

            try
            {
                result = dbService.excuteSqls(sqls, out message);
            }
            catch (Exception ex)
            {
                Config.IlogicLogService.Write(new LogicLog()
                {
                    AppName       = Config.AppName,
                    ClassName     = ClassName,
                    NamespaceName = NamespaceName,
                    MethodName    = MethodBase.GetCurrentMethod().Name,
                    Message       = ex.Message,
                    Oper          = Config.Oper
                });
            }
            if (result == true)
            {
                InsertCache(collectInfo);
                if (collectInfo.CollectorID != temp.CreaterID)
                {
                    MessageInfoDao.InsertCache(messageInfo);
                }
                lock (syncRoot)
                {
                    if (PublishInfoDao.items.Find(o => o.ID == collectInfo.PublishID) != null)
                    {
                        PublishInfoDao.items.Find(o => o.ID == collectInfo.PublishID).CollectNum = temp.CollectNum + 1;
                    }
                }
            }
            return(result);
        }