yavsc/Yavsc/Controllers/CircleController.cs

121 lines
3.2 KiB
C#
Raw Normal View History

2017-01-19 14:32:03 +01:00
2017-01-19 12:59:49 +01:00
using System.Threading.Tasks;
2016-05-17 18:22:18 +02:00
using Microsoft.AspNet.Mvc;
2017-01-19 12:59:49 +01:00
using Microsoft.Data.Entity;
2016-05-17 18:22:18 +02:00
using Yavsc.Models;
2017-01-19 12:59:49 +01:00
using Yavsc.Models.Relationship;
2016-05-17 18:22:18 +02:00
namespace Yavsc.Controllers
{
public class CircleController : Controller
{
private ApplicationDbContext _context;
public CircleController(ApplicationDbContext context)
{
2017-01-19 12:59:49 +01:00
_context = context;
2016-05-17 18:22:18 +02:00
}
// GET: Circle
2017-01-19 12:59:49 +01:00
public async Task<IActionResult> Index()
2016-05-17 18:22:18 +02:00
{
2017-01-19 12:59:49 +01:00
return View(await _context.Circle.ToListAsync());
2016-05-17 18:22:18 +02:00
}
// GET: Circle/Details/5
2017-01-19 12:59:49 +01:00
public async Task<IActionResult> Details(long? id)
2016-05-17 18:22:18 +02:00
{
if (id == null)
{
return HttpNotFound();
}
2017-01-19 12:59:49 +01:00
Circle circle = await _context.Circle.SingleAsync(m => m.Id == id);
if (circle == null)
2016-05-17 18:22:18 +02:00
{
return HttpNotFound();
}
2017-01-19 12:59:49 +01:00
return View(circle);
2016-05-17 18:22:18 +02:00
}
// GET: Circle/Create
public IActionResult Create()
{
return View();
}
// POST: Circle/Create
[HttpPost]
[ValidateAntiForgeryToken]
2017-01-19 12:59:49 +01:00
public async Task<IActionResult> Create(Circle circle)
2016-05-17 18:22:18 +02:00
{
if (ModelState.IsValid)
{
2017-01-19 12:59:49 +01:00
_context.Circle.Add(circle);
await _context.SaveChangesAsync();
2016-05-17 18:22:18 +02:00
return RedirectToAction("Index");
}
2017-01-19 12:59:49 +01:00
return View(circle);
2016-05-17 18:22:18 +02:00
}
// GET: Circle/Edit/5
2017-01-19 12:59:49 +01:00
public async Task<IActionResult> Edit(long? id)
2016-05-17 18:22:18 +02:00
{
if (id == null)
{
return HttpNotFound();
}
2017-01-19 12:59:49 +01:00
Circle circle = await _context.Circle.SingleAsync(m => m.Id == id);
if (circle == null)
2016-05-17 18:22:18 +02:00
{
return HttpNotFound();
}
2017-01-19 12:59:49 +01:00
return View(circle);
2016-05-17 18:22:18 +02:00
}
// POST: Circle/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
2017-01-19 12:59:49 +01:00
public async Task<IActionResult> Edit(Circle circle)
2016-05-17 18:22:18 +02:00
{
if (ModelState.IsValid)
{
2017-01-19 12:59:49 +01:00
_context.Update(circle);
await _context.SaveChangesAsync();
2016-05-17 18:22:18 +02:00
return RedirectToAction("Index");
}
2017-01-19 12:59:49 +01:00
return View(circle);
2016-05-17 18:22:18 +02:00
}
// GET: Circle/Delete/5
[ActionName("Delete")]
2017-01-19 12:59:49 +01:00
public async Task<IActionResult> Delete(long? id)
2016-05-17 18:22:18 +02:00
{
if (id == null)
{
return HttpNotFound();
}
2017-01-19 12:59:49 +01:00
Circle circle = await _context.Circle.SingleAsync(m => m.Id == id);
if (circle == null)
2016-05-17 18:22:18 +02:00
{
return HttpNotFound();
}
2017-01-19 12:59:49 +01:00
return View(circle);
2016-05-17 18:22:18 +02:00
}
// POST: Circle/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
2017-01-19 12:59:49 +01:00
public async Task<IActionResult> DeleteConfirmed(long id)
2016-05-17 18:22:18 +02:00
{
2017-01-19 12:59:49 +01:00
Circle circle = await _context.Circle.SingleAsync(m => m.Id == id);
_context.Circle.Remove(circle);
await _context.SaveChangesAsync();
2016-05-17 18:22:18 +02:00
return RedirectToAction("Index");
}
}
}