yavsc/Yavsc/Controllers/ColorsController.cs

120 lines
3.2 KiB
C#
Raw Normal View History

2017-02-12 03:53:33 +01:00
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.Data.Entity;
using Yavsc.Models;
using Yavsc.Models.Drawing;
namespace Yavsc.Controllers
{
public class ColorsController : Controller
{
private ApplicationDbContext _context;
public ColorsController(ApplicationDbContext context)
{
_context = context;
}
// GET: Colors
public async Task<IActionResult> Index()
{
return View(await _context.Color.ToListAsync());
}
// GET: Colors/Details/5
2017-02-12 22:20:57 +01:00
public async Task<IActionResult> Details(long? id)
2017-02-12 03:53:33 +01:00
{
if (id == null)
{
return HttpNotFound();
}
2017-02-12 22:20:57 +01:00
Color color = await _context.Color.SingleAsync(m => m.Id == id);
2017-02-12 03:53:33 +01:00
if (color == null)
{
return HttpNotFound();
}
return View(color);
}
// GET: Colors/Create
public IActionResult Create()
{
return View(new Color());
}
// POST: Colors/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Color color)
{
if (ModelState.IsValid)
{
_context.Color.Add(color);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(color);
}
// GET: Colors/Edit/5
2017-02-12 22:20:57 +01:00
public async Task<IActionResult> Edit(long? id)
2017-02-12 03:53:33 +01:00
{
if (id == null)
{
return HttpNotFound();
}
2017-02-12 22:20:57 +01:00
Color color = await _context.Color.SingleAsync(m => m.Id == id);
2017-02-12 03:53:33 +01:00
if (color == null)
{
return HttpNotFound();
}
return View(color);
}
// POST: Colors/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(Color color)
{
if (ModelState.IsValid)
{
_context.Update(color);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(color);
}
// GET: Colors/Delete/5
[ActionName("Delete")]
2017-02-12 22:20:57 +01:00
public async Task<IActionResult> Delete(long? id)
2017-02-12 03:53:33 +01:00
{
if (id == null)
{
return HttpNotFound();
}
2017-02-12 22:20:57 +01:00
Color color = await _context.Color.SingleAsync(m => m.Id == id);
2017-02-12 03:53:33 +01:00
if (color == null)
{
return HttpNotFound();
}
return View(color);
}
// POST: Colors/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
2017-02-12 22:20:57 +01:00
public async Task<IActionResult> DeleteConfirmed(long id)
2017-02-12 03:53:33 +01:00
{
2017-02-12 22:20:57 +01:00
Color color = await _context.Color.SingleAsync(m => m.Id == id);
2017-02-12 03:53:33 +01:00
_context.Color.Remove(color);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}