public void Test3()
        {
            List <Author> authors = new List <Author>()
            {
                new Author()
                {
                    Name = "A1"
                },
                new Author()
                {
                    Name = "B2"
                },
                new Author()
                {
                    Name = "B3"
                }
            };

            database = GetDatabase(authors);
            var service = new AuthorController(database, _logger);

            var result = service.Get();

            Assert.AreEqual(200, result.StatusCode);
            var list = ((DbSet <Author>)result.Value).ToList();

            Assert.AreEqual(authors.Count, list.Count);
            for (int i = 0; i < authors.Count; i++)
            {
                Assert.AreEqual(authors[i].Name, list[i].Name);
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var authId = Request["AuthId"];

            if (authId == null)
            {
                return;
            }
            FirstName.Text = authId;

            int intAuthId;

            int.TryParse(authId, out intAuthId);

            var                db           = new AuthorsContext();
            IList <Author>     qAuthors     = db.Authors.Select(p => p).ToList();
            IList <Book>       qBooks       = db.Books.Select(p => p).ToList();
            IList <AuthorBook> qAuthorBooks = db.AuthorBooks.Select(p => p).ToList();

            var author = qAuthors.Single(p => p.AuthorID == intAuthId);

            FirstName.Text  = author.FirstName;
            MiddleName.Text = author.MiddleName;
            LastName.Text   = author.LastName;
            AuthorID.Text   = author.AuthorID.ToString();

            var bookId    = qAuthorBooks.Where(s => s.AuthorID == author.AuthorID).Select(p => p.BookID);
            var listBooks = bookId.Select(id => qBooks.Single(p => p.BookID == id)).ToList();

            this.SubRepeater.DataSource = listBooks;
            this.SubRepeater.DataBind();
        }
        public void Test6()
        {
            List <Author> authors = new List <Author>()
            {
                new Author()
                {
                    Name = "A1"
                },
                new Author()
                {
                    Name = "B2"
                },
                new Author()
                {
                    Name = "B3"
                }
            };

            database = GetDatabase(authors);
            var service = new AuthorController(database, _logger);

            var result = service.Get("B2");

            Assert.AreEqual(200, result.StatusCode);
            var author = (Author)result.Value;

            Assert.AreEqual("B2", author.Name);
        }
        public void Test5()
        {
            List <Author> authors = new List <Author>()
            {
                new Author()
                {
                    Name = "A1"
                },
                new Author()
                {
                    Name = "B2"
                },
                new Author()
                {
                    Name = "B3"
                }
            };

            database = GetDatabase(authors);
            var service = new AuthorController(database, _logger);

            var result = service.Get("B400");

            Assert.AreEqual(404, result.StatusCode);
            Assert.AreEqual("No authors with this name found", result.Value);
        }
Beispiel #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, AuthorsContext context)
        {
            // context.Database.EnsureCreated ( );
            context.Database.Migrate( );  //prilikom konfiguracije aplikacije izvrsice se sve potrebne migracije baze
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Beispiel #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var _db = new AuthorsContext();
            IQueryable <Author> qAuthors = _db.Authors;

            List <Author> authors = new List <Author>();

            foreach (var a in qAuthors)
            {
                authors.Add(a);
            }

            this.SubRepeater.DataSource = authors;
            this.SubRepeater.DataBind();
        }
        public void Test8()
        {
            List <Author> authorsNew = new List <Author>()
            {
                new Author()
                {
                    Name = "A1"
                },
                new Author()
                {
                    Name = "B2"
                },
                new Author()
                {
                    Name = "B3"
                }
            };
            List <Author> authors = new List <Author>();

            database = GetDatabase(authors);
            var service = new AuthorController(database, _logger);

            foreach (var author in authorsNew)
            {
                var code = service.Post(author);
                Assert.AreEqual(200, code.StatusCode);
                Assert.AreEqual("Succesful adding", code.Value);
            }

            var result = service.Get();

            Assert.AreEqual(200, result.StatusCode);
            Assert.AreEqual(authorsNew.Count, authors.Count);
            for (int i = 0; i < authorsNew.Count; i++)
            {
                Assert.AreEqual(authorsNew[i].Name, authors[i].Name);
            }
        }
Beispiel #8
0
 public GenreController(AuthorsContext context)
 {
     _context = context;
 }
Beispiel #9
0
 public BookController(AuthorsContext context)
 {
     _context = context;
 }
Beispiel #10
0
        protected void Save_OnClick(object sender, EventArgs e)
        {
            var db = new AuthorsContext();

            int newAuthorID;
            var authors = db.Authors.Select(s =>
                                            s).ToList();
            var author = authors.FirstOrDefault(p => p.FirstName == FirstName.Text && p.LastName == LastName.Text &&
                                                p.MiddleName == MiddleName.Text);

            if (author != null)
            {
                newAuthorID = author.AuthorID;
            }
            else
            {
                author = new Author
                {
                    FirstName  = FirstName.Text,
                    LastName   = LastName.Text,
                    MiddleName = MiddleName.Text,
                    Birthday   = new DateTime(1950, 5, 5)
                };
                db.Authors.AddOrUpdate(author);
                db.SaveChanges();
                newAuthorID = db.Authors.Select(s =>
                                                s).First(p => p.FirstName == author.FirstName && p.LastName == author.LastName &&
                                                         p.MiddleName == author.MiddleName).AuthorID;
            }


            int i = 0;

            for (;;)
            {
                i++;
                var ctrlBookName = Page.Request.Form["BookName" + i];
                var ctrlGenre    = Page.Request.Form["Genre" + i];
                int ctrlPages;
                int.TryParse((Page.Request.Form["TotalPages" + i]), out ctrlPages);

                if (ctrlBookName == null &&
                    ctrlGenre == null &&
                    ctrlPages == 0)
                {
                    Response.Redirect("Default.aspx");
                    return;
                }

                int newBookID;
                var books = db.Books.Select(s =>
                                            s).ToList();
                var book = books.FirstOrDefault(p => p.Name == ctrlBookName && p.Genre == ctrlGenre && p.TotalPages == ctrlPages);
                if (book != null)
                {
                    newBookID = book.BookID;
                }
                else
                {
                    book = new Book
                    {
                        Name       = ctrlBookName,
                        Genre      = ctrlGenre,
                        TotalPages = ctrlPages
                    };
                    db.Books.AddOrUpdate(book);
                    db.SaveChanges();
                    newBookID =
                        db.Books.Select(s => s)
                        .First(
                            p =>
                            p.Name == ctrlBookName && p.Genre == ctrlGenre &&
                            p.TotalPages == ctrlPages)
                        .BookID;
                }

                var newAuthBooks = db.AuthorBooks.Select(s =>
                                                         s).ToList();
                var newAuthBook = newAuthBooks.FirstOrDefault(p => p.AuthorID == newAuthorID && p.BookID == newBookID);
                if (newAuthBook == null)
                {
                    newAuthBook = new AuthorBook
                    {
                        AuthorID = author.AuthorID,
                        BookID   = book.BookID
                    };
                    db.AuthorBooks.AddOrUpdate(newAuthBook);
                    db.SaveChanges();
                }
            }
        }
Beispiel #11
0
 public HomeController(AuthorsContext context)
 {
     _context = context;
 }
Beispiel #12
0
 public AuthorController(AuthorsContext nDatabase, ILogger <AuthorController> nLogger)
 {
     database = nDatabase;
     _logger  = nLogger;
 }
 public void Initialize()
 {
     _logger  = Mock.Of <ILogger <AuthorController> >();
     database = GetDatabase();
 }
 public AuthorController(AuthorsContext context)
 {
     _context = context;
 }
Beispiel #15
0
 public HomeController(ILogger <HomeController> logger, AuthorsContext context)
 {
     _logger      = logger;
     this.context = context;
 }