Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding AJAX Bid History

  • Loading branch information...
commit 49e289eaebca0ac9cb220779cda98f23e6ce1ce5 1 parent fca29f3
@jchadwick jchadwick authored
View
10 Website/App_Start/Routes.cs → Website/App_Start/Routing.cs
@@ -4,11 +4,11 @@
using CustomExtensions.Routing;
using Ebuy.Website.App_Start;
-[assembly: WebActivator.PostApplicationStartMethod(typeof(Routes), "InitializeRouting")]
+[assembly: WebActivator.PostApplicationStartMethod(typeof(Routing), "InitializeRouting")]
namespace Ebuy.Website.App_Start
{
- public static class Routes
+ public static class Routing
{
public static void InitializeRouting()
{
@@ -21,12 +21,6 @@ public static void RegisterRoutes(RouteCollection routes)
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
- "Auction",
- "Auctions/{title}/{key}",
- new { controller = "Auctions", action = "Auction" }
- );
-
- routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
View
4 Website/Content/Site.css
@@ -640,6 +640,10 @@ ul#social li {
}
+.hidden {
+ display: none;
+}
+
.hint {
color: #D3D3D3;
font-size: 80%;
View
12 Website/Controllers/AuctionsController.cs
@@ -25,6 +25,8 @@ public ActionResult Index(int page = 0, int pageSize = 25)
return View("Auctions", viewModel);
}
+ [Route("auctions/{key}-{title}")]
+ [Route("auctions/{key}")]
public ActionResult Auction(string key)
{
var auction = _repository.Single<Auction>(key);
@@ -36,7 +38,8 @@ public ActionResult Auction(string key)
return View("Auction", viewModel);
}
- [Route("auctions/{title}/{key}/bids")]
+ [Route("auctions/{key}-{title}/bids")]
+ [Route("auctions/{key}/bids")]
public ActionResult Bids(string key)
{
var auction = _repository.Single<Auction>(key);
@@ -49,18 +52,21 @@ public ActionResult Bids(string key)
var viewModel = new BidsViewModel
{
Auction = Mapper.DynamicMap<AuctionViewModel>(auction),
- Bids = bids.Select(x => new BidViewModel()
- {
+ Bids = bids.Select(x => new BidViewModel {
Amount = x.Amount,
Timestamp = x.Timestamp,
UserDisplayName = x.User.DisplayName,
}).ToArray(),
};
+ if (Request.IsAjaxRequest())
+ return PartialView("Bids", viewModel);
+
return View("Bids", viewModel);
}
[Authorize]
+ [Route("auctions/{key}-{title}/bid")]
[Route("auctions/{key}/bid")]
public ActionResult PlaceBid(string key, User user, double amount)
{
View
3  Website/Ebuy.Website.csproj
@@ -128,7 +128,7 @@
<Compile Include="App_Start\NinjectMVC3.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="App_Start\Routes.cs" />
+ <Compile Include="App_Start\Routing.cs" />
<Compile Include="Areas\Admin\AdminAreaRegistration.cs" />
<Compile Include="Areas\Admin\Controllers\UsersController.cs" />
<Compile Include="Areas\Admin\Models\UserViewModel.cs" />
@@ -215,6 +215,7 @@
<Content Include="Content\themes\base\minified\jquery.ui.slider.min.css" />
<Content Include="Content\themes\base\minified\jquery.ui.tabs.min.css" />
<Content Include="Content\themes\base\minified\jquery.ui.theme.min.css" />
+ <Content Include="Scripts\auction.js" />
<Content Include="Scripts\jquery-1.7.1-vsdoc.js" />
<Content Include="Scripts\jquery-1.7.1.js" />
<Content Include="Scripts\jquery-1.7.1.min.js" />
View
4 Website/Extensions/UrlHelperExtensions.cs
@@ -9,12 +9,12 @@ public static class UrlHelperExtensions
public static string Auction(this UrlHelper helper, Auction auction)
{
- return helper.RouteUrl("Auction", new { key = auction.Key, title = auction.Title });
+ return helper.Action("Auction", "Auctions", new { key = auction.Key, title = auction.Title });
}
public static string Auction(this UrlHelper helper, AuctionViewModel auction)
{
- return helper.RouteUrl("Auction", new { key = auction.Key, title = auction.Title });
+ return helper.Action("Auction", "Auctions", new { key = auction.Key, title = auction.Title });
}
}
View
6 Website/Models/BidsViewModel.cs
@@ -11,11 +11,7 @@ public class BidsViewModel
public string Title
{
- get
- {
- return string.Format("Bid history for Auction {0}: {1}",
- Auction.Key, Auction.Title);
- }
+ get { return string.Format("Bid history for {0}", Auction.Title); }
}
}
View
21 Website/Scripts/auction.js
@@ -1,3 +1,22 @@
-require(['jquery'], function() {
+$(function () {
+ $('.show-bid-history').click(function (evt) {
+ $('<div class="bid-history">')
+ .load($(this).attr('href'))
+ .insertAfter(this);
+
+ $('<a href="#">Hide Bid History</a>')
+ .click(function() {
+ $(this).siblings('.bid-history').hide();
+ $(this).siblings('.show-bid-history').show();
+ $(this).remove();
+ return false;
+ })
+ .insertBefore(this);
+
+ $(this).hide();
+
+ evt.stopPropagation();
+ return false;
+ });
});
View
8 Website/Views/Auctions/Auction.cshtml
@@ -13,13 +13,15 @@
<p>
Closing in <span class="time-remaining">@Model.RemainingTimeDisplay</span>
</p>
+ <div>
+ @Html.ActionLink("Bid History", "Bids", "Auctions", new { key = Model.Key }, new { @class = "show-bid-history" })
+ </div>
<p>
<strong>Current Bid: </strong>
<span class="current-bid-amount">@Model.WinningBidPrice</span>
<span class="current-bidder">@Model.WinningBidUsername</span>
-
- @Html.ActionLink("Bid History", "Bids", "Auctions", new { key = Model.Key }, null)
</p>
+
<p>
@using (Html.BeginForm("PlaceBid", "Auctions", new { key = Model.Key }))
{
@@ -36,3 +38,5 @@
<div class="description">
@Model.Description
</div>
+
+<script type="text/javascript" src="@Url.Content("~/scripts/auction.js")"></script>
Please sign in to comment.
Something went wrong with that request. Please try again.