Esempio n. 1
0
 // Token: 0x0600077C RID: 1916 RVA: 0x0003341C File Offset: 0x0003161C
 public static void StoreBlogItems(List <BlogItemDAL> blogItems, int targetBlogsCount)
 {
     if (targetBlogsCount < 0)
     {
         throw new ArgumentOutOfRangeException("targetBlogsCount", targetBlogsCount, "Should be >= 0");
     }
     using (SqlConnection sqlConnection = DatabaseFunctions.CreateConnection())
     {
         List <BlogItemDAL> list  = new List <BlogItemDAL>();
         List <BlogItemDAL> list2 = new List <BlogItemDAL>();
         foreach (BlogItemDAL blogItemDAL in blogItems)
         {
             BlogItemDAL blogItemForPost = BlogItemDAL.GetBlogItemForPost(blogItemDAL.PostGuid, blogItemDAL.PostId, sqlConnection);
             if (blogItemForPost != null)
             {
                 blogItemForPost.Title           = blogItemDAL.Title;
                 blogItemForPost.Description     = blogItemDAL.Description;
                 blogItemForPost.Url             = blogItemDAL.Url;
                 blogItemForPost.Owner           = blogItemDAL.Owner;
                 blogItemForPost.PublicationDate = blogItemDAL.PublicationDate;
                 blogItemForPost.CommentsUrl     = blogItemDAL.CommentsUrl;
                 blogItemForPost.CommentsCount   = blogItemDAL.CommentsCount;
                 list.Add(blogItemForPost);
             }
             else
             {
                 list2.Add(blogItemDAL);
             }
         }
         using (SqlTransaction sqlTransaction = sqlConnection.BeginTransaction(IsolationLevel.Serializable))
         {
             try
             {
                 foreach (BlogItemDAL blogItemDAL2 in list)
                 {
                     blogItemDAL2.Update(sqlConnection, sqlTransaction);
                 }
                 foreach (BlogItemDAL blogItemDAL3 in list2)
                 {
                     BlogItemDAL.Insert(sqlConnection, sqlTransaction, Guid.NewGuid(), blogItemDAL3.Title, blogItemDAL3.Description, false, blogItemDAL3.Url, null, null, blogItemDAL3.PostGuid, blogItemDAL3.PostId, blogItemDAL3.Owner, blogItemDAL3.PublicationDate, blogItemDAL3.CommentsUrl, blogItemDAL3.CommentsCount);
                 }
                 using (SqlCommand sqlCommand = new SqlCommand(string.Format("DELETE FROM NotificationBlogs WHERE BlogID NOT IN (SELECT TOP {0} BlogID FROM NotificationBlogs ORDER BY PublicationDate DESC)", targetBlogsCount)))
                 {
                     SqlHelper.ExecuteNonQuery(sqlCommand, sqlConnection, sqlTransaction);
                 }
                 using (SqlCommand sqlCommand2 = new SqlCommand("DELETE FROM NotificationItems WHERE NotificationTypeID=@TypeID AND NotificationID NOT IN (SELECT BlogID FROM NotificationBlogs)"))
                 {
                     sqlCommand2.Parameters.AddWithValue("@TypeID", BlogItem.BlogTypeGuid);
                     SqlHelper.ExecuteNonQuery(sqlCommand2, sqlConnection, sqlTransaction);
                 }
                 sqlTransaction.Commit();
             }
             catch
             {
                 sqlTransaction.Rollback();
                 throw;
             }
         }
     }
 }
Esempio n. 2
0
        // Token: 0x0600077D RID: 1917 RVA: 0x00033738 File Offset: 0x00031938
        private static BlogItemDAL Insert(SqlConnection con, SqlTransaction tr, Guid blogId, string title, string description, bool ignored, string url, DateTime?acknowledgedAt, string acknowledgedBy, Guid postGuid, long postId, string owner, DateTime publicationDate, string commentsUrl, int commentsCount)
        {
            if (tr == null)
            {
                throw new ArgumentNullException("tr");
            }
            if (postGuid == Guid.Empty)
            {
                throw new ArgumentException("postGuid GUID can't be Guid.Empty", "postGuid");
            }
            if (publicationDate == DateTime.MinValue)
            {
                throw new ArgumentNullException("publicationDate");
            }
            BlogItemDAL blogItemDAL = NotificationItemDAL.Insert <BlogItemDAL>(con, tr, blogId, title, description, ignored, url, acknowledgedAt, acknowledgedBy);

            if (blogItemDAL == null)
            {
                return(null);
            }
            BlogItemDAL result;

            using (SqlCommand sqlCommand = new SqlCommand("INSERT INTO NotificationBlogs (BlogID, PostGUID, PostID, Owner, PublicationDate, CommentsUrl, CommentsCount)\r\n                                              VALUES (@BlogID, @PostGUID, @PostID, @Owner, @PublicationDate, @CommentsUrl, @CommentsCount)"))
            {
                sqlCommand.Parameters.AddWithValue("@BlogID", blogId);
                sqlCommand.Parameters.AddWithValue("@PostGUID", postGuid);
                sqlCommand.Parameters.AddWithValue("@PostID", postId);
                sqlCommand.Parameters.AddWithValue("@Owner", string.IsNullOrEmpty(owner) ? DBNull.Value : owner);
                sqlCommand.Parameters.AddWithValue("@PublicationDate", publicationDate);
                sqlCommand.Parameters.AddWithValue("@CommentsUrl", string.IsNullOrEmpty(commentsUrl) ? DBNull.Value : commentsUrl);
                sqlCommand.Parameters.AddWithValue("@CommentsCount", (commentsCount < 0) ? DBNull.Value : commentsCount);
                if (SqlHelper.ExecuteNonQuery(sqlCommand, con, tr) == 0)
                {
                    result = null;
                }
                else
                {
                    blogItemDAL.PostGuid        = postGuid;
                    blogItemDAL.PostId          = postId;
                    blogItemDAL.Owner           = owner;
                    blogItemDAL.PublicationDate = publicationDate;
                    blogItemDAL.CommentsUrl     = commentsUrl;
                    blogItemDAL.CommentsCount   = commentsCount;
                    result = blogItemDAL;
                }
            }
            return(result);
        }
Esempio n. 3
0
        // Token: 0x0600077E RID: 1918 RVA: 0x000338E0 File Offset: 0x00031AE0
        public static BlogItemDAL Insert(Guid blogId, string title, string description, bool ignored, string url, DateTime?acknowledgedAt, string acknowledgedBy, Guid postGuid, long postId, string owner, DateTime publicationDate, string commentsUrl, int commentsCount)
        {
            BlogItemDAL result;

            using (SqlConnection sqlConnection = DatabaseFunctions.CreateConnection())
            {
                using (SqlTransaction sqlTransaction = sqlConnection.BeginTransaction())
                {
                    try
                    {
                        BlogItemDAL blogItemDAL = BlogItemDAL.Insert(sqlConnection, sqlTransaction, blogId, title, description, ignored, url, acknowledgedAt, acknowledgedBy, postGuid, postId, owner, publicationDate, commentsUrl, commentsCount);
                        sqlTransaction.Commit();
                        result = blogItemDAL;
                    }
                    catch (Exception ex)
                    {
                        sqlTransaction.Rollback();
                        BlogItemDAL.log.Error(string.Format("Can't INSERT blog item: ", Array.Empty <object>()) + ex.ToString());
                        throw;
                    }
                }
            }
            return(result);
        }
Esempio n. 4
0
        // Token: 0x0600077B RID: 1915 RVA: 0x00033380 File Offset: 0x00031580
        private static BlogItemDAL GetBlogItemForPost(Guid postGuid, long postId, SqlConnection connection)
        {
            BlogItemDAL result;

            using (SqlCommand textCommand = SqlHelper.GetTextCommand("SELECT * FROM NotificationBlogs LEFT JOIN NotificationItems ON NotificationBlogs.BlogID=NotificationItems.NotificationID \r\n                                 WHERE PostGUID=@PostGUID AND PostID=@PostID"))
            {
                textCommand.Parameters.AddWithValue("@PostGUID", postGuid);
                textCommand.Parameters.AddWithValue("@PostID", postId);
                using (IDataReader dataReader = SqlHelper.ExecuteReader(textCommand, connection))
                {
                    if (dataReader.Read())
                    {
                        BlogItemDAL blogItemDAL = new BlogItemDAL();
                        blogItemDAL.LoadFromReader(dataReader);
                        result = blogItemDAL;
                    }
                    else
                    {
                        result = null;
                    }
                }
            }
            return(result);
        }
Esempio n. 5
0
 // Token: 0x0600077A RID: 1914 RVA: 0x00033376 File Offset: 0x00031576
 public static BlogItemDAL GetBlogItemForPost(Guid postGuid, long postId)
 {
     return(BlogItemDAL.GetBlogItemForPost(postGuid, postId, null));
 }