public ActionResult Edit(Book book) { BooksRepo.Change(book); BooksRepo.SaveChanges(); var title = ViewData["BookTitle"]; var author = TempData["Author"]; var created = Session["Created"]; return(RedirectToAction("Edit", new { id = book.Id })); }
public void Edit_BookDoesNotExist_ExpectedException() { var fileHandlerMock = new Mock <IJsonWorker>(); fileHandlerMock.Setup(x => x.Load(path)).Returns(new List <Book> { }); var subject = new BookRepository(fileHandlerMock.Object); subject.Change(new Book { Id = 11, Title = "new 11" }); }
public void Edit_BookExists_ShouldBeChanged() { var fileHandlerMock = new Mock <IJsonWorker>(); fileHandlerMock.Setup(x => x.Load(path)).Returns(new List <Book> { }); var subject = new BookRepository(fileHandlerMock.Object); subject.Add(new Book { Id = 11, Title = "11" }); subject.Change(new Book { Id = 11, Title = "new 11" }); var result = subject.Get(11); Assert.IsNotNull(result); Assert.AreEqual("new 11", result.Title); }
static void Main(string[] args) { ShowDialog(); var BookRepo = new BookRepository(); ConsoleKeyInfo key; var ok = false; var book = new Book(); int id; string title; do { key = Console.ReadKey(); try { switch (key.Key) { case ConsoleKey.D0: Console.WriteLine("\nEnter Id..."); ok = int.TryParse(Console.ReadLine(), out id); book = BookRepo.Get(id); ShowBook(book); break; case ConsoleKey.D1: Console.WriteLine("\nEnter Id..."); ok = int.TryParse(Console.ReadLine(), out id); Console.WriteLine("\nEnter Title..."); title = Console.ReadLine(); book = new Book(id, title); BookRepo.Add(book); BookRepo.SaveChanges(); Console.WriteLine("\nBook added:"); ShowBook(book); break; case ConsoleKey.D2: Console.WriteLine("\nEnter Id..."); ok = int.TryParse(Console.ReadLine(), out id); Console.WriteLine("\nEnter Title..."); title = Console.ReadLine(); book = new Book(id, title); BookRepo.Change(book); BookRepo.SaveChanges(); Console.WriteLine("\nBook changed:"); ShowBook(book); break; case ConsoleKey.D3: Console.WriteLine("\nEnter Id..."); ok = int.TryParse(Console.ReadLine(), out id); BookRepo.Delete(id); BookRepo.SaveChanges(); Console.WriteLine("\nBook: {0} deleted", id); break; default: break; } } catch (Exception e) { Console.WriteLine(e.Message); ok = false; ShowDialog(); continue; } } while (key.Key != ConsoleKey.Escape || !ok); }