Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions Team2LibraryProject_01/Controllers/BooksController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
Expand All @@ -11,6 +12,10 @@

namespace Team2LibraryProject_01.Controllers
{
public class Pictures
{
public HttpPostedFileBase File { get; set; }
}
public class BooksController : Controller
{
private Team2LibraryEntities db = new Team2LibraryEntities();
Expand Down Expand Up @@ -383,6 +388,7 @@ public ActionResult AddBook()
[ValidateAntiForgeryToken]
public ActionResult AddBook([Bind(Include = "ISBN,Author_FName,Author_LName,Publisher,NumOfPages,Title,Year,Genre,Language,Rating,Synopsis,Shelf")] Book book)
{
ViewBag.ISBN = book.ISBN;
if (ModelState.IsValid)
{
db.Books.Add(book);
Expand All @@ -394,6 +400,18 @@ public ActionResult AddBook([Bind(Include = "ISBN,Author_FName,Author_LName,Publ

ViewBag.Genre = new SelectList(db.Genres, "GenreID", "Genre1", book.Genre);
ViewBag.Language = new SelectList(db.Languages, "LanguageID", "Language1", book.Language);

if (Request.Files.Count > 0)
{
var bookCover = Request.Files[0];
if (bookCover != null && bookCover.ContentLength > 0)
{
var filename = ISBN + ".png";
var path = Server.MapPath("~/Content/Images/Books/");
path = System.IO.Path.Combine(path, filename);
bookCover.SaveAs(path);
}
}
return View(book);
}

Expand Down
1 change: 1 addition & 0 deletions Team2LibraryProject_01/Team2LibraryProject_01.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@
<Content Include="Views\Reservations\Edit.cshtml" />
<Content Include="Views\Reservations\Index.cshtml" />
<Content Include="Views\Reviews\ReviewList.cshtml" />
<Content Include="Views\Home\imagetest.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
Expand Down
15 changes: 10 additions & 5 deletions Team2LibraryProject_01/Views/Books/AddBook.cshtml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
@model Team2LibraryProject_01.Models.Book

@using System.Collections

<h2>Create Book Entry</h2>
<hr />
<body>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")


@using (Html.BeginForm())
@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()

Expand Down Expand Up @@ -108,6 +110,13 @@
@Html.ValidationMessageFor(model => model.Shelf, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.Label("Cover Image", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" name="file" id="File" class="form-control" />
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
Expand All @@ -116,10 +125,6 @@
</div>
</div>
}
<hr />
<p style="color: red">*Note: Creating a new book will require code changes to properly implement thumbnails.</p>
<p style="color: red">Placeholder images will be used on the interim.</p>
<hr />
<div>
@Html.ActionLink("Back to List", "BookIndex")
</div>
Expand Down
2 changes: 1 addition & 1 deletion Team2LibraryProject_01/Views/Books/BookDetails.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<body>
<div class="row">
<div class="col-md-5">
<img id="books" alt="books_cover" src="@Url.Content(ViewBag.Image)" onerror="this.onerror = null; this.src = 'http://placehold.it/400x600';">
<img id="books" alt="books_cover" src="@Url.Content(ViewBag.Image)" height="600" width="400" onerror="this.onerror = null; this.src = 'http://placehold.it/400x600';">
</div>

<div class="col-md-6">
Expand Down
2 changes: 1 addition & 1 deletion Team2LibraryProject_01/Views/Home/Books.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
string output = item.ISBN;
string thumbOut = item.ISBN + ".png";
<div class="col-lg-3 col-sm-4 col-xs-6" align="center">
<a href="/Books/BookDetails/@output"><img src="~/Content/Images/Thumbs/@thumbOut" onerror="this.onerror = null; this.src = 'http://placehold.it/170x250';" align="middle"></a>
<a href="/Books/BookDetails/@output"><img src="~/Content/Images/Books/@thumbOut" height="250" width="170" onerror="this.onerror = null; this.src = 'http://placehold.it/170x250';" align="middle"></a>
<br />
<br />
<p style="font-size: 14px; font-weight: 500">@Html.DisplayFor(modelItem => item.Title)</p>
Expand Down