private static async Task UpdateAsync(BooksContext context, Book book, string user)
        {
            try
            {
                WriteLine($"{user}: updating id {book.BookId}, timestamp {book.TimeStamp.StringOutput()}");
                ShowChanges(book.BookId, context.Entry(book));

                int records = await context.SaveChangesAsync();

                WriteLine($"{user}: updated {book.TimeStamp.StringOutput()}");
                WriteLine($"{user}: {records} record(s) updated while updating {book.Title}");
            }
            catch (DbUpdateConcurrencyException ex)
            {
                WriteLine($"{user} update failed with {book.Title}");
                WriteLine($"{user} error: {ex.Message}");
                foreach (var entry in ex.Entries)
                {
                    Book b = entry.Entity as Book;

                    WriteLine($"{b.Title} {b.TimeStamp.StringOutput()}");
                    ShowChanges(book.BookId, context.Entry(book));
                }
            }
        }
Пример #2
0
        private static async Task UpdateAsync(BooksContext context, Book book, string user)
        {
            try
            {
                Console.WriteLine($"{user}: updating id {book.BookId}, " + $"timestamp: {book.TimeStamp}");
                ShowChanges(book.BookId, context.Entry(book));
                int records = await context.SaveChangesAsync();

                Console.WriteLine($"{user}: updated {book.TimeStamp}");
                Console.WriteLine($"{user}: {records} record(s) updated while updating " + $"{book.Title}");
            }
            catch (DbUpdateConcurrencyException ex)
            {
                Console.WriteLine($"{user}: update failed with {book.Title}");
                Console.WriteLine($"error: {ex.Message}");
                foreach (var entry in ex.Entries)
                {
                    Book b = entry.Entity as Book;
                    Console.WriteLine($"{b.Title} {b.TimeStamp}");
                    ShowChanges(book.BookId, context.Entry(book));
                }
            }



            Console.WriteLine($"successfully written to the database: id {book.BookId} with title {book.Title}");
        }
        private static async Task UpdateAsync(BooksContext context, Book book, string user)
        {
            try
            {
                WriteLine($"{user}: updating id {book.BookId}, timestamp {book.TimeStamp.StringOutput()}");
                ShowChanges(book.BookId, context.Entry(book));

                int records = await context.SaveChangesAsync();
                WriteLine($"{user}: updated {book.TimeStamp.StringOutput()}");
                WriteLine($"{user}: {records} record(s) updated while updating {book.Title}");
            }
            catch (DbUpdateConcurrencyException ex)
            { 
                WriteLine($"{user} update failed with {book.Title}");
                WriteLine($"{user} error: {ex.Message}");
                foreach (var entry in ex.Entries)
                {
                    Book b = entry.Entity as Book;

                    WriteLine($"{b.Title} {b.TimeStamp.StringOutput()}");
                    ShowChanges(book.BookId, context.Entry(book));
                }
            }            
        }