public ActionResult Create(BookViewModel bookViewModel) { // Model Kontrol Edilir if (ModelState.IsValid) { var category = db.Categories.Where(x => x.Id == bookViewModel.CategoryId).FirstOrDefault(); // Kategori Seçimi Kontrol Edilir if (category == null) { TempData.Add("Alert", "Lütfen kategori seçiniz."); return(View()); } else { // Yazar Seçimi Kontrol Edilir if (bookViewModel.AuthorId.Length <= 0) { TempData.Add("Alert", "Yazar seçmeniz gerekmektedir."); return(View()); } else { // Business Sınıfından Başarılı yazısı dönene kadar işlemler devam eder string returnMessage = Business.BookBusiness.CreateBook(bookViewModel); if (returnMessage == "Kayıt Başarılı") { TempData.Add("Alert", returnMessage); return(RedirectToAction("Index")); } else { var categoryList = BookBusiness.CategorySelectList(); var authorList = BookBusiness.AuthorSelectList(); TempData.Add("Alert", returnMessage); TempData["categories"] = categoryList; ViewBag.Categories = authorList; ViewBag.Author = categoryList; return(View()); } } } } else { var categoryList = BookBusiness.CategorySelectList(); var authorList = BookBusiness.AuthorSelectList(); TempData.Add("Alert", "Bir hata oluştu"); return(Redirect("/Book/create")); } }
public static Book ConvertToWebEntity(BookBusiness book) { var dataObject = new Book(); dataObject.Id = book.Id; dataObject.Name = book.Name; dataObject.ISBN = book.ISBN; dataObject.countPages = book.countPages; dataObject.datePublished = (DateTime)book.datePublished; dataObject.AuthorId = book.AuthorId; //MappingWeb.ConvertToWebEntity(book.Author); dataObject.OwnerId = book.OwnerId; //MappingWeb.ConvertToWebEntity(book.Owner); dataObject.isDeleted = book.isDeleted; return(dataObject); }
public static BookBusiness ConvertToBusinessEntity(Book book) { var businessObject = new BookBusiness(); businessObject.Id = book.Id; businessObject.Name = book.Name; businessObject.ISBN = book.ISBN; businessObject.countPages = book.countPages; businessObject.datePublished = (DateTime)book.datePublished; businessObject.AuthorId = book.AuthorId; //MappingWeb.ConvertToBusinessEntity(book.Author); businessObject.OwnerId = book.OwnerId; //MappingWeb.ConvertToBusinessEntity(book.Owner); businessObject.isDeleted = book.isDeleted; return(businessObject); }
public void GetByKeyId( ) { BookEntity bookEntity = new BookEntity( ); Mock <IRepository <BookEntity> > mockRepository = new Mock <IRepository <BookEntity> >( ); mockRepository .Setup((a) => a.FindByKeyId(It.IsAny <Guid>( ))) .Returns(bookEntity); BookBusiness bookBusiness = new BookBusiness(mockRepository.Object, AutoMapperConfigTest.GetInstance( )); var result = bookBusiness.GetByKeyId(It.IsAny <Guid>( )); result.Should( ).BeOfType <BookModel>( ); }
public void GetAll( ) { List <BookEntity> bookEntities = new List <BookEntity>( ); Mock <IRepository <BookEntity> > mockRepository = new Mock <IRepository <BookEntity> >( ); mockRepository .Setup((a) => a.FindAll( )) .Returns(bookEntities); BookBusiness bookBusiness = new BookBusiness(mockRepository.Object, AutoMapperConfigTest.GetInstance( )); var result = bookBusiness.ListAll( ); result.Should( ).BeOfType <List <BookModel> >( ); }
/// <summary> /// Adds a new book to the organization. /// </summary> /// <param name="book">The book.</param> public void AddBook(Book book) { if (ownedBooks.Contains(book)) { throw new InvalidOperationException("Book already contained"); } ownedBooks.Add(book); var business = bookBusinesses.FirstOrDefault(b => b.BookTemplate == book.Template); if (business == null) { business = new BookBusiness(book.Template, this); bookBusinesses.Add(business); } }
public static void Main(string[] args) { var db = new LibrarySystemDbEntities2(); var author = db.Book.FirstOrDefault(b => b.Id == 3).Owner.Name; Console.WriteLine(author); var bookRepo = new BookRepository(); var authorRepo = new AuthorRepository(); var ownerRepo = new OwnerRepository(); //var bookUpdate3 = bookRepo.Read(3); //var bookUpdate4 = bookRepo.Read(4); //bookUpdate3.isDeleted = false; //bookUpdate4.isDeleted = false; //bookRepo.Update(bookUpdate3); //bookRepo.Update(bookUpdate4); //var owner1 = new OwnerBusiness(); //owner1.Name = "Alex Todorv"; //owner1.Gender = 0; //owner1.Email = "*****@*****.**"; //owner1.Address = "Sofia, Druzhba 2"; //owner1.UniqueIdNumber = "9406257845"; //owner1.isDeleted = false; var book1 = new BookBusiness { Name = "Test book", ISBN = 122445667, countPages = 120, AuthorId = 12, OwnerId = 4 }; //var author1 = new AuthorBusiness(); //author1.Name = "Hristo Botev"; //author1.isDeleted = false; //author1.Gender = 0; //var book3 = new BookBusiness { Name = "Pod Igoto", ISBN = 122445667, countPages = 230, Author = author1, Owner = new OwnerBusiness { Name = "Gosho Peshov", PhoneNumber = "08859494616", Email = "*****@*****.**" } }; bookRepo.Create(book1); //authorRepo.Create(author1); //bookRepo.Create(book3); //ownerRepo.Create(owner1); }
public void Setup() { var data = new List <Book>().AsQueryable(); mockDBSetBooks = new Mock <DbSet <Book> >(); mockDBSetBooks.As <IQueryable <Book> >().Setup(m => m.Provider).Returns(data.Provider); mockDBSetBooks.As <IQueryable <Book> >().Setup(m => m.Expression).Returns(data.Expression); mockDBSetBooks.As <IQueryable <Book> >().Setup(m => m.ElementType).Returns(data.ElementType); mockDBSetBooks.As <IQueryable <Book> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); mockDBSetBooks.Setup(m => m.Find(2)).Returns(new Book() { Id = 2 }); //Sets up Find method for Case 2 mockContext = new Mock <LibraryContext>(); mockContext.Setup(m => m.Books).Returns(mockDBSetBooks.Object); bookBusiness = new BookBusiness(mockContext.Object); }
// GET: Book/Create public ActionResult Create() { var categoryList = BookBusiness.CategorySelectList(); var authorList = BookBusiness.AuthorSelectList(); if (categoryList.Any()) { if (authorList.Any()) { TempData["categories"] = categoryList; } else { TempData.Add("Alert", "Yazar seçimi yapmadınız"); } } else { TempData.Add("Alert", "Kategori seçimi yapmadınız."); } ViewBag.Author = authorList; ViewBag.Categories = categoryList; return(View()); }
public BooksController(BookStoreContext context) { _bookBusiness = new BookBusiness(context); }
/// <summary> /// Constructor /// </summary> /// <param name="business"></param> public BookController(BookBusiness business) { _business = business; }
public void Setup() { var data = new List <Book> //Books { new Book { Title = "AAA", AuthorName = "The Paladin", IsAvailable = true, ClientId = 2, PublisherId = 3, DateOfReturn = DateTime.Today, DateOfPublishing = DateTime.Today }, new Book { Title = "BBB", AuthorName = "The Paladin", IsAvailable = false, PublisherId = 2, Language = "eng", DateOfPublishing = DateTime.Today.AddDays(3) }, new Book { Title = "CCC", AuthorName = "The Professor", IsAvailable = true, PublisherId = 3, Language = "eng", DateOfPublishing = DateTime.Today.AddDays(14) }, }.AsQueryable(); mockDBSetBooks = new Mock <DbSet <Book> >(); mockDBSetBooks.As <IQueryable <Book> >().Setup(m => m.Provider).Returns(data.Provider); mockDBSetBooks.As <IQueryable <Book> >().Setup(m => m.Expression).Returns(data.Expression); mockDBSetBooks.As <IQueryable <Book> >().Setup(m => m.ElementType).Returns(data.ElementType); mockDBSetBooks.As <IQueryable <Book> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var data2 = new List <Client> //Clients { new Client { Id = 1 }, new Client { Id = 2 }, new Client { Id = 3 }, }.AsQueryable(); Mock <DbSet <Client> > mockDBSetClients = new Mock <DbSet <Client> >(); mockDBSetClients.As <IQueryable <Client> >().Setup(m => m.Provider).Returns(data2.Provider); mockDBSetClients.As <IQueryable <Client> >().Setup(m => m.Expression).Returns(data2.Expression); mockDBSetClients.As <IQueryable <Client> >().Setup(m => m.ElementType).Returns(data2.ElementType); mockDBSetClients.As <IQueryable <Client> >().Setup(m => m.GetEnumerator()).Returns(data2.GetEnumerator()); var data3 = new List <Publisher> //Publishers { new Publisher { Id = 1, Name = "Publisher 1" }, new Publisher { Id = 2, Name = "Publisher 2" }, new Publisher { Id = 3, Name = "Publisher 3" }, }.AsQueryable(); Mock <DbSet <Publisher> > mockDBSetPublishers = new Mock <DbSet <Publisher> >(); mockDBSetPublishers.As <IQueryable <Publisher> >().Setup(m => m.Provider).Returns(data3.Provider); mockDBSetPublishers.As <IQueryable <Publisher> >().Setup(m => m.Expression).Returns(data3.Expression); mockDBSetPublishers.As <IQueryable <Publisher> >().Setup(m => m.ElementType).Returns(data3.ElementType); mockDBSetPublishers.As <IQueryable <Publisher> >().Setup(m => m.GetEnumerator()).Returns(data3.GetEnumerator()); mockContext = new Mock <LibraryContext>(); mockContext.Setup(c => c.Books).Returns(mockDBSetBooks.Object); mockContext.Setup(c => c.Clients).Returns(mockDBSetClients.Object); mockContext.Setup(c => c.Publishers).Returns(mockDBSetPublishers.Object); bookBusiness = new BookBusiness(mockContext.Object); }
public BookDisplay() { bookBusiness = new BookBusiness(); Input(); }