diff --git a/Ebuy.Website/App_Data/Ebuy.Website.Models.EbuyDataContext.mdf b/Ebuy.Website/App_Data/Ebuy.Website.Models.EbuyDataContext.mdf new file mode 100644 index 0000000..0d79c1a Binary files /dev/null and b/Ebuy.Website/App_Data/Ebuy.Website.Models.EbuyDataContext.mdf differ diff --git a/Ebuy.Website/App_Data/Ebuy.Website.Models.EbuyDataContext_log.ldf b/Ebuy.Website/App_Data/Ebuy.Website.Models.EbuyDataContext_log.ldf new file mode 100644 index 0000000..5512605 Binary files /dev/null and b/Ebuy.Website/App_Data/Ebuy.Website.Models.EbuyDataContext_log.ldf differ diff --git a/Ebuy.Website/Controllers/AuctionsController.cs b/Ebuy.Website/Controllers/AuctionsController.cs index 70f12d7..305e39f 100644 --- a/Ebuy.Website/Controllers/AuctionsController.cs +++ b/Ebuy.Website/Controllers/AuctionsController.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; using System.Web.Mvc; +using Ebuy.Website.Models; namespace Ebuy.Website.Controllers { @@ -28,15 +26,16 @@ public ActionResult Details(long id = 0) Description = "This is a brand new version 2.0 Widget!", StartPrice = 1.00m, CurrentPrice = 13.40m, - StartTime = DateTime.Parse("6-15-2012 12:34 PM"), EndTime = DateTime.Parse("6-23-2012 12:34 PM"), }; return View(auction); } + // // GET: /Auctions/Create + [HttpGet] public ActionResult Create() { return View(); @@ -46,18 +45,18 @@ public ActionResult Create() // POST: /Auctions/Create [HttpPost] - public ActionResult Create(FormCollection collection) + public ActionResult Create(Auction auction) { - try + if (ModelState.IsValid) { - // TODO: Add insert logic here + var db = new EbuyDataContext(); + db.Auctions.Add(auction); + db.SaveChanges(); - return RedirectToAction("Index"); - } - catch - { - return View(); + return RedirectToAction("Details", new { id = auction.Id }); } + + return View(auction); } // diff --git a/Ebuy.Website/Ebuy.Website.csproj b/Ebuy.Website/Ebuy.Website.csproj index 9391fbe..554ba21 100644 --- a/Ebuy.Website/Ebuy.Website.csproj +++ b/Ebuy.Website/Ebuy.Website.csproj @@ -284,6 +284,7 @@ + diff --git a/Ebuy.Website/Models/Auction.cs b/Ebuy.Website/Models/Auction.cs index d1c59f4..c7fe5dd 100644 --- a/Ebuy.Website/Models/Auction.cs +++ b/Ebuy.Website/Models/Auction.cs @@ -1,15 +1,38 @@ using System; +using System.ComponentModel.DataAnnotations; namespace Ebuy.Website.Models { + using System.Data.Entity; + + public class EbuyDataContext : DbContext + { + public DbSet Auctions { get; set; } + + public EbuyDataContext() + { + Database.SetInitializer(new DropCreateDatabaseIfModelChanges()); + } + } + public class Auction { public long Id { get; set; } + + [Required] + [StringLength(50, + ErrorMessage = "Title cannot be longer than 50 characters")] public string Title { get; set; } + + [Required] public string Description { get; set; } + + [Range(1, 10000, + ErrorMessage = "The auction's starting price must be at least 1")] public decimal StartPrice { get; set; } + public decimal CurrentPrice { get; set; } - public DateTime StartTime { get; set; } + public DateTime EndTime { get; set; } } } \ No newline at end of file diff --git a/Ebuy.Website/Views/Auctions/Create.cshtml b/Ebuy.Website/Views/Auctions/Create.cshtml new file mode 100644 index 0000000..bbf6410 --- /dev/null +++ b/Ebuy.Website/Views/Auctions/Create.cshtml @@ -0,0 +1,32 @@ +@model Ebuy.Website.Models.Auction + +

Create Auction

+ +@using (Html.BeginForm()) +{ + @Html.ValidationSummary() + +

+ @Html.LabelFor(model => model.Title) + @Html.EditorFor(model => model.Title) + @Html.ValidationMessageFor(model => model.Title, "*") +

+

+ @Html.LabelFor(model => model.Description) + @Html.EditorFor(model => model.Description) + @Html.ValidationMessageFor(model => model.Description, "*") +

+

+ @Html.LabelFor(model => model.StartPrice) + @Html.EditorFor(model => model.StartPrice) + @Html.ValidationMessageFor(model => model.StartPrice) +

+

+ @Html.LabelFor(model => model.EndTime) + @Html.EditorFor(model => model.EndTime) + @Html.ValidationMessageFor(model => model.EndTime) +

+

+ +

+} \ No newline at end of file diff --git a/Ebuy.Website/Views/Auctions/Details.cshtml b/Ebuy.Website/Views/Auctions/Details.cshtml index d5532b2..45a6270 100644 --- a/Ebuy.Website/Views/Auctions/Details.cshtml +++ b/Ebuy.Website/Views/Auctions/Details.cshtml @@ -37,13 +37,6 @@ @Html.DisplayFor(model => model.CurrentPrice) -
- @Html.DisplayNameFor(model => model.StartTime) -
-
- @Html.DisplayFor(model => model.StartTime) -
-
@Html.DisplayNameFor(model => model.EndTime)