public void DeleteBook(long id) { BookRepository bRepo = new BookRepository(_dal); Book book = bRepo.Get(id); if (book == null) throw new HttpException(404, "Ressource not found"); try { _dal.BeginTransaction(); long ret = bRepo.Delete(id); if (ret == 0) throw new Exception("No book was deleted."); _dal.CommitTransaction(); } catch (Exception ex) { _dal.RollbackTransaction(); log.Error(ex); throw; } }
public BookModel GetBook(long id) { BookRepository bRepo = new BookRepository(_dal); StoryRepository sRepo = new StoryRepository(_dal); Book book = bRepo.Get(id); if (book == null) throw new HttpException(404, "Ressource not found"); Story[] stories = sRepo.List().Where(s => s.bookid == id).ToArray(); List<string> storyNames = new List<string>(); foreach (Story story in stories) { storyNames.Add(story.name); } BookModel bookModel = new BookModel() { Id = book.id, Name = book.name, Number = book.number, CategoryId = book.catid, Image = book.image, Added = book.added, Stories = storyNames.ToArray() }; return bookModel; }
public ActionResult Index(string search) { var isbnFiltered = ISBNFilter.Filter(search); var books = new BookRepository().SearchFor(book => book.ISBN.Contains(isbnFiltered) || book.Title.Contains(search)).ToList(); var model = Mapper.Map<IEnumerable<Book>, BooksListModel>(books); return View(model); }
public void DeleteCategory(long id) { CategoryRepository cRepo = new CategoryRepository(_dal); BookRepository bRepo = new BookRepository(_dal); Category category = cRepo.Get(id); if(category == null) throw new HttpException(404, "Ressource not found."); try { _dal.BeginTransaction(); long ret = cRepo.Delete(id); if(ret == 0) throw new Exception("No category was deleted."); _dal.CommitTransaction(); } catch(Exception ex) { _dal.RollbackTransaction(); log.Error(ex); throw; } }
public ActionResult Index(BooksListSuccessMessage message = BooksListSuccessMessage.None) { var books = new BookRepository().GetAll(); var model = Mapper.Map<IEnumerable<Book>, BooksListModel>(books); if (message != BooksListSuccessMessage.None) model.SuccessMessage = message.GetDescriptionAttributeValue(); return View(model); }
/// <summary> /// Constructor for servicefactory /// </summary> public ServiceFactory() { bookCopyRepo = repoFactory.GetBookCopyrepository(); bookRepo = repoFactory.GetBookRepository(); authorRepo = repoFactory.GetAuthorRepository(); loanRepo = repoFactory.GetLoanRepository(); memberRepo = repoFactory.GetMemberRepository(); }
public UnitOfWork(LuaContext context) { _context = context; Authors = new AuthorRepository(_context); Books = new BookRepository(_context); Customers = new CustomerRepository(_context); Rentals = new RentalRepository(_context); Stocks = new StockRepository(_context); }
public Search[] AjaxSearch(string query) { BookRepository bRepo = new BookRepository(_dal); string q = query.Filter(@"%\^#").Escape().Trim(); Search[] terms = bRepo.LiveSearch(q); return terms; }
public OrderObjectRepository(ReaderRepository readerRepository, BookRepository bookRepository, LibraryDepartmentRepository libraryDepartmentRepository, LibrarianRepository librarianRepository) { this.readerRepository = readerRepository; this.bookRepository = bookRepository; this.libraryDepartmentRepository = libraryDepartmentRepository; this.librarianRepository = librarianRepository; orders = new List<Order>(); }
public ActionResult Index(string search) { var isbnFiltered = ISBNFilter.Filter(search); var books = new BookRepository().SearchFor(book => book.ISBN.Contains(isbnFiltered) || book.Title.Contains(search)).ToList(); var model = new BooksListModel { Books = GetBooksListModels(books) }; return View(model); }
public ActionResult Edit(int id) { var book = new BookRepository().GetById(id); if (book == null) return RedirectToAction("Index", "Home"); var model = Mapper.Map<Book, BookModel>(book); model.IsEditMode = true; return View(model); }
public void ShouldInsertBook() { var repo = new BookRepository(Context); var book = new Book { Title = "The Silmarillion", ISBN = "0-04-823139-8", AuthorId = 1 }; repo.Create(book); Context.Commit(); var savedBook = repo.FindAll().SingleOrDefault(x => x.Title == book.Title && x.ISBN == book.ISBN); Assert.That(savedBook != null, "Unable to find the book that was inserted."); }
public void when_there_is_any_row_then_retur_them() { this.iNDbUnitTest = new SqlDbUnitTest(@"server=.\sql2008;database=devdays;integrated security = SSPI"); this.iNDbUnitTest.ReadXmlSchema(@".\ListDataSet.xsd"); this.iNDbUnitTest.ReadXml(@".\ListDataSet.xml"); this.iNDbUnitTest.PerformDbOperation(DbOperationFlag.CleanInsertIdentity); BookRepository sut = new BookRepository(); sut.List().Count.Should().Be(3); }
public Database() { // get config and context from request this.SqlConfig = HttpContext.Current.Items["config"] as SqlConfig; this.SqlContext = HttpContext.Current.Items["context"] as SqlContext; BookEntity = new BookRepository(this.SqlConfig, this.SqlContext); CategoryEntity = new CategoryRepository(this.SqlConfig, this.SqlContext); TagEntity = new TagRepository(this.SqlConfig, this.SqlContext); Tag2BookEntity = new Tag2BookRepository(this.SqlConfig, this.SqlContext); }
public ActionResult Index(BooksListSuccessMessage message = BooksListSuccessMessage.None) { var books = new BookRepository().GetAll(); var model = new BooksListModel { Books = GetBooksListModels(books) }; if (message != BooksListSuccessMessage.None) model.SuccessMessage = message.GetDescriptionAttributeValue(); return View(model); }
public OrderTextRepository(ReaderRepository readerRepository, BookRepository bookRepository, LibraryDepartmentRepository libraryDepartmentRepository, LibrarianRepository librarianRepository) { this.readerRepository = readerRepository; this.bookRepository = bookRepository; this.libraryDepartmentRepository = libraryDepartmentRepository; this.librarianRepository = librarianRepository; if (!Directory.GetParent(FileName).Exists) Directory.GetParent(FileName).Create(); if (!File.Exists(FileName)) File.Create(FileName).Close(); }
public OrderMSSQLRepository(ReaderRepository readerRepository, BookRepository bookRepository, LibraryDepartmentRepository libraryDepartmentRepository, LibrarianRepository librarianRepository, LibraryDataContext context) { this.readerRepository = readerRepository; this.bookRepository = bookRepository; this.libraryDepartmentRepository = libraryDepartmentRepository; this.librarianRepository = librarianRepository; this.context = context; }
public void ShouldUpdateBook() { var repo = new BookRepository(Context); var book = repo.FindById(2); // The Two Towers book.ISBN = "9780618002238"; repo.Update(book); Context.Commit(); var updatedBook = repo.FindById(2); Assert.That(updatedBook.ISBN == book.ISBN, "The book property has not changed."); }
public TestMongoRepository(string db_name) { getDatabase(db_name); this.cr = new ClientRepository(db); this.br = new BookRepository(db); this.or = new OrderRepository(db); Fill(); //View(); //Clear(); }
private static IRepository<Book> GetOrCreateSession() { var session = GetSession(); if (session != null) { return null; } session = new BookRepository(); SaveSession(session); return null; }
public void TestInitialize() { var book = BookCreator(); _db = new DataContext(); if (_db.Database.Exists()) _db.Database.Delete(); _db.Database.Create(); _db.Books.Add(book); _db.SaveChanges(); _repo = new BookRepository(); }
public ActionResult Edit(int id) { var book = new BookRepository().GetById(id); if (book == null) return RedirectToAction("Index", "Home"); return View(new BookModel { Id = book.Id, Title = book.Title, ISBN = book.ISBN, AuthorId = book.AuthorId, Authors = GetAuthorsList(), IsEditMode = true }); }
public void ShouldDeleteAuthorWithBooks() { var personRepo = new PersonRepository(Context); var author = personRepo.FindById(6); // Stephenie Meyer personRepo.Delete(author); Context.Commit(); var deletedAuthor = personRepo.FindById(6); Assert.That(deletedAuthor == null, "The deleted person was found by the repository."); var bookRepo = new BookRepository(Context); var deletedBooks = bookRepo.FindAll().Where(x => x.Id >= 8); Assert.That(!deletedBooks.Any(), "The person was deleted, but some of her books wasn't."); }
public OrderXMLRepository(ReaderRepository readerRepository, BookRepository BookRepository, LibraryDepartmentRepository libraryDepartmentRepository, LibrarianRepository librarianRepository) { this.readerRepository = readerRepository; this.bookRepository = BookRepository; this.libraryDepartmentRepository = libraryDepartmentRepository; this.librarianRepository = librarianRepository; if (!Directory.GetParent(FileName).Exists) Directory.GetParent(FileName).Create(); if (File.Exists(FileName)) { document = XDocument.Load(FileName); } else { document = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XElement("Orders", null)); document.Save(FileName); } }
public BookModel[] GetBooks() { BookRepository bRepo = new BookRepository(_dal); Book[] books = bRepo.List(); List<BookModel> bookModel = new List<BookModel>(); foreach(Book book in books) { bookModel.Add(new BookModel { Id = book.id, Name = book.name, Number = book.number, CategoryId = book.catid, Image = book.image, Added = book.added }); } return bookModel.ToArray(); }
private static BookRepository CreateRepository() { var repository = new BookRepository(); repository.Add(new Book("978-0735667457", "0735667454", "CLR via C#", 4, new DateTime(2012, 12, 4), new[] {"testing", "C#", "programming", "windows"})); repository.Add(new Book("978-0735662780", "0735662789", "Inside Windows Debugging", 1, new DateTime(2012, 5, 21), new[] {"debugging", "logic", "compiler", "windows"})); repository.Add(new Book("978-1617291081", "1617291080", "Learn Windows PowerShell 3 in a Month of Lunches", 1, new DateTime(2012, 11, 22), new[] {"C", "C++", "network", "administration", "windows"})); return repository; }
public BookModel[] GetLatestBooks(int count) { BookRepository bRepo = new BookRepository(_dal); Book[] books = bRepo.List().OrderByDescending(x => x.added).Take(count).ToArray(); List<BookModel> bookModel = new List<BookModel>(); foreach(Book book in books) { bookModel.Add(new BookModel { Id = book.id, Name = book.name, Number = book.number, CategoryId = book.catid, Image = book.image, Added = book.added }); } return bookModel.ToArray(); }
public BookModel[] Search(string query) { BookRepository bRepo = new BookRepository(_dal); string q = query.Filter(@"%\^#").Escape().Trim(); Book[] books = bRepo.Search(q); List<BookModel> bookModel = new List<BookModel>(); foreach(Book book in books) { bookModel.Add(new BookModel { Id = book.id, Name = book.name, Number = book.number, CategoryId = book.catid, Image = book.image, Added = book.added }); } return bookModel.ToArray(); }
public BookService(BookRepository bookingRepository) { bookRepository = bookingRepository; }
public IndexModel(CalibreContext db, IStringLocalizer <SharedResource> loc) { bookRepository = new BookRepository(db); authorRepository = new AuthorRepository(db); this.loc = loc; }
public DiscountService() { _discountRepository = new DiscountRepository(); _bookRepository = new BookRepository(); }
public int AddItem(Book book) { book.Id = ++IdStorage.UniqueId; BookRepository.GetBookRepository().Books.Add(book); return(IdStorage.UniqueId); }
public Book GetItemById(int id) { return(BookRepository.GetBookRepository().Books.FirstOrDefault(i => i.Id == id)); }
public HomeController(BookRepository bookRepo, CatRepository catRepo, SubCatRepository subCatRepo) { this.bookRepo = bookRepo; this.catRepo = catRepo; this.subCatRepo = subCatRepo; }
static void Main(string[] args) { //Exception Hnadeling StreamReader streamReader = null; try { streamReader = new StreamReader(@"c:\test.zip"); var content = streamReader.ReadToEnd(); throw new Exception("!"); } catch (Exception ex) { Console.WriteLine("Error Occurred!"); } finally { if (streamReader != null) { streamReader.Dispose(); } } ///Or /// StreamReader streamReader = null; try { //using (var StreamReader = new StreamReader(@"c:\test.zip")) //{ // var content = streamReader.ReadToEnd(); //} var youtube = new YouTubeApi(); var vids = youtube.GetVideos("user"); } catch (Exception ex) { Console.WriteLine(ex.Message); } //Dynamics dynamic dynamic = "test"; dynamic = 10; dynamic a = 10; dynamic bbb = 5; var c = a + bbb; int d = a; long e = d; //Nullables DateTime?date = null; Console.WriteLine(date.GetValueOrDefault()); Console.WriteLine(date.HasValue); //Console.WriteLine(date.Value); DateTime date2 = date.GetValueOrDefault(); DateTime?date3 = date2; ///Linq Extension Methods var books1 = new BookRepository().GetBooks(); var cheapBooks1 = books1.Where(x => x.Price < 10).OrderBy(x => x.Title); //Linq Query Operator var cheaperBooks = from b in books1 where b.Price < 10 orderby b.Title select b.Title; //Extensions string post = "this is long long long post..."; var shortenedPost = post.Shorten(3); Console.WriteLine(shortenedPost); //Events var video = new Video() { Title = "Video Title 1" }; var videoEncoder = new VideoEncoder(); /// Publisher var mailService = new MailService(); // subscriber var messageService = new MessageService(); videoEncoder.videoEncoded += mailService.OnVideoEncoded; videoEncoder.videoEncoded += messageService.OnVideoEncoded; videoEncoder.Encode(video); // => const int factor = 5; Func <int, int> multipler = n => n * factor; Console.WriteLine(multipler(5)); var books = new BookRepository().GetBooks(); //var cheapBooks = books.FindAll(IsCheaperThan10Dollars); var cheapBooks = books.FindAll(b => b.Price < 10); foreach (var book in cheapBooks) { Console.WriteLine(book.Title); } //Delegates var photo = new PhotoProcessor(); var filters = new PhotoFilters(); //PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += RemoveRedEyeFilter; photo.Process("test", filterHandler); //Generics var numbers = new Generic <int>(); numbers.Add(10); var dictionary = new GenericDictionary <string, Book>(); dictionary.Add("1", new Book()); var NUMBER = new AdvancedTopics.Nullable <int>(); Console.WriteLine("Has Value? " + NUMBER.HasValue); Console.WriteLine("Value: " + NUMBER.GetValueOrDefault()); //Or You can use System.Nullable for this purpose. }
// GET: BooksList public ActionResult Index() { Books = new BookRepository(); return(View(Books)); }
// GET: Home public ActionResult Index() { IEnumerable <BookDetails> bookDetails = BookRepository.GetBooks(); return(View(bookDetails)); }
public ActionResult DeleteBook(int id) { BookRepository.DeleteBook(id); TempData["Message"] = "Deleted Successfully"; return(RedirectToAction("Index")); }
public ActionResult UpdateResult([Bind(Exclude = "authorName")] BookDetails book) { BookRepository.UpdateBook(book.bookId, book.bookName, book.authorName); TempData["Message"] = "Updated Successfully"; return(RedirectToAction("Index")); }
protected async Task DeleteBook() { await BookRepository.Delete(Book.ID); NavigationManager.NavigateTo("/BookList"); }
static void Main(string[] args) { //Mapper.Initialize(cfg => cfg.AddProfiles(typeof(Startup))); var bookRepo = new BookRepository(); var authorRepo = new AuthorRepository(); var userRepo = new UserRepository(); var rentedBookRepo = new RentedBookRepository(); //var testBookBusiness = new BookBusiness { Name = "Test 3", ISBN = "987654321987", PageCount = 150, IsDeleted = false, PublishingDate = new DateTime(2016, 05, 07), AuthorId = 1 }; //var authorData = new AuthorBusiness(); //authorData.Name = "Test Author Business"; //authorData.Birthdate = new DateTime(2017, 12, 23); //authorData.Books.Add(testBookBusiness); //authorData.Books.ToList(); //authorData.IsDeleted = false; //authorData.Gender = 0; //var testUser = new UserBusiness { Name = "Test User", IsDeleted = false, Address = "Mladost 1", Email = "*****@*****.**", // Gender = 0, PhoneNumber = "0879 555 201", UniqueIdNumber = "7946132598" }; //var testRentedBook = new RentedBookBusiness { BookId = 10, UserId = 1, DateRented = DateTime.Now, DateToReturn = new DateTime(2018, 06, 05), IsDeleted = false}; //var authorUpdate = authorRepo.Read(2); //authorUpdate.Name = "Test Author Business 2"; //authorUpdate.Birthdate = new DateTime(2000, 5, 3); //authorRepo.Update(authorUpdate); //var bookUpdate = bookRepo.Read(9); //bookUpdate.Name = "Updated name 2"; //bookRepo.Update(bookUpdate); //authorRepo.Create(authorData); //bookRepo.Create(testBookBusiness); //userRepo.Create(testUser); //var rentedBookToUpdate = rentedBookRepo.Read(2); //rentedBookToUpdate.DateToReturn = new DateTime(2018, 06, 15); // rentedBookRepo.Update(rentedBookToUpdate); //var isRentedBook = bookRepo.IsBookRented(9); //Console.WriteLine(isRentedBook); //var book = Mapper.Map<BookBusiness>(bookBusiness); //var author = Mapper.Map<AuthorBusiness>(authorData); //bookRepo.Delete(8); var allBooks = bookRepo.ReadAll(); foreach (var book in allBooks) { Console.WriteLine($"{book.Name}"); } //Console.WriteLine($"{book.Name}, {book.ISBN}, {book.PageCount}, {book.IsDeleted}"); //Console.WriteLine($"{author.Name}, {author.Birthdate}, {author.Gender}, {author.IsDeleted}"); //foreach (var item in authorData.Books) //{ // Console.WriteLine($"{item.Name}, {item.PageCount}, {item.ISBN}, {item.IsDeleted}"); //} }
//We added dependency for BookRepository in Staup class public BookController(BookRepository bookRepository) { //_bookRepository = new BookRepository(); _bookRepository = bookRepository; }
public BooksController(BookRepository bookRepo) { _bookRepo = bookRepo; }
public BooksController(BookRepository bookRepository) { _bookRepository = bookRepository; }
public BookRepositoryTests() { _bkRepo = TestUtils.ConstructorUtils.bookRepo; _auRepo = TestUtils.ConstructorUtils.authorRepo; }
public BookController() { bookRepository = new BookRepository(); }
public bool RemoveItem(int id) { var result = BookRepository.GetBookRepository().Books.RemoveAll(book => book.Id == id); return(result > 0); }
public PurchaseOutputModel Process(PurchaseInputModel data) { PurchaseRepository repo = new PurchaseRepository(db); Payment temp = new Payment(); DateTime today = DateTime.Now; temp.Diskon = data.Diskon; temp.InvoiceNo = GenerateInvoice(); temp.UserID = data.UserID; temp.TotalPrice = data.GrandTotal; temp.SubTotalPrice = data.SubTotal; temp.CreateByUserID = data.UserID; temp.CreateDate = today; temp.TotalPaid = data.UangMuka; temp.PPNProsen = data.PPNProsen; temp.isLunas = data.GrandTotal - data.UangMuka == 0 ? true : false; if (data.BookID.Count() > 0) { foreach (var x in data.BookID) { Guid bookID = new Guid(); bookID = Guid.Parse(x); temp.BookID = bookID; //keterangan user bayar full payment atau DP var paymentTypeQuery = (from p in db.Payment join m in db.MidTransLog on p.ID equals m.PaymentID where p.BookID == bookID && m.MidTransStatus != 0 select new { m }); var countPaymentType = paymentTypeQuery.Count(); temp.PaymentType = countPaymentType == 0 && data.GrandTotal - data.UangMuka == 0 ? (int)TransactionTypeEnum.FullPayment : countPaymentType < 1 && data.GrandTotal - data.UangMuka != 0 ? (int)TransactionTypeEnum.DP : (int)TransactionTypeEnum.FullPayment; } } var res = repo.Insert(temp); PurchaseOutputModel output = new PurchaseOutputModel(); if (res.ID != Guid.Empty) { output.IDTransaction = res.ID; output.InvoiceNo = temp.InvoiceNo; List <Guid> listBookID = new List <Guid>(); foreach (var x in data.BookID) { listBookID.Add(Guid.Parse(x)); } BookRepository bookRepo = new BookRepository(db); bookRepo.UpdatePurchase(listBookID, res.ID); } return(output); }
public IEnumerable <Book> GetAllItems() { return(BookRepository.GetBookRepository().Books.ToArray()); }
public MyOrdersModel(CartRepository context, BookRepository Bcontext) { CR = context; BR = Bcontext; }
public BookDetailsForm(BookRentRepository bookRentRepository, BookRepository bookRepository) { InitializeComponent(); BookRentRepository = bookRentRepository; BookRepository = bookRepository; }
public Manager() { BookRepository = new BookRepository(); MemberRepository = new MemberRepository(); }
public UnitOfWork(BookContext context) { _context = context; Books = new BookRepository(_context); Authors = new AuthorRepository(_context); }
public void ShowAllBooks() { BookRepository.GetAll().ForEach(x => x.Print()); }
public void SearchByEditionDate_Test() { Book book1 = new Book { Author = "Author", Title = "Title1", EditionDate = DateTimeOffset.Parse("06/01/2008") }; Book book2 = new Book { Author = "Author", Title = "Title2", EditionDate = DateTimeOffset.Parse("06/01/2008") }; Book book3 = new Book { Author = "Author", Title = "Title3", EditionDate = DateTimeOffset.Parse("06/01/2008") }; Book book4 = new Book { Author = "Author", Title = "Title4", EditionDate = DateTimeOffset.Parse("06/02/2008") }; Book book5 = new Book { Author = "Author1", Title = "Title5", EditionDate = DateTimeOffset.Parse("06/02/2008") }; Book book6 = new Book { Author = "Author1", Title = "Title6", EditionDate = DateTimeOffset.Parse("06/02/2008") }; Book book7 = new Book { Author = "Author1", Title = "Title7", EditionDate = DateTimeOffset.Parse("06/02/2016") }; Book book8 = new Book { Author = "Author1", Title = "Title8", EditionDate = DateTimeOffset.Parse("06/02/2016") }; List <Book> list1 = new List <Book>(); list1.Add(book1); list1.Add(book2); list1.Add(book3); List <Book> list2 = new List <Book>(); list2.Add(book4); list2.Add(book5); list2.Add(book6); List <Book> list3 = new List <Book>(); list3.Add(book7); list3.Add(book8); var bookRepository = new BookRepository(context); bookRepository.Create(book1); bookRepository.Create(book2); bookRepository.Create(book3); bookRepository.Create(book4); bookRepository.Create(book5); bookRepository.Create(book6); bookRepository.Create(book7); bookRepository.Create(book8); var targetList1 = bookRepository.SearchByEditionDate("06", "01", "2008"); var targetList2 = bookRepository.SearchByEditionDate("06", "02", "2008"); var targetList3 = bookRepository.SearchByEditionDate("06", "02", "2016"); CollectionAssert.AreEqual(list1, targetList1); CollectionAssert.AreEqual(list2, targetList2); CollectionAssert.AreEqual(list3, targetList3); }
public BookController(BookRepository bookRepository, languageRepo languageRepo) //constructor and create dependencies in book constructor { _bookRepository = bookRepository; _languageRepo = languageRepo; }
public void Should_Map_A_Model_To_A_Book() { var repository = new AuthorRepository(); var author = repository.Insert(new Author { FirstName = "Cormac", LastName = "McCarthy" }); var book = new BookRepository(repository).CreateNew(); book = Mapper.Map<BookModel, Book>(new BookModel { Id = 5, Title = "The Road", ISBN = "1234567891234", AuthorId = author.Id, IsEditMode = false }, book); Assert.AreEqual(5, book.Id); Assert.AreEqual("The Road", book.Title); Assert.AreEqual("1234567891234", book.ISBN); Assert.AreEqual(author.Id, book.AuthorId); }
public APIDbTopFiveBooksController() { repo = new BookRepository(); }
public BookServices(BookRepository bookrepo) { _bookRepo = bookrepo; }
public ActionResult EditBook(int id) { BookDetails bookDetails = BookRepository.FindBook(id); return(View(bookDetails)); }