Skip to content

Instantly share code, notes, and snippets.

@Maarten88
Last active December 17, 2015 06:09
Show Gist options
  • Save Maarten88/5563702 to your computer and use it in GitHub Desktop.
Save Maarten88/5563702 to your computer and use it in GitHub Desktop.
Bootstrap compatible ASP.NET MVC4 EditorTemplate for DateAndTime class, using datepicker and timepicker controls
using System;
using System.ComponentModel.DataAnnotations;
using Auction.Web.Domain.Models;
using Auction.Web.Utility;
namespace Auction.Web.Areas.Seller.Models
{
public class AuctionViewModel : Domain.Models.Auction
{
public AuctionViewModel(Domain.Models.Auction auction)
: base(auction)
{
}
public AuctionViewModel()
{
// default values for new form
var now = DateTime.UtcNow;
this.Start = (now + TimeSpan.FromDays(1)).RoundDown(15);
this.End = (now + TimeSpan.FromDays(2)).RoundDown(15);
this.OpeningTime = new TimeSpan(8, 0, 0);
this.ClosingTime = new TimeSpan(22, 0, 0);
this.OpenOnSaturdays = true;
this.OpenOnSundays = false;
this.State = AuctionState.Planned;
this.Type = AuctionType.ExitAuction;
}
[Required]
[Display(Name = "Start datum en tijd")]
public DateAndTime StartDateAndTime
{
get
{
//return new DateAndTime((DateTime)this.Start);
return new DateAndTime((DateTime)this.Start.ToLocalAuctionTime());
}
set
{
this.Start = value.DateTime;
}
}
[Required]
[Display(Name = "Eind datum en tijd")]
public DateAndTime EndDateAndTime
{
get
{
//return new DateAndTime((DateTime)this.End);
return new DateAndTime((DateTime)this.End.Value.ToLocalAuctionTime());
}
set
{
this.End = value.DateTime;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment