140 lines
3.9 KiB
C#
140 lines
3.9 KiB
C#
|
8 years ago
|
using System.Threading.Tasks;
|
||
|
|
using Microsoft.AspNet.Mvc;
|
||
|
|
using Microsoft.Data.Entity;
|
||
|
|
using Yavsc.Models;
|
||
|
|
using Yavsc.Models.IT.Fixing;
|
||
|
7 years ago
|
using Yavsc.Models.IT.Evolution;
|
||
|
|
using Yavsc.Server.Helpers;
|
||
|
7 years ago
|
using System.Collections.Generic;
|
||
|
|
using Microsoft.AspNet.Mvc.Rendering;
|
||
|
|
using Microsoft.Extensions.Localization;
|
||
|
8 years ago
|
|
||
|
|
namespace Yavsc.Controllers
|
||
|
|
{
|
||
|
|
public class BugController : Controller
|
||
|
|
{
|
||
|
7 years ago
|
ApplicationDbContext _context;
|
||
|
|
IStringLocalizer<BugController> _localizer;
|
||
|
8 years ago
|
|
||
|
7 years ago
|
public BugController(ApplicationDbContext context, IStringLocalizer<BugController> localizer )
|
||
|
8 years ago
|
{
|
||
|
7 years ago
|
_context = context;
|
||
|
|
_localizer = localizer;
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
|
// GET: Bug
|
||
|
|
public async Task<IActionResult> Index()
|
||
|
|
{
|
||
|
|
return View(await _context.Bug.ToListAsync());
|
||
|
|
}
|
||
|
|
|
||
|
|
// GET: Bug/Details/5
|
||
|
|
public async Task<IActionResult> Details(long? id)
|
||
|
|
{
|
||
|
|
if (id == null)
|
||
|
|
{
|
||
|
|
return HttpNotFound();
|
||
|
|
}
|
||
|
|
|
||
|
|
Bug bug = await _context.Bug.SingleAsync(m => m.Id == id);
|
||
|
|
if (bug == null)
|
||
|
|
{
|
||
|
|
return HttpNotFound();
|
||
|
|
}
|
||
|
|
|
||
|
|
return View(bug);
|
||
|
|
}
|
||
|
|
|
||
|
|
// GET: Bug/Create
|
||
|
|
public IActionResult Create()
|
||
|
|
{
|
||
|
7 years ago
|
ViewBag.Features = Features(_context);
|
||
|
|
ViewBag.Statuses = Statuses(default(BugStatus));
|
||
|
8 years ago
|
return View();
|
||
|
|
}
|
||
|
|
|
||
|
7 years ago
|
IEnumerable<SelectListItem> Statuses(BugStatus ?status) =>
|
||
|
|
typeof(Yavsc.Models.IT.Fixing.BugStatus).CreateSelectListItems(status);
|
||
|
|
IEnumerable<SelectListItem> Features(ApplicationDbContext context) =>
|
||
|
|
context.Feature.CreateSelectListItems<Feature>(f => f.Id.ToString(), f => f.ShortName, null)
|
||
|
|
.AddNull(_localizer["noAttachedFID"]);
|
||
|
|
|
||
|
8 years ago
|
// POST: Bug/Create
|
||
|
|
[HttpPost]
|
||
|
|
[ValidateAntiForgeryToken]
|
||
|
|
public async Task<IActionResult> Create(Bug bug)
|
||
|
|
{
|
||
|
|
if (ModelState.IsValid)
|
||
|
|
{
|
||
|
|
_context.Bug.Add(bug);
|
||
|
|
await _context.SaveChangesAsync();
|
||
|
|
return RedirectToAction("Index");
|
||
|
|
}
|
||
|
|
return View(bug);
|
||
|
|
}
|
||
|
|
|
||
|
|
// GET: Bug/Edit/5
|
||
|
|
public async Task<IActionResult> Edit(long? id)
|
||
|
|
{
|
||
|
|
if (id == null)
|
||
|
|
{
|
||
|
|
return HttpNotFound();
|
||
|
|
}
|
||
|
|
|
||
|
|
Bug bug = await _context.Bug.SingleAsync(m => m.Id == id);
|
||
|
|
if (bug == null)
|
||
|
|
{
|
||
|
|
return HttpNotFound();
|
||
|
|
}
|
||
|
7 years ago
|
|
||
|
|
ViewBag.Features = Features(_context);
|
||
|
|
ViewBag.Statuses = Statuses(bug.Status);
|
||
|
|
|
||
|
8 years ago
|
return View(bug);
|
||
|
|
}
|
||
|
|
|
||
|
|
// POST: Bug/Edit/5
|
||
|
|
[HttpPost]
|
||
|
|
[ValidateAntiForgeryToken]
|
||
|
|
public async Task<IActionResult> Edit(Bug bug)
|
||
|
|
{
|
||
|
|
if (ModelState.IsValid)
|
||
|
|
{
|
||
|
|
_context.Update(bug);
|
||
|
|
await _context.SaveChangesAsync();
|
||
|
|
return RedirectToAction("Index");
|
||
|
|
}
|
||
|
|
return View(bug);
|
||
|
|
}
|
||
|
|
|
||
|
|
// GET: Bug/Delete/5
|
||
|
|
[ActionName("Delete")]
|
||
|
|
public async Task<IActionResult> Delete(long? id)
|
||
|
|
{
|
||
|
|
if (id == null)
|
||
|
|
{
|
||
|
|
return HttpNotFound();
|
||
|
|
}
|
||
|
|
|
||
|
|
Bug bug = await _context.Bug.SingleAsync(m => m.Id == id);
|
||
|
|
if (bug == null)
|
||
|
|
{
|
||
|
|
return HttpNotFound();
|
||
|
|
}
|
||
|
|
|
||
|
|
return View(bug);
|
||
|
|
}
|
||
|
|
|
||
|
|
// POST: Bug/Delete/5
|
||
|
|
[HttpPost, ActionName("Delete")]
|
||
|
|
[ValidateAntiForgeryToken]
|
||
|
|
public async Task<IActionResult> DeleteConfirmed(long id)
|
||
|
|
{
|
||
|
|
Bug bug = await _context.Bug.SingleAsync(m => m.Id == id);
|
||
|
|
_context.Bug.Remove(bug);
|
||
|
|
await _context.SaveChangesAsync();
|
||
|
|
return RedirectToAction("Index");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|