コード例 #1
0
ファイル: ParalelUpdates.cs プロジェクト: SGStoyanov/SoftUni
        public static void MakeParalelUpdate()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<NewsDbContext, Configuration>());
            var context = new NewsDbContext();
            var firstNews = context.News.FirstOrDefault();

            Console.WriteLine("First news current content: " + firstNews.Content);
            Console.WriteLine("Enter the new text: ");

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    var newText = Console.ReadLine();
                    firstNews.Content = newText;
                    context.SaveChanges();
                    transaction.Commit();

                    Console.WriteLine("Update successful");
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    Console.WriteLine("Conflict occured! \nThe transcation has been rolled back!");
                    Console.WriteLine(ex.Message);
                    MakeParalelUpdate();
                }
            }
        }
コード例 #2
0
 public static void AssemblyInit(TestContext context)
 {
     using (var newsDbContext = new NewsDbContext())
     {
         newsDbContext.Database.CreateIfNotExists();
     }
 }
コード例 #3
0
 private static void UpdateNewsContent(News firstNews, NewsDbContext context)
 {
     Console.WriteLine("Text from DB: " + firstNews.Content);
     Console.Write("Enter the corrected text: ");
     string newContent = Console.ReadLine();
     firstNews.Content = newContent;
 }
コード例 #4
0
        public static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<NewsDbContext, Configuration>());
            var database = new NewsDbContext();

            // Problem 2. Concurrent Updates (Console App)
            ParalelUpdates.MakeParalelUpdate();
        }
コード例 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if(this.ReaderId == string.Empty)
            {
                this.content.Visible = false;
                this.LikesLiteral.Text = db.Articles.Find(int.Parse(this.ArticleId)).Likes.Sum(l => l.Value).ToString();
            }

            this.db = new NewsDbContext();
        }
コード例 #6
0
        public static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<NewsDbContext, Configuration>());
            Console.WriteLine("Application started");

            var contextFirstUser = new NewsDbContext();
            var firstNews = contextFirstUser.News.FirstOrDefault();
            bool running = true;

            do
            {
                if (firstNews != null)
                {
                    UpdateNewsContent(firstNews, contextFirstUser);

                    var contextSecondUser = new NewsDbContext();
                    firstNews = contextSecondUser.News.FirstOrDefault();
                    UpdateNewsContent(firstNews, contextSecondUser);
                    contextFirstUser.SaveChanges();
                    try
                    {
                        contextSecondUser.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        Console.WriteLine("Conflict! Text from DB: {0}. Enter the corrected text:", firstNews.Content);
                        Console.WriteLine(ex.Message);
                        UpdateNewsContent(firstNews, contextSecondUser);
                    }
                }
                else
                {
                    Console.WriteLine("Sorry, no news yet!");
                }
            } while (!running);
        }
コード例 #7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     this.db = new NewsDbContext();
 }
コード例 #8
0
 public IEnumerable<Category> Categories_GetData()
 {
     var localDb = new NewsDbContext();
     return localDb.Categories.OrderBy(b => b.Name).ToList();
 }
コード例 #9
0
 public ArticleDetails()
 {
     this.dbContext = new NewsDbContext();
 }
コード例 #10
0
ファイル: News.aspx.cs プロジェクト: VDGone/TelerikAcademy-2
 public News()
 {
     this.db = new NewsDbContext();
 }
コード例 #11
0
 public BasePage()
 {
     this.dbContext = new NewsDbContext();
 }
コード例 #12
0
 public Articles()
 {
     this.db = new NewsDbContext();
 }
コード例 #13
0
 public Home()
 {
     this.dbContext = new NewsDbContext();
 }
コード例 #14
0
 public EditArticles()
 {
     this.dbContext = new NewsDbContext();
 }
コード例 #15
0
 public EditCategories()
 {
     this.dbContext = new NewsDbContext();
 }
コード例 #16
0
 public NewsRepository(NewsDbContext context)
 {
     _context = context;
 }
コード例 #17
0
 public Categories()
 {
     this.db = new NewsDbContext();
 }