Skip to content
Browse files

Implementing Categories

  • Loading branch information...
1 parent a6fb67a commit 9239429a97ee8c7e80ad9131fd965bd461338f48 @jchadwick jchadwick committed Jan 13, 2012
View
23 Website/Controllers/AuctionsController.cs
@@ -1,4 +1,4 @@
-using System;
+using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using AutoMapper;
@@ -18,13 +18,10 @@ public AuctionsController(IRepository repository)
}
[Route("auctions")]
- public ActionResult Index(int page = 0, int pageSize = 25)
+ public ActionResult Index()
{
- var auctions = this.ApplyPaging(_repository.All<Auction>().Active());
-
- var viewModel = auctions.Select(Mapper.DynamicMap<AuctionViewModel>);
-
- return View("Auctions", viewModel);
+ var auctions = _repository.All<Auction>();
+ return ActiveAuctionsResult(auctions);
}
[Route("auctions/{key}-{title}")]
@@ -108,9 +105,17 @@ public ActionResult FeaturedAuctions()
}
[Route("categories/{key}")]
- public ActionResult Category(string key, int pageIndex, int pageSize)
+ public ActionResult Category(string key, int pageIndex = 0, int pageSize = 25)
+ {
+ var auctions = _repository.Query<Auction>(x => x.Categories.Any(cat => cat.Key == key));
+ return ActiveAuctionsResult(auctions);
+ }
+
+ private ActionResult ActiveAuctionsResult(IEnumerable<Auction> auctions)
{
- throw new NotImplementedException();
+ var viewModel = this.ApplyPaging(auctions.Active()).Select(Mapper.DynamicMap<AuctionViewModel>);
+
+ return View("Auctions", viewModel);
}
}
}
View
1 Website/Ebuy.Website.csproj
@@ -128,6 +128,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="App_Start\Areas.cs" />
+ <Compile Include="App_Start\InitializeMembership.cs" />
<Compile Include="App_Start\ModelBinding.cs" />
<Compile Include="App_Start\Filters.cs" />
<Compile Include="App_Start\DataAccess.cs" />
View
2 Website/Models/CategoryViewModel.cs
@@ -5,6 +5,8 @@ public class CategoryViewModel
public string Key { get; set; }
public string Name { get; set; }
+
+ public int AuctionsCount { get; set; }
}
}
View
3 Website/Views/Auctions/_AuctionTile.cshtml
@@ -17,8 +17,5 @@
<span class="current-bid-amount">@Model.CurrentPrice</span>
<span class="current-bidder">@Model.WinningBidUsername</span>
</p>
- <p>
- <span><a href="StartNewAuction()">Bid Now</a></span>
- </p>
</div>
</div>
View
2 Website/Views/Home/Homepage.cshtml
@@ -46,7 +46,7 @@
<ul id="categories" class="content-wrapper">
@foreach (var category in Model.Categories)
{
- <li class="category"><a href="@Url.Category(category)">@category.Name</a></li>
+ <li class="category"><a href="@Url.Category(category)">@category.Name</a> (@category.AuctionsCount)</li>
}
</ul>
</div>

0 comments on commit 9239429

Please sign in to comment.
Something went wrong with that request. Please try again.