Hyper-links
parent
f38e1c3f6b
commit
c3193a72d6
@ -0,0 +1,148 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.Http;
|
||||||
|
using Microsoft.AspNet.Mvc;
|
||||||
|
using Microsoft.Data.Entity;
|
||||||
|
using Yavsc.Models;
|
||||||
|
using Yavsc.Models.Relationship;
|
||||||
|
|
||||||
|
namespace Yavsc.Controllers
|
||||||
|
{
|
||||||
|
[Produces("application/json")]
|
||||||
|
[Route("api/hyperlink")]
|
||||||
|
public class HyperLinkApiController : Controller
|
||||||
|
{
|
||||||
|
private ApplicationDbContext _context;
|
||||||
|
|
||||||
|
public HyperLinkApiController(ApplicationDbContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: api/HyperLinkApi
|
||||||
|
[HttpGet]
|
||||||
|
public IEnumerable<HyperLink> GetLinks()
|
||||||
|
{
|
||||||
|
return _context.Links;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: api/HyperLinkApi/5
|
||||||
|
[HttpGet("{id}", Name = "GetHyperLink")]
|
||||||
|
public async Task<IActionResult> GetHyperLink([FromRoute] string id)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return HttpBadRequest(ModelState);
|
||||||
|
}
|
||||||
|
|
||||||
|
HyperLink hyperLink = await _context.Links.SingleAsync(m => m.HRef == id);
|
||||||
|
|
||||||
|
if (hyperLink == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(hyperLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUT: api/HyperLinkApi/5
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
public async Task<IActionResult> PutHyperLink([FromRoute] string id, [FromBody] HyperLink hyperLink)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return HttpBadRequest(ModelState);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id != hyperLink.HRef)
|
||||||
|
{
|
||||||
|
return HttpBadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.Entry(hyperLink).State = EntityState.Modified;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch (DbUpdateConcurrencyException)
|
||||||
|
{
|
||||||
|
if (!HyperLinkExists(id))
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: api/HyperLinkApi
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IActionResult> PostHyperLink([FromBody] HyperLink hyperLink)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return HttpBadRequest(ModelState);
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.Links.Add(hyperLink);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch (DbUpdateException)
|
||||||
|
{
|
||||||
|
if (HyperLinkExists(hyperLink.HRef))
|
||||||
|
{
|
||||||
|
return new HttpStatusCodeResult(StatusCodes.Status409Conflict);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return CreatedAtRoute("GetHyperLink", new { id = hyperLink.HRef }, hyperLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE: api/HyperLinkApi/5
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public async Task<IActionResult> DeleteHyperLink([FromRoute] string id)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return HttpBadRequest(ModelState);
|
||||||
|
}
|
||||||
|
|
||||||
|
HyperLink hyperLink = await _context.Links.SingleAsync(m => m.HRef == id);
|
||||||
|
if (hyperLink == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.Links.Remove(hyperLink);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return Ok(hyperLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
_context.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool HyperLinkExists(string id)
|
||||||
|
{
|
||||||
|
return _context.Links.Count(e => e.HRef == id) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,122 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.Mvc;
|
||||||
|
using Microsoft.AspNet.Mvc.Rendering;
|
||||||
|
using Microsoft.Data.Entity;
|
||||||
|
using Yavsc.Models;
|
||||||
|
using Yavsc.Models.Relationship;
|
||||||
|
|
||||||
|
namespace Yavsc.Controllers
|
||||||
|
{
|
||||||
|
public class HyperLinkController : Controller
|
||||||
|
{
|
||||||
|
private ApplicationDbContext _context;
|
||||||
|
|
||||||
|
public HyperLinkController(ApplicationDbContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: HyperLink
|
||||||
|
public async Task<IActionResult> Index()
|
||||||
|
{
|
||||||
|
return View(await _context.Links.ToListAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: HyperLink/Details/5
|
||||||
|
public async Task<IActionResult> Details(string id)
|
||||||
|
{
|
||||||
|
if (id == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
HyperLink hyperLink = await _context.Links.SingleAsync(m => m.HRef == id);
|
||||||
|
if (hyperLink == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
return View(hyperLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: HyperLink/Create
|
||||||
|
public IActionResult Create()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: HyperLink/Create
|
||||||
|
[HttpPost]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> Create(HyperLink hyperLink)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
_context.Links.Add(hyperLink);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
return View(hyperLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: HyperLink/Edit/5
|
||||||
|
public async Task<IActionResult> Edit(string id)
|
||||||
|
{
|
||||||
|
if (id == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
HyperLink hyperLink = await _context.Links.SingleAsync(m => m.HRef == id);
|
||||||
|
if (hyperLink == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
return View(hyperLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: HyperLink/Edit/5
|
||||||
|
[HttpPost]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> Edit(HyperLink hyperLink)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
_context.Update(hyperLink);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
return View(hyperLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: HyperLink/Delete/5
|
||||||
|
[ActionName("Delete")]
|
||||||
|
public async Task<IActionResult> Delete(string id)
|
||||||
|
{
|
||||||
|
if (id == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
HyperLink hyperLink = await _context.Links.SingleAsync(m => m.HRef == id);
|
||||||
|
if (hyperLink == null)
|
||||||
|
{
|
||||||
|
return HttpNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
return View(hyperLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: HyperLink/Delete/5
|
||||||
|
[HttpPost, ActionName("Delete")]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> DeleteConfirmed(string id)
|
||||||
|
{
|
||||||
|
HyperLink hyperLink = await _context.Links.SingleAsync(m => m.HRef == id);
|
||||||
|
_context.Links.Remove(hyperLink);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
@model Yavsc.Models.Relationship.HyperLink
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Create";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Create</h2>
|
||||||
|
|
||||||
|
<form asp-action="Create">
|
||||||
|
<div class="form-horizontal">
|
||||||
|
<h4>HyperLink</h4>
|
||||||
|
<hr />
|
||||||
|
<div asp-validation-summary="ValidationSummary.ModelOnly" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="ContentType" class="col-md-2 control-label"></label>
|
||||||
|
<div class="col-md-10">
|
||||||
|
<input asp-for="ContentType" class="form-control" />
|
||||||
|
<span asp-validation-for="ContentType" class="text-danger" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Rel" class="col-md-2 control-label"></label>
|
||||||
|
<div class="col-md-10">
|
||||||
|
<input asp-for="Rel" class="form-control" />
|
||||||
|
<span asp-validation-for="Rel" 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>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<a asp-action="Index">Back to List</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
@model Yavsc.Models.Relationship.HyperLink
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Delete";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Delete</h2>
|
||||||
|
|
||||||
|
<h3>Are you sure you want to delete this?</h3>
|
||||||
|
<div>
|
||||||
|
<h4>HyperLink</h4>
|
||||||
|
<hr />
|
||||||
|
<dl class="dl-horizontal">
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.ContentType)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.ContentType)
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.Rel)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.Rel)
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<form asp-action="Delete">
|
||||||
|
<div class="form-actions no-color">
|
||||||
|
<input type="submit" value="Delete" class="btn btn-default" /> |
|
||||||
|
<a asp-action="Index">Back to List</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
@model Yavsc.Models.Relationship.HyperLink
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Details";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Details</h2>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h4>HyperLink</h4>
|
||||||
|
<hr />
|
||||||
|
<dl class="dl-horizontal">
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.ContentType)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.ContentType)
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.Rel)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.Rel)
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
<p>
|
||||||
|
@Html.ActionLink("Edit", "Edit", new { /* id = Model.PrimaryKey */ }) |
|
||||||
|
<a asp-action="Index">Back to List</a>
|
||||||
|
</p>
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
@model Yavsc.Models.Relationship.HyperLink
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Edit";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Edit</h2>
|
||||||
|
|
||||||
|
<form asp-action="Edit">
|
||||||
|
<div class="form-horizontal">
|
||||||
|
<h4>HyperLink</h4>
|
||||||
|
<hr />
|
||||||
|
<div asp-validation-summary="ValidationSummary.ModelOnly" class="text-danger"></div>
|
||||||
|
<input type="hidden" asp-for="HRef" />
|
||||||
|
<input type="hidden" asp-for="Method" />
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="ContentType" class="col-md-2 control-label"></label>
|
||||||
|
<div class="col-md-10">
|
||||||
|
<input asp-for="ContentType" class="form-control" />
|
||||||
|
<span asp-validation-for="ContentType" class="text-danger" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Rel" class="col-md-2 control-label"></label>
|
||||||
|
<div class="col-md-10">
|
||||||
|
<input asp-for="Rel" class="form-control" />
|
||||||
|
<span asp-validation-for="Rel" class="text-danger" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-offset-2 col-md-10">
|
||||||
|
<input type="submit" value="Save" class="btn btn-default" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<a asp-action="Index">Back to List</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
@model IEnumerable<Yavsc.Models.Relationship.HyperLink>
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Index";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Index</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<a asp-action="Create">Create New</a>
|
||||||
|
</p>
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.ContentType)
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.Rel)
|
||||||
|
</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
@foreach (var item in Model) {
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.ContentType)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Rel)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
|
||||||
|
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
|
||||||
|
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</table>
|
||||||
Loading…
Reference in New Issue