2023-03-19 17:57:55 +00:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2016-07-30 22:51:19 +02:00
|
|
|
using Yavsc.Models;
|
|
|
|
|
using Yavsc.Models.Billing;
|
2025-07-15 19:43:41 +01:00
|
|
|
using Yavsc.Server.Helpers;
|
2026-08-31 02:14:04 +01:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System.Linq;
|
2016-07-30 22:51:19 +02:00
|
|
|
|
|
|
|
|
namespace Yavsc.Controllers
|
|
|
|
|
{
|
2025-08-18 11:27:13 +01:00
|
|
|
[Authorize("AdministratorOnly")]
|
2016-07-30 22:51:19 +02:00
|
|
|
public class SIRENExceptionsController : Controller
|
|
|
|
|
{
|
2020-10-09 19:35:39 +01:00
|
|
|
private readonly ApplicationDbContext _context;
|
2016-07-30 22:51:19 +02:00
|
|
|
|
|
|
|
|
public SIRENExceptionsController(ApplicationDbContext context)
|
|
|
|
|
{
|
2026-08-31 02:14:04 +01:00
|
|
|
_context = context;
|
2016-07-30 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: SIRENExceptions
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View(_context.ExceptionsSIREN.ToList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: SIRENExceptions/Details/5
|
|
|
|
|
public IActionResult Details(string id)
|
|
|
|
|
{
|
|
|
|
|
if (id == null)
|
|
|
|
|
{
|
2023-03-19 17:57:55 +00:00
|
|
|
return NotFound();
|
2016-07-30 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExceptionSIREN exceptionSIREN = _context.ExceptionsSIREN.Single(m => m.SIREN == id);
|
|
|
|
|
if (exceptionSIREN == null)
|
|
|
|
|
{
|
2023-03-19 17:57:55 +00:00
|
|
|
return NotFound();
|
2016-07-30 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(exceptionSIREN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: SIRENExceptions/Create
|
|
|
|
|
public IActionResult Create()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: SIRENExceptions/Create
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public IActionResult Create(ExceptionSIREN exceptionSIREN)
|
|
|
|
|
{
|
2026-08-31 02:14:04 +01:00
|
|
|
exceptionSIREN ??= new ExceptionSIREN();
|
|
|
|
|
exceptionSIREN.SIREN = NormalizeSiren(exceptionSIREN.SIREN);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(exceptionSIREN.SIREN) || exceptionSIREN.SIREN.Length != 9 || !exceptionSIREN.SIREN.All(char.IsDigit))
|
|
|
|
|
{
|
|
|
|
|
ModelState.AddModelError(nameof(ExceptionSIREN.SIREN), "Le SIREN doit contenir exactement 9 chiffres.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_context.ExceptionsSIREN.Any(e => e.SIREN == exceptionSIREN.SIREN))
|
|
|
|
|
{
|
|
|
|
|
ModelState.AddModelError(nameof(ExceptionSIREN.SIREN), "Ce SIREN est deja dans la liste des exceptions.");
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-30 22:51:19 +02:00
|
|
|
if (ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
_context.ExceptionsSIREN.Add(exceptionSIREN);
|
2026-08-31 02:14:04 +01:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_context.SaveChanges(User.GetUserId());
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
|
|
|
|
catch (DbUpdateException)
|
|
|
|
|
{
|
|
|
|
|
ModelState.AddModelError(string.Empty, "Impossible d'enregistrer cette exception SIREN.");
|
|
|
|
|
}
|
2016-07-30 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
return View(exceptionSIREN);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-31 02:14:04 +01:00
|
|
|
private static string NormalizeSiren(string? siren)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(siren)) return string.Empty;
|
|
|
|
|
return new string(siren.Where(char.IsDigit).ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-30 22:51:19 +02:00
|
|
|
// GET: SIRENExceptions/Edit/5
|
|
|
|
|
public IActionResult Edit(string id)
|
|
|
|
|
{
|
|
|
|
|
if (id == null)
|
|
|
|
|
{
|
2023-03-19 17:57:55 +00:00
|
|
|
return NotFound();
|
2016-07-30 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExceptionSIREN exceptionSIREN = _context.ExceptionsSIREN.Single(m => m.SIREN == id);
|
|
|
|
|
if (exceptionSIREN == null)
|
|
|
|
|
{
|
2023-03-19 17:57:55 +00:00
|
|
|
return NotFound();
|
2016-07-30 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
return View(exceptionSIREN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: SIRENExceptions/Edit/5
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public IActionResult Edit(ExceptionSIREN exceptionSIREN)
|
|
|
|
|
{
|
|
|
|
|
if (ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
_context.Update(exceptionSIREN);
|
2017-02-23 03:10:30 +01:00
|
|
|
_context.SaveChanges(User.GetUserId());
|
2016-07-30 22:51:19 +02:00
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
|
|
|
|
return View(exceptionSIREN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: SIRENExceptions/Delete/5
|
|
|
|
|
[ActionName("Delete")]
|
|
|
|
|
public IActionResult Delete(string id)
|
|
|
|
|
{
|
|
|
|
|
if (id == null)
|
|
|
|
|
{
|
2023-03-19 17:57:55 +00:00
|
|
|
return NotFound();
|
2016-07-30 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExceptionSIREN exceptionSIREN = _context.ExceptionsSIREN.Single(m => m.SIREN == id);
|
|
|
|
|
if (exceptionSIREN == null)
|
|
|
|
|
{
|
2023-03-19 17:57:55 +00:00
|
|
|
return NotFound();
|
2016-07-30 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(exceptionSIREN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: SIRENExceptions/Delete/5
|
|
|
|
|
[HttpPost, ActionName("Delete")]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public IActionResult DeleteConfirmed(string id)
|
|
|
|
|
{
|
|
|
|
|
ExceptionSIREN exceptionSIREN = _context.ExceptionsSIREN.Single(m => m.SIREN == id);
|
|
|
|
|
_context.ExceptionsSIREN.Remove(exceptionSIREN);
|
2017-02-23 03:10:30 +01:00
|
|
|
_context.SaveChanges(User.GetUserId());
|
2016-07-30 22:51:19 +02:00
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|