Exploration des activités

This commit is contained in:
Paul Schneider 2026-08-31 02:14:04 +01:00
commit 3c51e66e50
20 changed files with 743 additions and 61 deletions

View file

@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Mvc;
using Yavsc.Models;
using Yavsc.Models.Billing;
using Yavsc.Server.Helpers;
using Microsoft.EntityFrameworkCore;
using System.Linq;
namespace Yavsc.Controllers
{
@ -13,7 +15,7 @@ namespace Yavsc.Controllers
public SIRENExceptionsController(ApplicationDbContext context)
{
_context = context;
_context = context;
}
// GET: SIRENExceptions
@ -50,15 +52,41 @@ namespace Yavsc.Controllers
[ValidateAntiForgeryToken]
public IActionResult Create(ExceptionSIREN exceptionSIREN)
{
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.");
}
if (ModelState.IsValid)
{
_context.ExceptionsSIREN.Add(exceptionSIREN);
_context.SaveChanges(User.GetUserId());
return RedirectToAction("Index");
try
{
_context.SaveChanges(User.GetUserId());
return RedirectToAction("Index");
}
catch (DbUpdateException)
{
ModelState.AddModelError(string.Empty, "Impossible d'enregistrer cette exception SIREN.");
}
}
return View(exceptionSIREN);
}
private static string NormalizeSiren(string? siren)
{
if (string.IsNullOrWhiteSpace(siren)) return string.Empty;
return new string(siren.Where(char.IsDigit).ToArray());
}
// GET: SIRENExceptions/Edit/5
public IActionResult Edit(string id)
{

View file

@ -63,9 +63,35 @@ namespace Yavsc.Controllers
.Where(a => a.ParentCode == id)
.OrderByDescending(a => a.Rate).ToList();
var candidateCodes = toShow
.Select(a => a.Code)
.Concat(toShow.SelectMany(a => (a.Children ?? new List<Yavsc.Models.Workflow.Activity>())
.Where(c => !c.Hidden)
.Select(c => c.Code)))
.Where(c => !string.IsNullOrWhiteSpace(c))
.Distinct()
.ToArray();
var performerCounts = _dbContext.UserActivities
.Where(ua => candidateCodes.Contains(ua.DoesCode))
.GroupBy(ua => ua.DoesCode)
.Select(g => new { Code = g.Key, Count = g.Select(x => x.UserId).Distinct().Count() })
.ToDictionary(x => x.Code, x => x.Count);
toShow = toShow
.Where(a =>
(performerCounts.TryGetValue(a.Code, out var ownCount) && ownCount > 0)
|| (a.Children ?? new List<Yavsc.Models.Workflow.Activity>())
.Where(c => !c.Hidden)
.Any(c => performerCounts.TryGetValue(c.Code, out var childCount) && childCount > 0))
.ToList();
foreach (var a in toShow)
{
a.Children = a.Children.Where(c => !c.Hidden).ToList();
a.Children = (a.Children ?? new List<Yavsc.Models.Workflow.Activity>())
.Where(c => !c.Hidden)
.Where(c => performerCounts.TryGetValue(c.Code, out var childCount) && childCount > 0)
.ToList();
}
return View(toShow);
}