Exemple #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;
             }
         }
     }
 }
Exemple #2
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);
        }