public static void Save(
            this IRepository <NntpForum> repository,
            [NotNull] int?nntpForumId,
            [NotNull] int nntpServerId,
            [NotNull] string groupName,
            [NotNull] int forumID,
            [NotNull] bool active,
            [NotNull] DateTime?datecutoff)
        {
            if (nntpForumId.HasValue)
            {
                repository.UpdateOnly(
                    () => new NntpForum
                {
                    NntpServerID = nntpServerId,
                    GroupName    = groupName,
                    ForumID      = forumID,
                    Active       = active,
                    DateCutOff   = datecutoff
                },
                    n => n.ID == nntpForumId);
            }
            else
            {
                var entity = new NntpForum
                {
                    NntpServerID  = nntpServerId,
                    GroupName     = groupName,
                    ForumID       = forumID,
                    Active        = active,
                    DateCutOff    = datecutoff,
                    LastUpdate    = DateTime.UtcNow,
                    LastMessageNo = 0,
                };

                repository.Insert(entity);

                repository.FireNew(entity);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The save message.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="nntpForum">
        /// The nntp Forum.
        /// </param>
        /// <param name="topic">
        /// The topic.
        /// </param>
        /// <param name="body">
        /// The body.
        /// </param>
        /// <param name="userId">
        /// The user id.
        /// </param>
        /// <param name="userName">
        /// The user name.
        /// </param>
        /// <param name="ip">
        /// The IP Address.
        /// </param>
        /// <param name="posted">
        /// The posted.
        /// </param>
        /// <param name="externalMessageId">
        /// The external message id.
        /// </param>
        /// <param name="referenceMessageId">
        /// The reference message id.
        /// </param>
        public static void SaveMessage(
            this IRepository <NntpTopic> repository,
            [NotNull] NntpForum nntpForum,
            [NotNull] string topic,
            [NotNull] string body,
            [NotNull] int userId,
            [NotNull] string userName,
            [NotNull] string ip,
            [NotNull] DateTime posted,
            [NotNull] string externalMessageId,
            [NotNull] string referenceMessageId)
        {
            CodeContracts.VerifyNotNull(repository);

            int?topicId;
            int?replyTo = null;

            var externalMessage = BoardContext.Current.GetRepository <Message>()
                                  .GetSingle(m => m.ExternalMessageId == referenceMessageId);

            if (externalMessage != null)
            {
                // -- referenced message exists
                topicId = externalMessage.TopicID;
                replyTo = externalMessage.ID;
            }
            else
            {
                // --thread doesn't exists
                var newTopic = new Topic
                {
                    ForumID         = nntpForum.ForumID,
                    UserID          = userId,
                    UserName        = userName,
                    UserDisplayName = userName,
                    Posted          = posted,
                    TopicName       = topic,
                    Views           = 0,
                    Priority        = 0,
                    NumPosts        = 0
                };

                topicId = BoardContext.Current.GetRepository <Topic>().Insert(newTopic);

                repository.Insert(
                    new NntpTopic {
                    NntpForumID = nntpForum.ID, Thread = string.Empty, TopicID = topicId.Value
                });
            }

            BoardContext.Current.GetRepository <Message>().SaveNew(
                nntpForum.ForumID,
                topicId.Value,
                userId,
                body,
                userName,
                ip,
                posted,
                replyTo,
                new MessageFlags(17));
        }