Permalink
Browse files

Adding Bundles... (for jquery validation); Client validation related …

…code
  • Loading branch information...
1 parent c10e10c commit 55995c1cc97b9addb6335209867a991614048291 @mrchief mrchief committed Jul 5, 2012
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Web.Optimization;
+using Ebuy.Website.App_Start;
+
+[assembly: WebActivator.PostApplicationStartMethod(typeof(BundleConfig), "RegisterBundles")]
+
+namespace Ebuy.Website.App_Start
+{
+ public class BundleConfig
+ {
+ public static void RegisterBundles()
+ {
+ var bundles = BundleTable.Bundles;
+ bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
+ "~/Scripts/jquery.validate.min.js",
+ "~/Scripts/jquery.validate.unobtrusive.min.js"
+ ));
+ }
+ }
+}
@@ -24,98 +24,106 @@ public ActionResult Index()
return ActiveAuctionsResult(auctions);
}
- [Route("auctions/{key}-{title}")]
- [Route("auctions/{key}")]
- public ActionResult Auction(string key)
- {
- var auction = _repository.Single<Auction>(key);
+ //[Route("auctions/{key}-{title}")]
+ //[Route("auctions/{key}")]
+ //public ActionResult Auction(string key)
+ //{
+ // var auction = _repository.Single<Auction>(key);
- if (auction == null)
- return View("NotFound");
+ // if (auction == null)
+ // return View("NotFound");
- var viewModel = Mapper.DynamicMap<AuctionViewModel>(auction);
+ // var viewModel = Mapper.DynamicMap<AuctionViewModel>(auction);
- viewModel.SuccessfulBid = TempData["SuccessfulBid"] as BidViewModel;
+ // viewModel.SuccessfulBid = TempData["SuccessfulBid"] as BidViewModel;
- return View("Auction", viewModel);
- }
+ // return View("Auction", viewModel);
+ //}
- [Route("auctions/{key}-{title}/bids")]
- [Route("auctions/{key}/bids")]
- public ActionResult Bids(string key)
- {
- var auction = _repository.Single<Auction>(key);
+ //[Route("auctions/{key}-{title}/bids")]
+ //[Route("auctions/{key}/bids")]
+ //public ActionResult Bids(string key)
+ //{
+ // var auction = _repository.Single<Auction>(key);
- if (auction == null)
- return View("NotFound");
-
- var bids =
- _repository
- .Query<Bid>(x => x.Auction.Key == key, "User", "Auction")
- .OrderByDescending(x => x.Timestamp)
- .ToArray();
-
- var viewModel = new BidsViewModel {
- Auction = Mapper.DynamicMap<AuctionViewModel>(auction),
- 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);
- }
+ // if (auction == null)
+ // return View("NotFound");
- [Authorize]
- [Route("auctions/{key}-{title}/bid")]
- [Route("auctions/{key}/bid")]
- public ActionResult PlaceBid(string key, User user, double amount)
- {
- var auction = _repository.Single<Auction>(key);
+ // var bids =
+ // _repository
+ // .Query<Bid>(x => x.Auction.Key == key, "User", "Auction")
+ // .OrderByDescending(x => x.Timestamp)
+ // .ToArray();
- if (auction == null)
- return View("NotFound");
+ // var viewModel = new BidsViewModel {
+ // Auction = Mapper.DynamicMap<AuctionViewModel>(auction),
+ // Bids = bids.Select(x => new BidViewModel {
+ // Amount = x.Amount,
+ // Timestamp = x.Timestamp,
+ // UserDisplayName = x.User.DisplayName,
+ // }).ToArray(),
+ // };
- var bid = auction.PostBid(user, amount);
+ // if (Request.IsAjaxRequest())
+ // return PartialView("Bids", viewModel);
- TempData["SuccessfulBid"] = Mapper.DynamicMap<BidViewModel>(bid);
+ // return View("Bids", viewModel);
+ //}
- return RedirectToAction("Auction", new { key });
- }
+ //[Authorize]
+ //[Route("auctions/{key}-{title}/bid")]
+ //[Route("auctions/{key}/bid")]
+ //public ActionResult PlaceBid(string key, User user, double amount)
+ //{
+ // var auction = _repository.Single<Auction>(key);
- [Route("featured")]
- public ActionResult FeaturedAuctions()
- {
- var featuredAuctions = _repository.All<Auction>().Active().Featured();
- featuredAuctions = this.ApplyPaging(featuredAuctions, 5);
+ // if (auction == null)
+ // return View("NotFound");
+
+ // var bid = auction.PostBid(user, amount);
+
+ // TempData["SuccessfulBid"] = Mapper.DynamicMap<BidViewModel>(bid);
+
+ // return RedirectToAction("Auction", new { key });
+ //}
- var viewModel = new FeaturedAuctionsViewModel {
- Auctions = featuredAuctions.Select(Mapper.DynamicMap<AuctionViewModel>)
- };
+ //[Route("featured")]
+ //public ActionResult FeaturedAuctions()
+ //{
+ // var featuredAuctions = _repository.All<Auction>().Active().Featured();
+ // featuredAuctions = this.ApplyPaging(featuredAuctions, 5);
- if (Request.IsAjaxRequest() || ControllerContext.IsChildAction)
- return PartialView("FeaturedAuctions", viewModel);
+ // var viewModel = new FeaturedAuctionsViewModel {
+ // Auctions = featuredAuctions.Select(Mapper.DynamicMap<AuctionViewModel>)
+ // };
- return View("FeaturedAuctions", viewModel);
+ // if (Request.IsAjaxRequest() || ControllerContext.IsChildAction)
+ // return PartialView("FeaturedAuctions", viewModel);
+
+ // return View("FeaturedAuctions", viewModel);
- }
+ //}
- [Route("categories/{key}")]
- 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);
- }
+ //[Route("categories/{key}")]
+ //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)
- {
- var viewModel = this.ApplyPaging(auctions.Active()).Select(Mapper.DynamicMap<AuctionViewModel>);
+ private ActionResult ActiveAuctionsResult(IEnumerable<Auction> auctions)
+ {
+ var viewModel = this.ApplyPaging(auctions.Active()).Select(Mapper.DynamicMap<AuctionViewModel>);
- return View("Auctions", viewModel);
- }
+ return View("Auctions", viewModel);
+ }
+
+ [Route("auctions/Create/{auction}")]
+ public ActionResult Create(AuctionViewModel auction)
+ {
+ // TODO: Do something with the data!
+
+ return View(auction);
+ }
}
}
@@ -45,6 +45,9 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Antlr3.Runtime">
+ <HintPath>..\packages\WebGrease.1.0.0\lib\Antlr3.Runtime.dll</HintPath>
+ </Reference>
<Reference Include="AutoMapper">
<HintPath>..\packages\AutoMapper.2.0.0\lib\net40-client\AutoMapper.dll</HintPath>
</Reference>
@@ -69,9 +72,6 @@
<Reference Include="Microsoft.Web.Mvc, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Mvc3Futures.3.0.20105.0\lib\Microsoft.Web.Mvc.dll</HintPath>
</Reference>
- <Reference Include="Microsoft.Web.Optimization">
- <HintPath>..\packages\Microsoft.Web.Optimization.0.1\lib\net40\Microsoft.Web.Optimization.dll</HintPath>
- </Reference>
<Reference Include="MvcContrib, Version=3.0.94.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MvcContrib.Mvc3-ci.3.0.94.0\lib\MvcContrib.dll</HintPath>
</Reference>
@@ -99,6 +99,9 @@
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Mvc.4.0.20505.0\lib\net40\System.Web.Mvc.dll</HintPath>
</Reference>
+ <Reference Include="System.Web.Optimization">
+ <HintPath>..\packages\Microsoft.AspNet.Web.Optimization.1.0.0-beta3\lib\net40\System.Web.Optimization.dll</HintPath>
+ </Reference>
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Razor.2.0.20505.0\lib\net40\System.Web.Razor.dll</HintPath>
@@ -127,10 +130,14 @@
<Reference Include="WebActivator">
<HintPath>..\packages\WebActivator.1.4.4\lib\net40\WebActivator.dll</HintPath>
</Reference>
+ <Reference Include="WebGrease">
+ <HintPath>..\packages\WebGrease.1.0.0\lib\WebGrease.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ActionFilters\CategoriesActionFilter.cs" />
<Compile Include="App_Start\Areas.cs" />
+ <Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\InitializeMembership.cs" />
<Compile Include="App_Start\ModelBinding.cs" />
<Compile Include="App_Start\Filters.cs" />
@@ -294,6 +301,7 @@
<Content Include="Views\Auctions\_AuctionTileMobile.cshtml" />
<Content Include="Views\Auctions\Auctions.iPhone.cshtml" />
<Content Include="Views\Auctions\Auctions.WindowsPhone.cshtml" />
+ <Content Include="Views\Auctions\Create.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\Auctions\Auctions.cshtml" />
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace Ebuy.Website.Models
@@ -11,6 +12,7 @@ public string CurrencyCode
get { return CurrentPrice.Code; }
}
+ [Required]
public string Description { get; set; }
public DateTime? EndTime { get; set; }
@@ -107,6 +109,8 @@ public string RemainingTimeDisplay
public BidViewModel SuccessfulBid { get; set; }
+ [Required]
+ [StringLength(50, ErrorMessage = "Titles cannot be longer than {0} characters")]
public string Title { get; set; }
public Bid WinningBid { get; set; }
@@ -121,5 +125,10 @@ public string WinningBidUsername
return string.Empty;
}
}
+
+ [Range(1, 10000,
+ ErrorMessage = "The auction's starting price must be at least {0}")]
+ public decimal StartPrice { get; set; }
+
}
}
@@ -0,0 +1,40 @@
+@using System.Web.Optimization
+@model Ebuy.Website.Models.AuctionViewModel
+@{
+ ViewBag.Title = "Create";
+}
+
+<h2>Create</h2>
+
+@using (Html.BeginForm())
+{
+ @Html.ValidationSummary()
+
+ <p>
+ @Html.LabelFor(model => model.Title)
+ @Html.EditorFor(model => model.Title)
+ </p>
+ <p>
+ @Html.LabelFor(model => model.Description)
+ @Html.EditorFor(model => model.Description)
+ </p>
+ <p>
+ @Html.LabelFor(model => model.StartPrice)
+ @Html.TextBoxFor(model => model.StartPrice)
+ </p>
+ <p>
+ @Html.LabelFor(model => model.EndTime)
+ @Html.TextBoxFor(model => model.EndTime)
+ </p>
+ <p>
+ <input type="submit" value="Create" />
+ </p>
+}
+
+<div>
+ @Html.ActionLink("Back to List", "Index")
+</div>
+
+@section Scripts {
+ @Scripts.Render("~/bundles/jqueryval")
+}
@@ -48,19 +48,20 @@
@RenderBody()
</section>
</div>
- <footer>
- <div class="content-wrapper">
- <div class="float-left">
- <p>&copy; @DateTime.Now.Year - @SiteName</p>
- </div>
- <div class="float-right">
- <ul id="social">
- <li><a href="http://facebook.com" class="facebook">Facebook</a></li>
- <li><a href="http://twitter.com" class="twitter">Twitter</a></li>
- </ul>
- </div>
- </div>
- @Html.Partial("_ViewSwitcher")
- </footer>
+ <footer>
+ <div class="content-wrapper">
+ <div class="float-left">
+ <p>&copy; @DateTime.Now.Year - @SiteName</p>
+ </div>
+ <div class="float-right">
+ <ul id="social">
+ <li><a href="http://facebook.com" class="facebook">Facebook</a></li>
+ <li><a href="http://twitter.com" class="twitter">Twitter</a></li>
+ </ul>
+ </div>
+ </div>
+ @Html.Partial("_ViewSwitcher")
+ </footer>
+ @RenderSection("Scripts", false)
</body>
</html>
@@ -16,9 +16,9 @@
<package id="knockoutjs" version="1.2.9.0" />
<package id="Microsoft.AspNet.Mvc" version="4.0.20505.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Razor" version="2.0.20505.0" targetFramework="net40" />
+ <package id="Microsoft.AspNet.Web.Optimization" version="1.0.0-beta3" />
<package id="Microsoft.AspNet.WebPages" version="2.0.20505.0" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" />
- <package id="Microsoft.Web.Optimization" version="0.1" />
<package id="Modernizr" version="2.0.6" />
<package id="Mvc3Futures" version="3.0.20105.0" />
<package id="MvcContrib.Mvc3-ci" version="3.0.94.0" />
@@ -27,4 +27,5 @@
<package id="NLog" version="2.0.0.2000" />
<package id="NLog.Config" version="2.0.0.2000" />
<package id="WebActivator" version="1.4.4" />
+ <package id="WebGrease" version="1.0.0" />
</packages>

0 comments on commit 55995c1

Please sign in to comment.