public ActionResult AddBook(AddBookViewModel model) { var name = Request["Name"]; if (ModelState.IsValid) { Book book = new Book() { Name = model.Name, Isbn = model.Isbn, Price = model.Price, CategoryId = model.CategoryId, CreatedDate = DateTime.Now, CreatedBy = HttpContext.User.Identity.Name }; BookStoreService.SaveBook(book); //TempData["message"] = "Hello from Add Book"; return(RedirectToAction("Index")); } var categoryList = BookStoreService.GetCategoryList(); model.CategoryList = new SelectList(categoryList, "Id", "Name", model.CategoryId); //ModelState.AddModelError("", "Some other error such as Book Name already exist"); return(View(model)); }
private async Task LoadAuthors() { var authors = (await BookStoreService.GetAllAsync("authors")); authors = null; if (authors == null) { var accessToken = await LocalStorageService.GetItemAsync <string>("accessToken"); var refreshToken = await LocalStorageService.GetItemAsync <string>("refreshToken"); var refreshRequest = new RefreshRequest { AccessToken = accessToken, RefreshToken = refreshToken }; var user = (await UserService.RefreshAccessTokenAsync(refreshRequest)) as UserWithToken; if (user != null) { await LocalStorageService.SetItemAsync("accessToken", user.AccessToken); authors = (await BookStoreService.GetAllAsync("authors")); } } Authors = authors != null?authors.OrderByDescending(a => a.AuthorId).ToList() : new List <Author>(); StateHasChanged(); }
public async Task <string> GetAuthorName() { var bookService = new BookStoreService(); var author = await bookService.GetAuthorAsync(AuthorId); return(author.Name); }
public async Task <string> GetGenreName() { var bookService = new BookStoreService(); var genre = await bookService.GetGenreAsync(GenreId); return(genre.Name); }
private async Task LoadPublishers() { var publishers = (await BookStoreService.GetAllAsync("publishers")); FilteredPublishers = Publishers = publishers != null?publishers.OrderByDescending(p => p.PubId).ToList() : new List <Publisher>(); StateHasChanged(); }
private async Task LoadAuthors() { var authors = (await BookStoreService.GetAllAsync("authors")); FilteredAuthors = Authors = authors != null?authors.OrderByDescending(a => a.AuthorId).ToList() : new List <Author>(); StateHasChanged(); }
public BooksPage() { var bookStore = new BookStoreService(); var pageService = new PageService(); ViewModel = new BooksPageViewModel(bookStore, pageService); InitializeComponent(); ViewModel.LoadBooksCommand.Execute(null); }
public void get_books_returns_all_available_books() { //given moqBookService.Setup(m => m.GetAllBooks()).Returns(TestData.Books); var sut = new BookStoreService(moqStudentService.Object, moqBookService.Object, moqBookAllocationService.Object); //when var result = sut.GetAllBooks(); //then Assert.IsInstanceOfType(result, typeof(IEnumerable <Book>)); Assert.AreEqual(TestData.Books.Count, result.Count()); moqBookService.Verify(v => v.GetAllBooks(), Times.Once); }
public void get_overdue_books_returns_all_books_which_are_overdue() { //given var overDueBooksId = TestData.IssuedBooks.Where(i => DateTime.Now.Subtract(i.ReturnDate).Days > 0).Select(s => s.BookId).ToList(); var overDueBooks = TestData.Books.Where(b => overDueBooksId.Contains(b.BookId)); moqBookService.Setup(m => m.GetOverdueBooks()).Returns(overDueBooks); var sut = new BookStoreService(moqStudentService.Object, moqBookService.Object, moqBookAllocationService.Object); //when var result = sut.GetOverdueBooks(); //then Assert.IsInstanceOfType(result, typeof(IEnumerable <Book>)); moqBookService.Verify(v => v.GetOverdueBooks(), Times.Once); }
public void GetAuthorByNameTest_AuthorFirstInQuery() { var data = GetFakeAuthor(50); var expected = data .Where(a => a.Name.Contains("a")) .ToList(); var context = CreateDbContext(data); var service = new BookStoreService(context.Object); // act var actual = service.GetAuthorService("a"); // assert Assert.Equal(expected.First(), actual.First()); }
//If only route prefix is used= /BookStore/AddBook // GET: Admin/Admin //[Route] //[OverrideAuthorization] //[Authorize(Users = "*****@*****.**")] // [Route("AddNewBook")] public ActionResult AddBook() { //ViewBag.Title = "Add Book"; //ViewData["Message"] = "You can add book from here"; //ViewData.Add("key", 5); //ViewData.Add(new KeyValuePair<string, object>("newKey",6)); var categoryList = BookStoreService.GetCategoryList(); AddBookViewModel viewModel = new AddBookViewModel() { CategoryList = new SelectList(categoryList, "Id", "Name", 0) }; return(View(viewModel)); //return View("~/Areas/Admin/Views/Admin/AddBook.cshtml",viewModel); }
public void PostAuthorTest_InsertNewAuthor() { var data = GetFakeAuthor(10); var expected = "New Actor"; dynamic jsonObject = new JObject(); jsonObject.name = expected; var context = CreateDbContext(data); var service = new BookStoreService(context.Object); // act service.PostAuthorService(jsonObject); var actual = service.GetAuthorService(expected).Count(); // assert Assert.Equal(1, actual); }
public void extend_date_extends_book_return_date() { //given int randomBookId = rnd.Next(1, TestData.IssuedBooks.Count); var issuedBook = TestData.IssuedBooks.Where(s => s.BookId == randomBookId); moqBookService.Setup(m => m.GetIssuedBooks()).Returns(issuedBook); moqBookAllocationService.Setup(m => m.ExtendReturndate(It.IsAny <IssuedBook>(), It.IsAny <int>())).Returns(true); var sut = new BookStoreService(moqStudentService.Object, moqBookService.Object, moqBookAllocationService.Object); //when var result = sut.ExtendReturnDate(issuedBook.First().BookId, rnd.Next(1, 10)); //then Assert.IsInstanceOfType(result, typeof(bool)); Assert.IsTrue(result); moqBookService.Verify(v => v.GetIssuedBooks(), Times.Once); moqBookAllocationService.Verify(v => v.ExtendReturndate(It.IsAny <IssuedBook>(), It.IsAny <int>()), Times.Once); }
public async Task SaveAuthorAsync() { Author.City = _selectedCity; Author savedAuthor; if (Author.AuthorId > 0) { savedAuthor = await BookStoreService.UpdateAsync("authors", Author.AuthorId, Author); } else { savedAuthor = await BookStoreService.SaveAsync("authors", Author); } Result = savedAuthor != null ? true : false; IsVisible = true; RecordName = Author.FirstName + " " + Author.LastName; await LoadAuthors(); Author = new Author(); await JSRuntime.InvokeVoidAsync("setFocus", firstNameRef); }
public void issue_book_does_not_issue_book_to_student() { //given int randomStudentId = rnd.Next(1, TestData.Students.Count); var student = TestData.Students.Where(s => s.StudentId == randomStudentId).First(); int randomBookId = rnd.Next(1, TestData.IssuedBooks.Count); var book = TestData.Books.Where(s => s.BookId == randomBookId).First(); moqStudentService.Setup(m => m.GetStudent(It.IsAny <int>())).Returns(student); moqBookService.Setup(m => m.GetBook(It.IsAny <int>())).Returns(book); var sut = new BookStoreService(moqStudentService.Object, moqBookService.Object, moqBookAllocationService.Object); //when var result = sut.IssueBook(student.StudentId, book.BookId); //then Assert.IsInstanceOfType(result, typeof(bool)); Assert.IsFalse(result); moqStudentService.Verify(v => v.GetStudent(It.IsAny <int>()), Times.Once); moqBookService.Verify(v => v.GetBook(It.IsAny <int>()), Times.Once); }
public void TestItAll() { IBookstoreService bookstore = new BookStoreService(); IList <Book> books = bookstore.GetBooks(); Assert.AreEqual(3, books.Count); Book book = bookstore.GetBook("1"); Assert.AreEqual("C# 5.0", book.Title); Assert.IsNull(bookstore.GetBook("100")); Assert.AreEqual("C# 5.0", bookstore.GetBookTitle("1")); Assert.IsNull(bookstore.GetBookTitle("100")); Book b1 = new Book { Title = "Essential C# 5.0", Publisher = "Addison Wesley" }; Book b1Copy = bookstore.AddBook(b1); Assert.AreEqual(4, b1Copy.Id); Assert.AreEqual("Essential C# 5.0", b1Copy.Title); b1Copy.Title = "Strange title"; Assert.AreEqual(4, bookstore.GetBooks().Count); Book updatedBook = bookstore.UpdateBook(b1Copy.Id.ToString(), b1Copy); Assert.AreEqual("Strange title", updatedBook.Title); Book bCopy2 = bookstore.DeleteBook("2"); Assert.AreEqual(2, bCopy2.Id); Assert.AreEqual("Beginning Android 4 Application Development", bCopy2.Title); Assert.AreEqual(3, bookstore.GetBooks().Count); Assert.IsNull(bookstore.DeleteBook("100")); }
protected async Task SavePublisherAsync() { Publisher.City = _selectedCity; Publisher savedPublisher; if (Publisher.PubId > 0) { savedPublisher = await BookStoreService.UpdateAsync("publishers", Publisher.PubId, Publisher); } else { savedPublisher = await BookStoreService.SaveAsync("publishers", Publisher); } Result = savedPublisher == null ? false : true; RecordName = Publisher.PublisherName; IsVisible = true; await LoadPublishers(); var name = Publisher.PublisherName; Publisher = new Publisher(); await JSRuntime.InvokeVoidAsync("setFocus", publisherNameRef); }
public async Task DeleteAuthor(int id) { await BookStoreService.DeleteAsync("authors", id); await LoadAuthors(); }
public Service(BookStoreHttpContext bookStoreHttp) { BookStoreService = new BookStoreService(bookStoreHttp); }
protected override async Task OnInitializedAsync() { Author = await BookStoreService.GetByIdAsync("authors", int.Parse(Id)); }
public async Task DeletePublisher(int id) { await BookStoreService.DeleteAsync("publishers", id); await LoadPublishers(); }