yavsc/Yavsc/Controllers/Haircut/HairTaintsController.cs

130 lines
4.0 KiB
C#

using System.Security.Claims;
8 years ago
using System.Threading.Tasks;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Mvc;
8 years ago
using Microsoft.AspNet.Mvc.Rendering;
8 years ago
using Microsoft.Data.Entity;
8 years ago
using Yavsc.Models;
using Yavsc.Models.Haircut;
8 years ago
namespace Yavsc.Controllers
{
[Authorize("AdministratorOnly")]
public class HairTaintsController : Controller
{
private ApplicationDbContext _context;
public HairTaintsController(ApplicationDbContext context)
{
8 years ago
_context = context;
8 years ago
}
// GET: HairTaints
public async Task<IActionResult> Index()
{
8 years ago
var applicationDbContext = _context.HairTaint.Include(h => h.Color);
return View(await applicationDbContext.ToListAsync());
8 years ago
}
// GET: HairTaints/Details/5
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
return HttpNotFound();
}
HairTaint hairTaint = await _context.HairTaint.SingleAsync(m => m.Id == id);
if (hairTaint == null)
{
return HttpNotFound();
}
return View(hairTaint);
}
// GET: HairTaints/Create
public IActionResult Create()
{
8 years ago
ViewBag.ColorId = new SelectList(_context.Color, "Id", "Name");
8 years ago
return View();
}
// POST: HairTaints/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(HairTaint hairTaint)
{
if (ModelState.IsValid)
{
_context.HairTaint.Add(hairTaint);
await _context.SaveChangesAsync(User.GetUserId());
8 years ago
return RedirectToAction("Index");
}
8 years ago
ViewBag.ColorId = new SelectList(_context.Color, "Id", "Name", hairTaint.ColorId);
8 years ago
return View(hairTaint);
}
// GET: HairTaints/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return HttpNotFound();
}
HairTaint hairTaint = await _context.HairTaint.SingleAsync(m => m.Id == id);
if (hairTaint == null)
{
return HttpNotFound();
}
8 years ago
ViewBag.ColorId = new SelectList(_context.Color, "Id", "Name",hairTaint.ColorId);
8 years ago
return View(hairTaint);
}
// POST: HairTaints/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(HairTaint hairTaint)
{
if (ModelState.IsValid)
{
_context.Update(hairTaint);
await _context.SaveChangesAsync(User.GetUserId());
8 years ago
return RedirectToAction("Index");
}
8 years ago
ViewBag.ColorId = new SelectList(_context.Color, "Id", "Name", hairTaint.ColorId);
8 years ago
return View(hairTaint);
}
// GET: HairTaints/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
return HttpNotFound();
}
HairTaint hairTaint = await _context.HairTaint.SingleAsync(m => m.Id == id);
if (hairTaint == null)
{
return HttpNotFound();
}
return View(hairTaint);
}
// POST: HairTaints/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
HairTaint hairTaint = await _context.HairTaint.SingleAsync(m => m.Id == id);
_context.HairTaint.Remove(hairTaint);
await _context.SaveChangesAsync(User.GetUserId());
8 years ago
return RedirectToAction("Index");
}
}
}