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);
}

View file

@ -62,7 +62,7 @@
<label asp-for="Active" class="col-md-2 control-label">ActivateMyProSettings</label>
<div>
<input asp-for="Active" class="form-control" />
<input class="form-check-input" type="checkbox" asp-for="Active" class="form-control" />
<span asp-validation-for="Active" class="text-danger"></span>
</div>

View file

@ -5,21 +5,28 @@
}
<form asp-action="Create" method="post">
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Exception SIREN</h4>
<hr />
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group mb-3">
<label asp-for="SIREN" class="control-label">SIREN</label>
<input asp-for="SIREN" class="form-control" maxlength="9" pattern="[0-9]{9}" inputmode="numeric" autocomplete="off" />
<span asp-validation-for="SIREN" class="text-danger"></span>
</div>
<div class="form-group">
@Html.TextBox("SIREN")
<div class="col-md-offset-1 col-md-10">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</div>
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</div>
</form>
<div>
<a asp-action="Index">Back to List</a>
</div>
</div>
@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}