예제 #1
0
파일: Program.cs 프로젝트: uFreezy/SoftUni
        static void Main()
        {
            var context = new NewsDBContext();

            var data = context.News.Find(1);

            //WARNING: Concurency handling should be tested by running two instances of the app.

            while (true)
            {
                try
                {
                    data.Content = Console.ReadLine();
                    context.SaveChanges();
                    Console.WriteLine("Changes successfully saved in the DB.");
                    break;
                }
                catch (DbUpdateConcurrencyException exc)
                {
                    exc.Entries.Single().Reload();
                    Console.WriteLine("Conflict! Text from DB:" + context.News.Find(1).Content
                                      + ". Enter the corrected text:");
                }
            }
        }
예제 #2
0
        static void Main()
        {
            var context    = new NewsDBContext();
            var newContext = new NewsDBContext();
            var firstNews  = context.News.FirstOrDefault();

            Console.WriteLine("Application started");
            Console.Write("Text from DB: ");
            Console.WriteLine(firstNews.NewsContent);
            Console.WriteLine("Enter the corrected text: ");


            firstNews.NewsContent = Console.ReadLine();

            try
            {
                context.SaveChanges();

                Console.WriteLine("Changes successfully saved in the DB.");
            }
            catch (DbUpdateConcurrencyException ex)
            {
                var textFromDB = newContext.News.FirstOrDefault();
                Console.WriteLine("Conflict! Text from DB: {0}. Enter the corrected text:", textFromDB.NewsContent);
                Main();
            }
        }
예제 #3
0
        public static void Main()
        {
            using (var db = new NewsDBContext())
            {
                db.News.Add(new News { Content = "Some very long and interesting content!" });

                db.SaveChanges();
            }
        }
예제 #4
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            news     = new News();
            editNews = new EditNews();
            success  = new Success();
            error    = new Error();

            Application.Run(news);

            using (var context = new NewsDBContext())
            {
                var loadedEntity = context.News.First();

                CatchConcurrencyConflict(context, loadedEntity);
            }
        }
예제 #5
0
 public NewsletterRepository(NewsDBContext context)
 {
     _context = context;
 }
예제 #6
0
 public CommentRepository(NewsDBContext context)
 {
     _context = context;
 }
예제 #7
0
 public UnitOfWork(NewsDBContext context, IMapper mapper, IConfiguration configuration)
 {
     _Context       = context;
     _mapper        = mapper;
     _configuration = configuration;
 }
예제 #8
0
 public RankController(NewsDBContext context)
 {
     _context = context;
 }
예제 #9
0
 public CategoryRepository(NewsDBContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
     _context.CheckArgumentIsNull(nameof(_context));
 }
예제 #10
0
 public NewsService(NewsDBContext dbContext)
 {
     this._dbContext = dbContext;
 }