Skip to content

Commit 15e14ba

Browse files
committed
Added tagcloud + tooltip + basecontroller + some refactoring
1 parent 0ff6f3e commit 15e14ba

File tree

23 files changed

+261
-93
lines changed

23 files changed

+261
-93
lines changed

BookCollection.Tests/Controllers/HomeControllerTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public void Index()
2525
Assert.IsNotNull(result);
2626
}
2727

28-
[TestMethod]
29-
/*public void About()
28+
/*[TestMethod]
29+
public void About()
3030
{
3131
// Arrange
3232
HomeController controller = new HomeController();
@@ -38,6 +38,6 @@ public void Index()
3838
Assert.AreEqual("Your application description page.", result.ViewBag.Message);
3939
}
4040
*/
41-
41+
4242
}
4343
}

BookCollection/App_Start/BundleConfig.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ public static void RegisterBundles(BundleCollection bundles)
2121

2222
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
2323
"~/Scripts/bootstrap.js",
24-
"~/Scripts/respond.js",
25-
"~/Scripts/_bookCollecion.js"));
24+
"~/Scripts/respond.js"));
2625

2726
bundles.Add(new StyleBundle("~/Content/css").Include(
2827
"~/Content/bootstrap.css",

BookCollection/App_Start/RouteConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static void RegisterRoutes(RouteCollection routes)
1818
url: "{controller}/{action}/{id}",
1919
defaults: new { controller = "Books", action = "Index", id = UrlParameter.Optional }
2020
);
21+
2122
}
2223
}
2324
}

BookCollection/BookCollection.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,14 @@
193193
<Compile Include="App_Start\UnityConfig.cs" />
194194
<Compile Include="App_Start\UnityMvcActivator.cs" />
195195
<Compile Include="Controllers\AuthorsController.cs" />
196+
<Compile Include="Controllers\BaseController.cs" />
196197
<Compile Include="Controllers\BooksController.cs" />
197198
<Compile Include="Controllers\CategoriesController.cs" />
198199
<Compile Include="Controllers\HomeController.cs" />
199200
<Compile Include="Controllers\PublishersController.cs" />
200201
<Compile Include="Controllers\SubjectsController.cs" />
201202
<Compile Include="DAL\BookContext.cs" />
203+
<Compile Include="DAL\BookRepository.cs" />
202204
<Compile Include="DAL\SeedData\BookInitializer.cs" />
203205
<Compile Include="DAL\BookInterceptorLogging.cs" />
204206
<Compile Include="DAL\BookInterceptorTransientErrors.cs" />
@@ -229,6 +231,7 @@
229231
<Content Include="Content\bootstrap.css" />
230232
<Content Include="Content\bootstrap.min.css" />
231233
<Content Include="Content\PagedList.css" />
234+
<Content Include="Content\Tagcloud.css" />
232235
<Content Include="favicon.ico" />
233236
<Content Include="fonts\glyphicons-halflings-regular.svg" />
234237
<Content Include="Global.asax" />
@@ -508,7 +511,6 @@
508511
<Content Include="Scripts\modernizr-2.8.3.js" />
509512
<Content Include="Scripts\respond.js" />
510513
<Content Include="Scripts\respond.min.js" />
511-
<Content Include="Scripts\_bookCollection.js" />
512514
<Content Include="Scripts\_references.js" />
513515
<Content Include="Web.config" />
514516
<Content Include="Web.Debug.config">
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
------------------------------
3+
Tag Cloud
4+
------------------------------
5+
*/
6+
7+
.tag1{font-size: 0.8 em}
8+
.tag2{font-size: 0.9em}
9+
.tag3{font-size: 1em}
10+
.tag4{font-size: 1.2em}
11+
.tag5{font-size: 1.4em}
12+
.tag6{font-size: 1.7em}
13+
.tag7{font-size: 2.0em}

BookCollection/Controllers/AuthorsController.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212

1313
namespace BookCollection.Controllers
1414
{
15-
public class AuthorsController : Controller
15+
public class AuthorsController : BaseController
1616
{
17-
private BookContext db = new BookContext();
18-
1917
// GET: Authors
2018
public ActionResult Index(string sortOrder, string currentFilter, string searchString, int? page, bool noPaging = false)
2119
{
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using BookCollection.DAL;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Web;
6+
using System.Web.Mvc;
7+
8+
namespace BookCollection.Controllers
9+
{
10+
public abstract class BaseController : Controller
11+
{
12+
protected readonly IBookRepository repo;
13+
protected readonly BookContext db;
14+
15+
protected BaseController() : this(new BookRepository(), new BookContext())
16+
{
17+
18+
}
19+
20+
protected BaseController(IBookRepository rep, BookContext bc)
21+
{
22+
repo = rep;
23+
repo.SetContext(bc);
24+
db = bc;
25+
26+
}
27+
}
28+
}

BookCollection/Controllers/BooksController.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ public ActionResult Create()
149149
{
150150
PopulateAuthorDropDownList();
151151
PopulateCategoryDropDownList();
152+
PopulatePublishersDropDownList();
153+
PopulateMainSubjectDropDownList();
154+
PopulateSubjectDropDownList();
152155
return View();
153156
}
154157

@@ -157,9 +160,8 @@ public ActionResult Create()
157160
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
158161
[HttpPost]
159162
[ValidateAntiForgeryToken]
160-
public ActionResult Create([Bind(Include = "BookID,Title,AlternativeTitle,AuthorID,CategoryID,InitialPrintedYear,ActualPrintYear,Language,Material,Read,Pages,ISBN,Website,CoverLink")] Book book)
163+
public ActionResult Create([Bind(Include = "BookID,Title,AlternativeTitle,AuthorID,CategoryID,InitialPrintedYear,ActualPrintYear,Language,Material,Read,Pages,ISBN,Website,CoverLink,Rating,CodeWithinSerie,Condition,ReviewNote,Location")] Book book)
161164
{
162-
book.CreationDate = DateTime.Now;
163165
if (ModelState.IsValid)
164166
{
165167

@@ -169,9 +171,21 @@ public ActionResult Create([Bind(Include = "BookID,Title,AlternativeTitle,Author
169171
}
170172
PopulateAuthorDropDownList(book.AuthorID);
171173
PopulateCategoryDropDownList(book.CategoryID);
174+
PopulatePublishersDropDownList(book.PublisherID);
175+
PopulateMainSubjectDropDownList(book.MainSubjectID);
176+
177+
if (book.Subjects.Count > 0)
178+
{
179+
PopulateSubjectDropDownList(book.Subjects.First().SubjectID);
180+
}else
181+
{
182+
PopulateSubjectDropDownList();
183+
}
184+
172185
return View(book);
173186
}
174187

188+
#region dropdowns
175189
private void PopulateAuthorDropDownList(object selected = null)
176190
{
177191
var query = _db.Query<Author>().OrderBy(a => a.Lastname);
@@ -182,6 +196,27 @@ private void PopulateCategoryDropDownList(object selected = null)
182196
var query = _db.Query<Category>().OrderBy(a => a.Title);
183197
ViewBag.CategoryID = new SelectList(query, "CategoryID", "Title", selected);
184198
}
199+
200+
private void PopulatePublishersDropDownList(object selected = null)
201+
{
202+
var query = _db.Query<Publisher>().OrderBy(a => a.Name);
203+
ViewBag.PublisherID = new SelectList(query, "PublisherID", "Name", selected);
204+
}
205+
206+
private void PopulateMainSubjectDropDownList(object selected = null)
207+
{
208+
var query = _db.Query<Subject>().OrderBy(a => a.Name);
209+
ViewBag.MainSubjectID = new SelectList(query, "MainSubjectID", "Name", selected);
210+
}
211+
212+
private void PopulateSubjectDropDownList(object selected = null)
213+
{
214+
var query = _db.Query<Subject>().OrderBy(a => a.Name);
215+
ViewBag.SubjectID = new SelectList(query, "SubjectID", "Name", selected);
216+
}
217+
#endregion
218+
219+
185220
// GET: Books/Edit/5
186221
public ActionResult Edit(int? id)
187222
{
@@ -194,6 +229,9 @@ public ActionResult Edit(int? id)
194229
{
195230
return HttpNotFound();
196231
}
232+
PopulateAuthorDropDownList(book.AuthorID);
233+
PopulateCategoryDropDownList(book.CategoryID);
234+
PopulatePublishersDropDownList(book.PublisherID);
197235
return View(book);
198236
}
199237

@@ -202,14 +240,17 @@ public ActionResult Edit(int? id)
202240
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
203241
[HttpPost]
204242
[ValidateAntiForgeryToken]
205-
public ActionResult Edit([Bind(Include = "BookID,Title,AlternativeTitle,CreationDate,InitialPrintedYear,ActualPrintYear,Language,Material,Read,Pages,ISBN,Website,CoverLink")] Book book)
243+
public ActionResult Edit([Bind(Include = "BookID,Title,AlternativeTitle,CreationDate,InitialPrintedYear,ActualPrintYear,Language,Material,Read,Pages,ISBN,Website,CoverLink,Rating,CodeWithinSerie,Condition,ReviewNote,Location")] Book book)
206244
{
207245
if (ModelState.IsValid)
208246
{
209247
_db.Update(book);
210248
_db.SaveChanges();
211249
return RedirectToAction("Index");
212250
}
251+
PopulateAuthorDropDownList(book.AuthorID);
252+
PopulateCategoryDropDownList(book.CategoryID);
253+
PopulatePublishersDropDownList(book.PublisherID);
213254
return View(book);
214255
}
215256

BookCollection/Controllers/CategoriesController.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212

1313
namespace BookCollection.Controllers
1414
{
15-
public class CategoriesController : Controller
15+
public class CategoriesController : BaseController
1616
{
17-
private BookContext db = new BookContext();
18-
1917
// GET: Categories
2018
public ActionResult Index(string sortOrder, string currentFilter, string searchString, int? page, bool noPaging = false)
2119
{
@@ -72,6 +70,24 @@ public ActionResult Details(int? id)
7270
return View(category);
7371
}
7472

73+
public ActionResult DetailsForName(string name)
74+
{
75+
if (string.IsNullOrEmpty(name))
76+
{
77+
return RedirectToAction("Index");
78+
}
79+
Category category = db.Categories.FirstOrDefault(b => b.Title == name);
80+
if (category == null)
81+
{
82+
return HttpNotFound();
83+
}
84+
else
85+
{
86+
category.Books = db.Books.Where(b => b.CategoryID == category.CategoryID).ToList();
87+
}
88+
return View("Details", category);
89+
}
90+
7591
// GET: Categories/Create
7692
public ActionResult Create()
7793
{

BookCollection/Controllers/HomeController.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99
namespace BookCollection.Controllers
1010
{
11-
public class HomeController : Controller
11+
public class HomeController : BaseController
1212
{
13-
private BookContext db = new BookContext();
14-
1513
public ActionResult Index()
1614
{
15+
// http://www.mikesdotnetting.com/article/107/creating-a-tag-cloud-using-asp-net-mvc-and-the-entity-framework
16+
ViewData["TagCloud"] = repo.GetBookCategories();
17+
1718
return View();
1819
}
1920

0 commit comments

Comments
 (0)