static void Main() { var context = new NewsEntities(); var firstNews = new News() { Content = "Turkey's air force is attacking Islamic State (IS) positions in Syria and Kurdish PKK militants in northern Iraq to defend the country's security, Turkish PM Ahmet Davutoglu says." }; context.News.Add(firstNews); context.SaveChanges(); var secNews = new News() { Content = "The Pentagon has urged US citizens not to carry out armed patrols outside military recruitment centres." }; context.News.Add(secNews); context.SaveChanges(); var thirdNews = new News() { Content = "A man has been killed by a shark off the Tasmanian coast, the first such death in the region for 17 years." }; context.News.Add(thirdNews); context.SaveChanges(); }
static void Main() { Console.WriteLine("Application started"); var context = new NewsEntities(); var firstNews = context.News.First(); Console.WriteLine("Text from DB: {0}", firstNews.Content); Console.Write("Enter the corrected text:"); string input = Console.ReadLine(); firstNews.Content = input; var context2 = new NewsEntities(); var firstNewssecUser = context2.News.First(); Console.WriteLine("Text from DB: {0}", firstNewssecUser.Content); Console.Write("Enter the corrected text:"); string input2 = Console.ReadLine(); context.SaveChanges(); Console.WriteLine("Changes successfully saved in the DB."); try { firstNewssecUser.Content = input2; context2.SaveChanges(); Console.WriteLine("Changes successfully saved in the DB."); } catch (Exception) { var context3 = new NewsEntities(); var firstNewsthirdUser = context3.News.First(); Console.WriteLine("Conflict! Text from DB: {0}.", firstNewsthirdUser.Content); Console.Write("Enter the corrected text:"); string newInput = Console.ReadLine(); firstNewsthirdUser.Content = newInput; context3.SaveChanges(); Console.WriteLine("Changes successfully saved in the DB."); } }