Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion MVC-DataExploration/Controllers/CustomerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,32 @@
using System.Web;
using System.Web.Mvc;
using MVC_DataExploration.Models;

//revision
namespace MVC_DataExploration.Controllers
{
public class CustomerController : Controller
{
private MyDbContext db = new MyDbContext();

//POST
[HttpPost]
// Pass the Create() method a Customer object, called customer
public ActionResult Create(Customer customer)
{

//Use the db.Customers Add() method to add the passed Customer to the model
db.Customers.Add(customer);
//Use the db.SaveChanges() method to update the Database (the first time run, this will create the database too)
db.SaveChanges();
//Send the user back an updated Index page by returning an Index view with the db.Customers model, return View("Index",db.Customers)
return View("Index", db.Customers);
}
//GET
[HttpGet]
public ActionResult Create()
{
return View(db.Customers);
}
// GET: Customer
public ActionResult Index()
{
Expand Down
2 changes: 1 addition & 1 deletion MVC-DataExploration/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Web;
using System.Web.Mvc;

//Revision
namespace MVC_DataExploration.Controllers
{
public class HomeController : Controller
Expand Down
2 changes: 2 additions & 0 deletions MVC-DataExploration/MVC-DataExploration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<UseGlobalApplicationHostFile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<Use64BitIISExpress />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -175,6 +176,7 @@
<Content Include="Views\Home\Contact.cshtml" />
<Content Include="Views\Home\Index.cshtml" />
<Content Include="Views\Customer\Index.cshtml" />
<Content Include="Views\Customer\Create.cshtml" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion MVC-DataExploration/Models/Customer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

//Revision
namespace MVC_DataExploration.Models
{
public class Customer
Expand All @@ -12,11 +12,13 @@ public class Customer
public int CustomerId { get; set; }
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
public string LastName { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
[Display(Name = "Number of Cards")]
public int LoyaltyCardId { get; set; }
public int FamilyCount { get; set; }
}
Expand Down
96 changes: 96 additions & 0 deletions MVC-DataExploration/Views/Customer/Create.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
@model MVC_DataExploration.Models.Customer

@{
ViewBag.Title = "Create";
}

<h2>Create</h2>


@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>Customer</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.Address, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Address, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Address, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.City, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.City, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.City, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.State, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.State, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.State, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.Zip, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Zip, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Zip, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.LoyaltyCardId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.LoyaltyCardId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.LoyaltyCardId, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.FamilyCount, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FamilyCount, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.FamilyCount, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
69 changes: 35 additions & 34 deletions MVC-DataExploration/Views/Customer/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@{
ViewBag.Title = "Index";
}

//Q: errors? couldn't run it
<h2>Index</h2>

<p>
Expand Down Expand Up @@ -38,38 +38,39 @@
<th></th>
</tr>

@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
<td>
@Html.DisplayFor(modelItem => item.City)
</td>
<td>
@Html.DisplayFor(modelItem => item.State)
</td>
<td>
@Html.DisplayFor(modelItem => item.Zip)
</td>
<td>
@Html.DisplayFor(modelItem => item.LoyaltyCardId)
</td>
<td>
@Html.DisplayFor(modelItem => item.FamilyCount)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.CustomerId }) |
@Html.ActionLink("Details", "Details", new { id=item.CustomerId }) |
@Html.ActionLink("Delete", "Delete", new { id=item.CustomerId })
</td>
</tr>
}
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
<td>
@Html.DisplayFor(modelItem => item.City)
</td>
<td>
@Html.DisplayFor(modelItem => item.State)
</td>
<td>
@Html.DisplayFor(modelItem => item.Zip)
</td>
<td>
@Html.DisplayFor(modelItem => item.LoyaltyCardId)
</td>
<td>
@Html.DisplayFor(modelItem => item.FamilyCount)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.CustomerId }) |
@Html.ActionLink("Details", "Details", new { id = item.CustomerId }) |
@Html.ActionLink("Delete", "Delete", new { id = item.CustomerId })
</td>
</tr>
}

</table>