Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
relyky committed Apr 19, 2019
1 parent fecb38e commit 445aa85
Show file tree
Hide file tree
Showing 17 changed files with 757 additions and 4 deletions.
Binary file modified mvcReduxLab/App_Data/MyDatabase.mdf
Binary file not shown.
Binary file modified mvcReduxLab/App_Data/MyDatabase_log.ldf
Binary file not shown.
89 changes: 89 additions & 0 deletions mvcReduxLab/Areas/MVCLab/Controllers/TestMController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace mvcReduxLab.Areas.MVCLab.Controllers
{
public class TestMController : Controller
{
// GET: MVCLab/TestM
public ActionResult Index()
{
return View();
}

// GET: MVCLab/TestM/Details/5
public ActionResult Details(int id)
{
return View();
}

// GET: MVCLab/TestM/Create
public ActionResult Create()
{
return View();
}

// POST: MVCLab/TestM/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here

return RedirectToAction("Index");
}
catch
{
return View();
}
}

// GET: MVCLab/TestM/Edit/5
public ActionResult Edit(int id)
{
return View();
}

// POST: MVCLab/TestM/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here

return RedirectToAction("Index");
}
catch
{
return View();
}
}

// GET: MVCLab/TestM/Delete/5
public ActionResult Delete(int id)
{
return View();
}

// POST: MVCLab/TestM/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here

return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
127 changes: 127 additions & 0 deletions mvcReduxLab/Areas/MVCLab/Controllers/TestVMController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using mvcReduxLab;

namespace mvcReduxLab.Areas.MVCLab.Controllers
{
public class TestVMController : Controller
{
private MyDatabaseEntities db = new MyDatabaseEntities();

// GET: MVCLab/TestVM
public ActionResult Index()
{
return View(db.Account.ToList());
}

// GET: MVCLab/TestVM/Details/5
public ActionResult Details(string id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Account account = db.Account.Find(id);
if (account == null)
{
return HttpNotFound();
}
return View(account);
}

// GET: MVCLab/TestVM/Create
public ActionResult Create()
{
return View();
}

// POST: MVCLab/TestVM/Create
// 若要免於過量張貼攻擊,請啟用想要繫結的特定屬性,如需
// 詳細資訊,請參閱 https://go.microsoft.com/fwlink/?LinkId=317598。
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "name,email,mobilePhone,birthday,contactTime,remark")] Account account)
{
if (ModelState.IsValid)
{
db.Account.Add(account);
db.SaveChanges();
return RedirectToAction("Index");
}

return View(account);
}

// GET: MVCLab/TestVM/Edit/5
public ActionResult Edit(string id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Account account = db.Account.Find(id);
if (account == null)
{
return HttpNotFound();
}
return View(account);
}

// POST: MVCLab/TestVM/Edit/5
// 若要免於過量張貼攻擊,請啟用想要繫結的特定屬性,如需
// 詳細資訊,請參閱 https://go.microsoft.com/fwlink/?LinkId=317598。
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "name,email,mobilePhone,birthday,contactTime,remark")] Account account)
{
if (ModelState.IsValid)
{
db.Entry(account).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(account);
}

// GET: MVCLab/TestVM/Delete/5
public ActionResult Delete(string id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Account account = db.Account.Find(id);
if (account == null)
{
return HttpNotFound();
}
return View(account);
}

// POST: MVCLab/TestVM/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(string id)
{
Account account = db.Account.Find(id);
db.Account.Remove(account);
db.SaveChanges();
return RedirectToAction("Index");
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
75 changes: 75 additions & 0 deletions mvcReduxLab/Areas/MVCLab/Views/TestVM/Create.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@model mvcReduxLab.Account

@{
ViewBag.Title = "Create";
}

<h2>Create</h2>

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

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

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

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

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

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

<div class="form-group">
@Html.LabelFor(model => model.remark, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.remark, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.remark, "", 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>
64 changes: 64 additions & 0 deletions mvcReduxLab/Areas/MVCLab/Views/TestVM/Delete.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@model mvcReduxLab.Account

@{
ViewBag.Title = "Delete";
}

<h2>Delete</h2>

<h3>Are you sure you want to delete this?</h3>
<div>
<h4>Account</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.email)
</dt>

<dd>
@Html.DisplayFor(model => model.email)
</dd>

<dt>
@Html.DisplayNameFor(model => model.mobilePhone)
</dt>

<dd>
@Html.DisplayFor(model => model.mobilePhone)
</dd>

<dt>
@Html.DisplayNameFor(model => model.birthday)
</dt>

<dd>
@Html.DisplayFor(model => model.birthday)
</dd>

<dt>
@Html.DisplayNameFor(model => model.contactTime)
</dt>

<dd>
@Html.DisplayFor(model => model.contactTime)
</dd>

<dt>
@Html.DisplayNameFor(model => model.remark)
</dt>

<dd>
@Html.DisplayFor(model => model.remark)
</dd>

</dl>

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

<div class="form-actions no-color">
<input type="submit" value="Delete" class="btn btn-default" /> |
@Html.ActionLink("Back to List", "Index")
</div>
}
</div>
Loading

0 comments on commit 445aa85

Please sign in to comment.