Skip to content

Commit

Permalink
Redesign Cat Details Edit page
Browse files Browse the repository at this point in the history
  • Loading branch information
Victoria-Rhine committed Dec 20, 2019
1 parent a245fd9 commit f6e1876
Show file tree
Hide file tree
Showing 9 changed files with 459 additions and 29 deletions.
2 changes: 1 addition & 1 deletion TheCatProject/Content/Site.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ a:link {

/* visited link */
a:visited {
color: azure;
color: #E7717D;
}

/* mouse over link */
Expand Down
145 changes: 145 additions & 0 deletions TheCatProject/Controllers/PTagsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
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 TheCatProject.DAL;
using TheCatProject.Models;

namespace TheCatProject.Controllers
{
public class PTagsController : Controller
{
private CatsContext db = new CatsContext();

// GET: PTags
public ActionResult Index()
{
var pTags = db.PTags.Include(p => p.Cat).Include(p => p.Personality).Include(p => p.Personality1).Include(p => p.Personality2);
return View(pTags.ToList());
}

// GET: PTags/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
PTag pTag = db.PTags.Find(id);
if (pTag == null)
{
return HttpNotFound();
}
return View(pTag);
}

// GET: PTags/Create
public ActionResult Create()
{
ViewBag.CID = new SelectList(db.Cats, "ID", "Name");
ViewBag.FirstTrait = new SelectList(db.Personalities, "ID", "Type");
ViewBag.SecondTrait = new SelectList(db.Personalities, "ID", "Type");
ViewBag.ThirdTrait = new SelectList(db.Personalities, "ID", "Type");
return View();
}

// POST: PTags/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ID,CID,FirstTrait,SecondTrait,ThirdTrait")] PTag pTag)
{
if (ModelState.IsValid)
{
db.PTags.Add(pTag);
db.SaveChanges();
return RedirectToAction("Index");
}

ViewBag.CID = new SelectList(db.Cats, "ID", "Name", pTag.CID);
ViewBag.FirstTrait = new SelectList(db.Personalities, "ID", "Type", pTag.FirstTrait);
ViewBag.SecondTrait = new SelectList(db.Personalities, "ID", "Type", pTag.SecondTrait);
ViewBag.ThirdTrait = new SelectList(db.Personalities, "ID", "Type", pTag.ThirdTrait);
return View(pTag);
}

// GET: PTags/Edit/5
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
PTag pTag = db.PTags.Find(id);
if (pTag == null)
{
return HttpNotFound();
}
ViewBag.CID = new SelectList(db.Cats, "ID", "Name", pTag.CID);
ViewBag.FirstTrait = new SelectList(db.Personalities, "ID", "Type", pTag.FirstTrait);
ViewBag.SecondTrait = new SelectList(db.Personalities, "ID", "Type", pTag.SecondTrait);
ViewBag.ThirdTrait = new SelectList(db.Personalities, "ID", "Type", pTag.ThirdTrait);
return View(pTag);
}

// POST: PTags/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "ID,CID,FirstTrait,SecondTrait,ThirdTrait")] PTag pTag)
{
if (ModelState.IsValid)
{
db.Entry(pTag).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.CID = new SelectList(db.Cats, "ID", "Name", pTag.CID);
ViewBag.FirstTrait = new SelectList(db.Personalities, "ID", "Type", pTag.FirstTrait);
ViewBag.SecondTrait = new SelectList(db.Personalities, "ID", "Type", pTag.SecondTrait);
ViewBag.ThirdTrait = new SelectList(db.Personalities, "ID", "Type", pTag.ThirdTrait);
return View(pTag);
}

// GET: PTags/Delete/5
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
PTag pTag = db.PTags.Find(id);
if (pTag == null)
{
return HttpNotFound();
}
return View(pTag);
}

// POST: PTags/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
PTag pTag = db.PTags.Find(id);
db.PTags.Remove(pTag);
db.SaveChanges();
return RedirectToAction("Index");
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
6 changes: 6 additions & 0 deletions TheCatProject/TheCatProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Controllers\CatsController.cs" />
<Compile Include="Controllers\InformationController.cs" />
<Compile Include="Controllers\PTagsController.cs" />
<Compile Include="Controllers\TraitsController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
Expand Down Expand Up @@ -194,6 +195,11 @@
<Content Include="Views\Traits\Edit.cshtml" />
<Content Include="Views\Information\About.cshtml" />
<Content Include="Views\Information\BeforeYouStart.cshtml" />
<Content Include="Views\PTags\Create.cshtml" />
<Content Include="Views\PTags\Delete.cshtml" />
<Content Include="Views\PTags\Details.cshtml" />
<Content Include="Views\PTags\Edit.cshtml" />
<Content Include="Views\PTags\Index.cshtml" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
Expand Down
58 changes: 30 additions & 28 deletions TheCatProject/Views/Cats/Edit.cshtml
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
@model TheCatProject.Models.Cat
@* Create Cat - Details - Edit Details page
User page to edit entered name, age, sex *@


@model TheCatProject.Models.Cat

@{
ViewBag.Title = "Edit";
}

<h3>Kitty Kat Info</h3>
<h4>Make sure all is correct before saving!</h4>
<h3 id="pageheaders">Displaying: @Html.DisplayFor(model => model.Name)</h3>
<h5>Make sure all is correct before saving</h5>

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

<h4>Edit your cat's information:</h4>
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })

<div class="row">
<div class="col-md-12">
@Html.TextBoxFor(model => model.Name, new { @class = "boxes", placeholder = "Name" })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
<div class="row">
<div class="col-md-12">
@Html.TextBoxFor(model => model.Name, new { @class = "boxes", placeholder = "Name" })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
<div class="row">
<div class="col-md-12">
@Html.TextBoxFor(model => model.Age, new { @class = "boxes", type = "number", min = "0", step = "0.1", placeholder = "Age", })
@Html.ValidationMessageFor(model => model.Age, "", new { @class = "text-danger" })
</div>
</div>
<div class="row">
<div class="col-md-12">
@Html.TextBoxFor(model => model.Age, new { @class = "boxes", type = "number", min = "0", step = "0.1", placeholder = "Age", })
@Html.ValidationMessageFor(model => model.Age, "", new { @class = "text-danger" })
</div>
<br />
<div class="row">
<div class="col-md-12">
Female: @Html.RadioButtonFor(model => model.Sex, "Female")
Male: @Html.RadioButtonFor(model => model.Sex, "Male")
@Html.ValidationMessageFor(model => model.Sex, "", new { @class = "text-danger" })
</div>
</div>
<br />
<div class="row">
<div class="col-md-12">
Female: @Html.RadioButtonFor(model => model.Sex, "Female")
Male: @Html.RadioButtonFor(model => model.Sex, "Male")
@Html.ValidationMessageFor(model => model.Sex, "", new { @class = "text-danger" })
</div>
<div class="row">
<div class="col-md-12">
<input type="submit" value="Update my Cat!" class="myButton" />
</div>
</div>
<div class="row">
<div class="col-md-12">
<input type="submit" value="update my cat" class="myButton" />
</div>
</div>
}

@section Scripts {
Expand Down
59 changes: 59 additions & 0 deletions TheCatProject/Views/PTags/Create.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@model TheCatProject.Models.PTag

@{
ViewBag.Title = "Create";
}

<h2>Create</h2>

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

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

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

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

<div class="form-group">
@Html.LabelFor(model => model.ThirdTrait, "ThirdTrait", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("ThirdTrait", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.ThirdTrait, "", 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>
56 changes: 56 additions & 0 deletions TheCatProject/Views/PTags/Delete.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@model TheCatProject.Models.PTag

@{
ViewBag.Title = "Delete";
}

<h2>Delete</h2>

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

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

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

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

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

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

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

<dd>
@Html.DisplayFor(model => model.Personality2.Type)
</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 f6e1876

Please sign in to comment.