Permalink
Browse files

Streamlining code with the book snippets

  • Loading branch information...
1 parent 0c8e441 commit 81e6e80019e636d0a345daae836e42155eaca151 @mrchief mrchief committed Apr 12, 2013
@@ -11,6 +11,7 @@ public class EbuyDataContext : DbContext
public EbuyDataContext()
{
+ Configuration.ProxyCreationEnabled = false;
#if(DEBUG)
Database.SetInitializer(new EbuyInitializer());
#endif
@@ -1,19 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using AutoMapper;
-using Ebuy.Website.Models;
-
-namespace Ebuy.Website.App_Start
-{
- public class AutoMapperConfig
- {
- public static void RegisterMappings()
- {
- Mapper.CreateMap<Auction, AuctionViewModel>();
-
- Mapper.AssertConfigurationIsValid();
- }
- }
-}
@@ -15,7 +15,7 @@ public ActionResult Index(int page = 0, int size = 25)
{
var db = new EbuyDataContext();
var auctions = db.Auctions.OrderByDescending(x => x.EndTime).Skip(page * 25).Take(size);
- return View("Auctions", Mapper.Map<IEnumerable<AuctionViewModel>>(auctions).ToArray());
+ return View("Auctions", auctions.ToArray());
}
[MultipleResponseFormats]
@@ -43,7 +43,7 @@ public ActionResult JsonAuction(string id)
{
var db = new EbuyDataContext();
var auction = db.Auctions.FirstOrDefault(x => x.Key == id);
- return Json(Mapper.Map<AuctionViewModel>(auction), JsonRequestBehavior.AllowGet);
+ return Json(auction, JsonRequestBehavior.AllowGet);
}
public ActionResult PartialAuction(string id)
@@ -177,7 +177,6 @@
<Compile Include="Api\AuctionsDataController.cs" />
<Compile Include="Api\CustomExceptionFilter.cs" />
<Compile Include="App_Start\AuthConfig.cs" />
- <Compile Include="App_Start\AutoMapperConfig.cs" />
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\NinjectWebCommon.cs" />
@@ -187,8 +186,6 @@
<Compile Include="Controllers\AuctionsController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\SearchController.cs" />
- <Compile Include="Models\AuctionViewModel.cs" />
- <Compile Include="Models\BidViewModel.cs" />
<Compile Include="Models\SearchViewModel.cs" />
<Compile Include="Filters\InitializeSimpleMembershipAttribute.cs" />
<Compile Include="Global.asax.cs">
@@ -1,12 +1,7 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Web.Http;
+using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
-using Ebuy.Website.App_Start;
namespace Ebuy.Website
{
@@ -24,8 +19,6 @@ protected void Application_Start()
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
-
- AutoMapperConfig.RegisterMappings();
}
}
}
@@ -1,107 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Ebuy.Util;
-
-namespace Ebuy.Website.Models
-{
- public class AuctionViewModel
- {
-
- public string Description { get; set; }
-
- public DateTime? EndTime { get; set; }
-
- /// <summary>
- /// Closing Date in mm/dd/yyyy format
- /// </summary>
- /// <example>18th Oct, 2012 at 5:00 PM</example>
- public string EndTimeDisplay
- {
- get
- {
- if (EndTime == null)
- return string.Empty;
-
-
- return EndTime.Value.ToString("MMM d, yyyy 'at' h:mm tt 'GMT'");
- }
- }
-
- public bool HasWinningBid
- {
- get { return WinningBid != null; }
- }
-
- public WebsiteImage Image
- {
- get
- {
- var images = Images ?? Enumerable.Empty<WebsiteImage>();
- return images.FirstOrDefault();
- }
- }
-
- public IEnumerable<WebsiteImage> Images { get; set; }
-
- public string Key { get; set; }
-
-
- /// <summary>
- /// Display Representation in days, hours, minutes
- /// </summary>
- /// <example>05d:12h:30m</example>
- public string RemainingTimeDisplay
- {
- get
- {
- if (EndTime == null)
- return "N/A";
-
-
- var time = EndTime.Value.Subtract(Clock.Now);
-
-
- if (time.Days > 0)
- return string.Format("{0} days, {1} hours",
- time.Days, time.Hours);
-
-
- if (time.Hours > 0)
- return string.Format("{0} hours, {1} minutes",
- time.Hours, time.Minutes);
-
-
- if (time.Minutes > 0)
- return string.Format("{0} minutes, {1} seconds",
- time.Minutes, time.Seconds);
-
-
- if (time.Seconds > 0)
- return string.Format("{0} seconds", time.Seconds);
-
-
- return "Closed";
- }
- }
-
- public string CurrentPrice { get; set; }
-
- public string Title { get; set; }
-
- public Bid WinningBid { get; set; }
-
- public string WinningBidUsername
- {
- get
- {
- if (HasWinningBid && WinningBid.User != null)
- return WinningBid.User.DisplayName;
-
-
- return string.Empty;
- }
- }
- }
-
-}
@@ -1,36 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-
-namespace Ebuy.Website.Models
-{
- public class BidsViewModel
- {
- public AuctionViewModel Auction { get; set; }
-
- public IEnumerable<BidViewModel> Bids { get; set; }
-
-
- public string Title
- {
- get { return Auction.Title; }
- }
- }
-
-
- public class BidViewModel
- {
- public string Amount { get; set; }
-
- public DateTime Timestamp { get; set; }
-
- public string TimestampDisplay
- {
- get { return Timestamp.ToString("G"); }
- }
-
- public string UserDisplayName { get; set; }
- }
-
-}
@@ -2,19 +2,34 @@
namespace Ebuy.Website.Models
{
- public class SearchViewModel
- {
- public string SearchKeyword { get; set; }
+ public class SearchViewModel
+ {
+ public string SearchKeyword { get; set; }
- public int CurrentPage { get; set; }
- public int MaxPages { get; set; }
+ public int CurrentPage { get; set; }
+ public int MaxPages { get; set; }
- public int PagingSize { get; set; }
- public IEnumerable<int> PagingSizeList { get; set; }
+ public int PagingSize { get; set; }
+ public IEnumerable<int> PagingSizeList { get; set; }
- public string SortByField { get; set; }
- public IEnumerable<string> SortByFieldList { get; set; }
+ public string SortByField { get; set; }
+ public IEnumerable<string> SortByFieldList { get; set; }
- public IEnumerable<AuctionViewModel> SearchResult { get; set; }
- }
+ public IEnumerable<AuctionViewModel> SearchResult { get; set; }
+ }
+
+ public class AuctionViewModel
+ {
+ public string Image { get; set; }
+
+ public long Id { get; set; }
+
+ public string Title { get; set; }
+
+ public string Description { get; set; }
+
+ public string CurrentPrice { get; set; }
+
+ public string RemainingTimeDisplay { get; set; }
+ }
}
@@ -1,10 +1,10 @@
-@model AuctionViewModel
+@model Ebuy.Auction
<div class="title">@Model.Title</div>
<div class="overview">
<p>
<strong>Current Price: </strong>
-<span class="current-price">@Model.CurrentPrice</span>
+<span class="current-price">@Model.CurrentPrice.Code @Model.CurrentPrice.Value</span>
</p>
</div>
<h3>Description</h3>
@@ -1,4 +1,4 @@
-@model IEnumerable<AuctionViewModel>
+@model IEnumerable<Ebuy.Auction>
<h2>Auctions</h2>
<ul class="auctions">
@@ -30,7 +30,7 @@
<div class="overview">
<p>
<strong>Current Price: </strong>
-<span class="current-bid">{{CurrentPrice}}</span>
+<span class="current-bid">{{CurrentPrice.Code}} {{CurrentPrice.Value}}</span>
</p>
</div>
<h3>Description</h3>

0 comments on commit 81e6e80

Please sign in to comment.