Permalink
Browse files

Tweaking views

  • Loading branch information...
1 parent d3a0731 commit 169f117d87530027051bc7efd5e4f084742b8d6f @jchadwick jchadwick committed Dec 21, 2011
View
@@ -5,7 +5,7 @@ namespace Ebuy
{
public class Bid : IEquatable<Bid>
{
- public virtual Guid Id
+ public Guid Id
{
get
{
@@ -18,22 +18,22 @@ public virtual Guid Id
}
private Guid? _id;
- public virtual Auction Auction { get; private set; }
+ public Auction Auction { get; private set; }
- public virtual bool IsWinningBid
+ public bool IsWinningBid
{
get
{
return Auction != null
- && this == Auction.WinningBid;
+ && this == Auction.WinningBid;
}
}
- public virtual Currency Price { get; private set; }
+ public Currency Price { get; private set; }
- public virtual DateTime Timestamp { get; private set; }
+ public DateTime Timestamp { get; private set; }
- public virtual User User { get; private set; }
+ public User User { get; private set; }
public Bid(User user, Auction auction, Currency price)
@@ -20,10 +20,6 @@ public class Currency : IEquatable<Currency>
public decimal Amount { get; private set; }
- private Currency()
- {
- }
-
public Currency(string code, decimal amount)
{
Code = code;
@@ -39,6 +35,10 @@ public Currency(string currency)
Amount = decimal.Parse(currency.Substring(1));
}
+ private Currency()
+ {
+ }
+
public bool Equals(Currency other)
{
@@ -8,13 +8,21 @@ public class WebsiteImage
{
public virtual Guid Id
{
- get { return _id ?? Guid.NewGuid(); }
- set { _id = value; }
+ get
+ {
+ if (_id == null)
+ _id = Guid.NewGuid();
+
+ return _id.Value;
+ }
+ private set { _id = value; }
}
private Guid? _id;
public virtual string ImageUrl { get; set; }
+ public virtual string Title { get; set; }
+
public virtual string ThumbnailUrl { get; set; }
@@ -147,7 +147,11 @@ protected override void Seed(DataContext context)
foreach (var product in context.Products.Local)
{
- var startTime = new DateTime(2011, rand.Next(1, 12), rand.Next(1, 28), rand.Next(0, 24), rand.Next(0, 60), 0);
+ var startTime =
+ DateTime.UtcNow
+ .AddDays(rand.Next(-2, 4))
+ .AddHours(rand.Next(1, 24))
+ .AddHours(rand.Next(1, 60));
var auction = new Auction()
{
@@ -132,6 +132,8 @@
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\AuctionsController.cs" />
<Compile Include="Controllers\ViewSwitcherController.cs" />
+ <Compile Include="Extensions\HtmlHelperExtensions.cs" />
+ <Compile Include="Extensions\UrlHelperExtensions.cs" />
<Compile Include="Models\AccountModels.cs" />
<Compile Include="Models\AuctionModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -289,7 +291,7 @@
<Content Include="Views\Auctions\Auctions.mobile.cshtml" />
</ItemGroup>
<ItemGroup>
- <Content Include="Views\Auctions\_Auction.cshtml" />
+ <Content Include="Views\Auctions\_AuctionTile.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
@@ -0,0 +1,55 @@
+using System.Web;
+using System.Web.Mvc;
+
+namespace Ebuy.Website.Extensions
+{
+
+ public static class HtmlHelperExtensions
+ {
+
+ public static IHtmlString Image<T>(this HtmlHelper<T> helper, WebsiteImage image, string title = null)
+ {
+ var img = new TagBuilder("img");
+ img.Attributes.Add("src", helper.RelativeUrl(image.ImageUrl));
+ ApplyTitle(img, image, title);
+
+ return new HtmlString(img.ToString(TagRenderMode.SelfClosing));
+ }
+
+ public static IHtmlString Thumbnail<T>(this HtmlHelper<T> helper, WebsiteImage image, string title = null)
+ {
+ var img = new TagBuilder("img");
+ img.AddCssClass("thumbnail");
+ img.Attributes.Add("data-image", image.ImageUrl);
+ ApplyTitle(img, image, title);
+
+ if(string.IsNullOrWhiteSpace(image.ThumbnailUrl))
+ {
+ img.Attributes.Add("src", helper.RelativeUrl(image.ImageUrl));
+ img.Attributes.Add("width", "140px");
+ img.Attributes.Add("height", "140px");
+ }
+ else
+ {
+ img.Attributes.Add("src", helper.RelativeUrl(image.ThumbnailUrl));
+ }
+
+ return new HtmlString(img.ToString(TagRenderMode.SelfClosing));
+ }
+
+
+ private static string RelativeUrl(this HtmlHelper helper, string url)
+ {
+ return new UrlHelper(helper.ViewContext.RequestContext).Content(url);
+ }
+
+ private static void ApplyTitle(TagBuilder img, WebsiteImage image, string title)
+ {
+ var alt = title ?? image.Title;
+
+ if (!string.IsNullOrWhiteSpace(alt))
+ img.Attributes.Add("alt", alt);
+ }
+ }
+
+}
@@ -0,0 +1,22 @@
+using System.Web.Mvc;
+using Ebuy.Website.Models;
+
+namespace Ebuy.Website.Extensions
+{
+
+ public static class UrlHelperExtensions
+ {
+
+ public static string Auction(this UrlHelper helper, Auction auction)
+ {
+ return helper.RouteUrl("Auction", new { id = auction.Key, title = auction.Title });
+ }
+
+ public static string Auction(this UrlHelper helper, AuctionViewModel auction)
+ {
+ return helper.RouteUrl("Auction", new { id = auction.Key, title = auction.Title });
+ }
+
+ }
+
+}
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Linq;
namespace Ebuy.Website.Models
{
@@ -16,38 +17,93 @@ public class AuctionViewModel
public string ProductKey { get; set; }
public string ProductName { get; set; }
- public string WinningBidUserDisplayName { get; set; }
- public Currency WinningBidPrice { get; set; }
+ public Bid WinningBid { get; set; }
+
+ public bool HasWinningBid
+ {
+ get { return WinningBid != null; }
+ }
+
+ public string WinningBidUsername
+ {
+ get
+ {
+ if (HasWinningBid)
+ return WinningBid.User.DisplayName;
+
+ return string.Empty;
+ }
+ }
+
+ public Currency WinningBidPrice
+ {
+ get
+ {
+ if (HasWinningBid)
+ return WinningBid.Price;
+
+ return null;
+ }
+ }
+
+ public WebsiteImage Image
+ {
+ get
+ {
+ var images = Images ?? Enumerable.Empty<WebsiteImage>();
+ return images.FirstOrDefault();
+ }
+ }
public IEnumerable<WebsiteImage> Images { get; set; }
/// <summary>
- /// Friendly Representation in days, hours, minutes
+ /// Display Representation in days, hours, minutes
/// </summary>
/// <example>05d:12h:30m</example>
- public string ClosingIn
+ public string RemainingTimeDisplay
{
get
{
if (EndTime == null)
- return "Unknown";
+ return "N/A";
+
+ var time = EndTime.Value.Subtract(DateTime.UtcNow);
+
+ 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);
- var span = EndTime.Value.Subtract(DateTime.Now);
+ if (time.Seconds > 0)
+ return string.Format("{0} seconds", time.Seconds);
- return span.ToString();
+ return "Closed";
}
}
+ public DateTime? EndTime { get; set; }
+
/// <summary>
/// Closing Date in mm/dd/yyyy format
/// </summary>
/// <example>18th Oct, 2012 at 5:00 PM</example>
- public DateTime? EndTime { get; set; }
-
public string EndTimeDisplay
{
- get;
- set;
+ get
+ {
+ if (EndTime == null)
+ return string.Empty;
+
+ return EndTime.Value.ToString("MMM d, yyyy 'at' h:mm tt 'GMT'");
+ }
}
public string Key { get; set; }
@@ -1,10 +1,29 @@
-@model Ebuy.Website.Models.AuctionViewModel
+@model AuctionViewModel
@{
ViewBag.Title = Model.Title;
}
<h2>@ViewBag.Title</h2>
-<div>
- <img src="@Url.Content(Model.Images.First().ImageUrl)"/>
-</div>
+<div class="overview">
+ <div class="product-image">
+ @Html.Image(Model.Image, Model.Title)
+ </div>
+
+ <p>
+ Closing in <span class="time-remaining">@Model.RemainingTimeDisplay</span>
+ </p>
+ <p>
+ <strong>Current Bid: </strong>
+ <span class="current-bid-amount">@Model.WinningBidPrice</span>
+ <span class="current-bidder">@Model.WinningBidUsername</span>
+ </p>
+ <p>
+ <span><a href="StartNewAuction()">Bid Now</a></span>
+ </p>
+</div>
+
+<h3>Description</h3>
+<div class="description">
+ @Model.Description
+</div>
@@ -16,7 +16,7 @@
@foreach (var auction in Model.Auctions)
{
<li class="listitem">
- @Html.Partial("_Auction", auction)
+ @Html.Partial("_AuctionTile", auction)
</li>
}
</ul>
@@ -16,7 +16,7 @@
@foreach (var auction in Model.Auctions)
{
<li class="listitem">
- @Html.Partial("_Auction", auction);
+ @Html.Partial("_AuctionTile", auction);
</li>
}
</ul>
@@ -1,21 +0,0 @@
-@model Ebuy.Website.Models.AuctionViewModel
-@{
- var auctionUrl = Url.RouteUrl("Auction", new { id = Model.Key, title = Model.Title });
-}
-<div>
- <div class="thumbnail">
- <a href="@auctionUrl">
- <img src="@Url.Content(Model.Images.First().ImageUrl)" alt="@Model.Title"/>
- </a>
- </div>
- <div class="data">
- <h4 class="title"><a href="@auctionUrl">@Model.Title</a></h4>
- <span class="">Auction closing in <span class="closingTime">00d:5h:45m</span></span>
- <br />
- <span><strong>Current Bid: </strong>$30.14
- <br />
- user1394 </span>
- <br />
- <span><a href="StartNewAuction()">Bid Now</a></span>
- </div>
-</div>
Oops, something went wrong.

0 comments on commit 169f117

Please sign in to comment.