2019-05-27 18:48:47 +01:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-02-10 02:10:18 +00:00
|
|
|
using Marechai.Database.Models;
|
2019-05-27 18:48:47 +01:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
2020-02-10 02:20:48 +00:00
|
|
|
namespace Marechai
|
2019-05-27 18:48:47 +01:00
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
[Area("Admin"), Authorize]
|
2019-05-27 18:48:47 +01:00
|
|
|
public class LicensesController : Controller
|
|
|
|
|
{
|
2020-02-10 02:47:39 +00:00
|
|
|
readonly MarechaiContext _context;
|
2019-05-27 18:48:47 +01:00
|
|
|
|
2020-02-10 22:44:18 +00:00
|
|
|
public LicensesController(MarechaiContext context) => _context = context;
|
2019-05-27 18:48:47 +01:00
|
|
|
|
|
|
|
|
// GET: Licenses
|
2020-02-10 22:44:18 +00:00
|
|
|
public async Task<IActionResult> Index() => View(await _context.Licenses.OrderBy(l => l.Name).ToListAsync());
|
2019-05-27 18:48:47 +01:00
|
|
|
|
|
|
|
|
// GET: Licenses/Details/5
|
|
|
|
|
public async Task<IActionResult> Details(int? id)
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
if(id == null)
|
|
|
|
|
return NotFound();
|
2019-05-27 18:48:47 +01:00
|
|
|
|
|
|
|
|
License license = await _context.Licenses.FirstOrDefaultAsync(m => m.Id == id);
|
2020-02-10 22:44:18 +00:00
|
|
|
|
|
|
|
|
if(license == null)
|
|
|
|
|
return NotFound();
|
2019-05-27 18:48:47 +01:00
|
|
|
|
|
|
|
|
return View(license);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: Licenses/Create
|
|
|
|
|
public IActionResult Create() => View();
|
|
|
|
|
|
|
|
|
|
// POST: Licenses/Create
|
2020-02-10 22:44:18 +00:00
|
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
2019-05-27 18:48:47 +01:00
|
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
2020-02-10 22:44:18 +00:00
|
|
|
[HttpPost, ValidateAntiForgeryToken]
|
2019-05-27 18:48:47 +01:00
|
|
|
public async Task<IActionResult> Create([Bind("Name,SPDX,FsfApproved,OsiApproved,Link,Text,Id")]
|
|
|
|
|
License license)
|
|
|
|
|
{
|
|
|
|
|
if(ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
_context.Add(license);
|
|
|
|
|
await _context.SaveChangesAsync();
|
2020-02-10 22:44:18 +00:00
|
|
|
|
2019-05-27 18:48:47 +01:00
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(license);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: Licenses/Edit/5
|
|
|
|
|
public async Task<IActionResult> Edit(int? id)
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
if(id == null)
|
|
|
|
|
return NotFound();
|
2019-05-27 18:48:47 +01:00
|
|
|
|
|
|
|
|
License license = await _context.Licenses.FindAsync(id);
|
2020-02-10 22:44:18 +00:00
|
|
|
|
|
|
|
|
if(license == null)
|
|
|
|
|
return NotFound();
|
2019-05-27 18:48:47 +01:00
|
|
|
|
|
|
|
|
return View(license);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: Licenses/Edit/5
|
2020-02-10 22:44:18 +00:00
|
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
2019-05-27 18:48:47 +01:00
|
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
2020-02-10 22:44:18 +00:00
|
|
|
[HttpPost, ValidateAntiForgeryToken]
|
2019-05-27 18:48:47 +01:00
|
|
|
public async Task<IActionResult> Edit(int id, [Bind("Name,SPDX,FsfApproved,OsiApproved,Link,Text,Id")]
|
|
|
|
|
License license)
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
if(id != license.Id)
|
|
|
|
|
return NotFound();
|
2019-05-27 18:48:47 +01:00
|
|
|
|
|
|
|
|
if(ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_context.Update(license);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
catch(DbUpdateConcurrencyException)
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
if(!LicenseExists(license.Id))
|
|
|
|
|
return NotFound();
|
2019-05-27 18:48:47 +01:00
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(license);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: Licenses/Delete/5
|
|
|
|
|
public async Task<IActionResult> Delete(int? id)
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
if(id == null)
|
|
|
|
|
return NotFound();
|
2019-05-27 18:48:47 +01:00
|
|
|
|
|
|
|
|
License license = await _context.Licenses.FirstOrDefaultAsync(m => m.Id == id);
|
2020-02-10 22:44:18 +00:00
|
|
|
|
|
|
|
|
if(license == null)
|
|
|
|
|
return NotFound();
|
2019-05-27 18:48:47 +01:00
|
|
|
|
|
|
|
|
return View(license);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: Licenses/Delete/5
|
2020-02-10 22:44:18 +00:00
|
|
|
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
|
2019-05-27 18:48:47 +01:00
|
|
|
public async Task<IActionResult> DeleteConfirmed(int id)
|
|
|
|
|
{
|
|
|
|
|
License license = await _context.Licenses.FindAsync(id);
|
|
|
|
|
_context.Licenses.Remove(license);
|
|
|
|
|
await _context.SaveChangesAsync();
|
2020-02-10 22:44:18 +00:00
|
|
|
|
2019-05-27 18:48:47 +01:00
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 22:44:18 +00:00
|
|
|
bool LicenseExists(int id) => _context.Licenses.Any(e => e.Id == id);
|
2019-05-27 18:48:47 +01:00
|
|
|
}
|
|
|
|
|
}
|