diff --git a/Yavsc/ApiControllers/HyperLinkApiController.cs b/Yavsc/ApiControllers/HyperLinkApiController.cs new file mode 100644 index 00000000..b6699f6f --- /dev/null +++ b/Yavsc/ApiControllers/HyperLinkApiController.cs @@ -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 GetLinks() + { + return _context.Links; + } + + // GET: api/HyperLinkApi/5 + [HttpGet("{id}", Name = "GetHyperLink")] + public async Task 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 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 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 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; + } + } +} diff --git a/Yavsc/Controllers/HyperLinkController.cs b/Yavsc/Controllers/HyperLinkController.cs new file mode 100644 index 00000000..2e85e49f --- /dev/null +++ b/Yavsc/Controllers/HyperLinkController.cs @@ -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 Index() + { + return View(await _context.Links.ToListAsync()); + } + + // GET: HyperLink/Details/5 + public async Task 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 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 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 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 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 DeleteConfirmed(string id) + { + HyperLink hyperLink = await _context.Links.SingleAsync(m => m.HRef == id); + _context.Links.Remove(hyperLink); + await _context.SaveChangesAsync(); + return RedirectToAction("Index"); + } + } +} diff --git a/Yavsc/Views/HyperLink/Create.cshtml b/Yavsc/Views/HyperLink/Create.cshtml new file mode 100644 index 00000000..9a840b95 --- /dev/null +++ b/Yavsc/Views/HyperLink/Create.cshtml @@ -0,0 +1,39 @@ +@model Yavsc.Models.Relationship.HyperLink + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +
+
+

HyperLink

+
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+ +
+
+
+
+ + + diff --git a/Yavsc/Views/HyperLink/Delete.cshtml b/Yavsc/Views/HyperLink/Delete.cshtml new file mode 100644 index 00000000..40e529b3 --- /dev/null +++ b/Yavsc/Views/HyperLink/Delete.cshtml @@ -0,0 +1,34 @@ +@model Yavsc.Models.Relationship.HyperLink + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

HyperLink

+
+
+
+ @Html.DisplayNameFor(model => model.ContentType) +
+
+ @Html.DisplayFor(model => model.ContentType) +
+
+ @Html.DisplayNameFor(model => model.Rel) +
+
+ @Html.DisplayFor(model => model.Rel) +
+
+ +
+
+ | + Back to List +
+
+
diff --git a/Yavsc/Views/HyperLink/Details.cshtml b/Yavsc/Views/HyperLink/Details.cshtml new file mode 100644 index 00000000..f043f8f1 --- /dev/null +++ b/Yavsc/Views/HyperLink/Details.cshtml @@ -0,0 +1,30 @@ +@model Yavsc.Models.Relationship.HyperLink + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

HyperLink

+
+
+
+ @Html.DisplayNameFor(model => model.ContentType) +
+
+ @Html.DisplayFor(model => model.ContentType) +
+
+ @Html.DisplayNameFor(model => model.Rel) +
+
+ @Html.DisplayFor(model => model.Rel) +
+
+
+

+ @Html.ActionLink("Edit", "Edit", new { /* id = Model.PrimaryKey */ }) | + Back to List +

diff --git a/Yavsc/Views/HyperLink/Edit.cshtml b/Yavsc/Views/HyperLink/Edit.cshtml new file mode 100644 index 00000000..e4a0a4fd --- /dev/null +++ b/Yavsc/Views/HyperLink/Edit.cshtml @@ -0,0 +1,41 @@ +@model Yavsc.Models.Relationship.HyperLink + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +
+
+

HyperLink

+
+
+ + +
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+ +
+
+
+
+ + + diff --git a/Yavsc/Views/HyperLink/Index.cshtml b/Yavsc/Views/HyperLink/Index.cshtml new file mode 100644 index 00000000..cf29fc77 --- /dev/null +++ b/Yavsc/Views/HyperLink/Index.cshtml @@ -0,0 +1,38 @@ +@model IEnumerable + +@{ + ViewData["Title"] = "Index"; +} + +

Index

+ +

+ Create New +

+ + + + + + + +@foreach (var item in Model) { + + + + + +} +
+ @Html.DisplayNameFor(model => model.ContentType) + + @Html.DisplayNameFor(model => model.Rel) +
+ @Html.DisplayFor(modelItem => item.ContentType) + + @Html.DisplayFor(modelItem => item.Rel) + + @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | + @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) | + @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) +