This commit is contained in:
Paul Schneider 2026-02-28 21:17:54 +00:00
commit 40e8e08690
3487 changed files with 39 additions and 21 deletions

View file

@ -0,0 +1,161 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Yavsc.Models;
using Yavsc.Server.Models.IT.SourceCode;
using Yavsc.Helpers;
using Microsoft.EntityFrameworkCore;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{
[Authorize("AdministratorOnly")]
public class GitController : Controller
{
private readonly ApplicationDbContext _context;
public GitController(ApplicationDbContext context)
{
_context = context;
}
[Route("~/Git/sources/{*path}")]
[HttpGet]
public IActionResult Sources(string path)
{
if (path == null)
{
return NotFound();
}
/*
GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Path == path);
if (gitRepositoryReference == null)
{
return NotFound();
}
*/
var info = Config.GitOptions.FileProvider.GetFileInfo(path);
if (!info.Exists)
return NotFound();
var stream = info.CreateReadStream();
if (path.EndsWith(".ansi.log"))
{
var accept = Request.Headers["Accept"];
if (accept.Any(v => v.Split(',').Contains("text/html")))
{
return File(AnsiToHtmlEncoder.GetStream(stream), "text/html");
}
return File(stream, "text/text");
}
if (path.EndsWith(".html")) return File(stream, "text/html");
if (path.EndsWith(".cshtml")) return File(stream, "text/razor-html-csharp");
if (path.EndsWith(".cs")) return File(stream, "text/csharp");
return File(stream, "application/octet-stream");
}
// GET: Git
[HttpGet]
public async Task<IActionResult> Index()
{
var applicationDbContext = _context.GitRepositoryReference.Include(g => g.Owner);
return View(await applicationDbContext.ToListAsync());
}
// GET: Git/Details/5
[HttpGet]
public async Task<IActionResult> Details(long id)
{
GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Id == id);
if (gitRepositoryReference == null)
{
return NotFound();
}
return View(gitRepositoryReference);
}
// GET: Git/Create
[HttpGet]
public IActionResult Create()
{
return View();
}
// POST: Git/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(GitRepositoryReference gitRepositoryReference)
{
gitRepositoryReference.OwnerId = User.GetUserId();
if (ModelState.IsValid)
{
_context.GitRepositoryReference.Add(gitRepositoryReference);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewData["OwnerId"] = new SelectList(_context.ApplicationUser, "Id", "Owner", gitRepositoryReference.OwnerId);
return View(gitRepositoryReference);
}
// GET: Git/Edit/5
[HttpGet]
public async Task<IActionResult> Edit(long id)
{
GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Id == id);
if (gitRepositoryReference == null)
{
return NotFound();
}
ViewBag.OwnerId = new SelectList(_context.ApplicationUser, "Id", "Owner", gitRepositoryReference.OwnerId);
return View(gitRepositoryReference);
}
// POST: Git/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(GitRepositoryReference gitRepositoryReference)
{
if (ModelState.IsValid)
{
_context.Update(gitRepositoryReference);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewData["OwnerId"] = new SelectList(_context.ApplicationUser, "Id", "Owner", gitRepositoryReference.OwnerId);
return View(gitRepositoryReference);
}
// GET: Git/Delete/5
[ActionName("Delete")]
[HttpGet]
public async Task<IActionResult> Delete(string id)
{
if (id == null)
{
return NotFound();
}
GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Path == id);
if (gitRepositoryReference == null)
{
return NotFound();
}
return View(gitRepositoryReference);
}
// POST: Git/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string id)
{
GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Path == id);
_context.GitRepositoryReference.Remove(gitRepositoryReference);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,166 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Yavsc.Models;
using Yavsc.Server.Models.IT;
using Microsoft.AspNetCore.Authorization;
using Yavsc.Server.Helpers;
using Yavsc.Models.Workflow;
using Yavsc.Models.Payment;
using Yavsc.Server.Models.IT.SourceCode;
using Microsoft.Extensions.Localization;
using Microsoft.EntityFrameworkCore;
namespace Yavsc.Controllers
{
[Authorize("AdministratorOnly")]
public class ProjectController : Controller
{
private readonly ApplicationDbContext _context;
readonly IStringLocalizer<ProjectController> _localizer;
readonly IStringLocalizer<BugController> _bugLocalizer;
public ProjectController(ApplicationDbContext context,
IStringLocalizer<ProjectController> localizer,
IStringLocalizer<BugController> bugLocalizer
)
{
_context = context;
_localizer = localizer;
_bugLocalizer = bugLocalizer;
}
// GET: Project
public async Task<IActionResult> Index()
{
var applicationDbContext = _context.Project.Include(p => p.Client).Include(p => p.Context).Include(p => p.PerformerProfile).Include(p => p.Regularisation).Include(p => p.Repository);
return View(await applicationDbContext.ToListAsync());
}
// GET: Project/Details/5
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
return NotFound();
}
Project project = await _context.Project.SingleAsync(m => m.Id == id);
if (project == null)
{
return NotFound();
}
return View(project);
}
// GET: Project/Create
public IActionResult Create()
{
ViewBag.ClientIdItems = _context.ApplicationUser.CreateSelectListItems<ApplicationUser>(
u => u.Id, u => u.UserName);
ViewBag.OwnerIdItems = _context.ApplicationUser.CreateSelectListItems<ApplicationUser>(
u => u.Id, u => u.UserName);
ViewBag.ActivityCodeItems = _context.Activities.CreateSelectListItems<Activity>(
a => a.Code, a => a.Name);
ViewBag.PerformerIdItems = _context.Performers.Include(p=>p.Performer).CreateSelectListItems<PerformerProfile>(p => p.PerformerId, p => p.Performer.UserName);
ViewBag.PaymentIdItems = _context.PayPalPayment.CreateSelectListItems<PayPalPayment>
(p => p.OrderReference, p => $"{p.Executor.UserName} {p.PaypalPayerId} {p.OrderReference}");
ViewBag.Status = _bugLocalizer.CreateSelectListItems(typeof(Yavsc.QueryStatus), Yavsc.QueryStatus.Inserted);
ViewBag.RepositoryItems = _context.GitRepositoryReference.CreateSelectListItems<GitRepositoryReference>(
u => u.Id.ToString(), u => u.ToString());
return View();
}
// POST: Project/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Project project)
{
if (ModelState.IsValid)
{
_context.Project.Add(project);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewBag.ClientIdItems = _context.ApplicationUser.CreateSelectListItems<ApplicationUser>(
u => u.Id, u => u.UserName, project.ClientId);
ViewBag.OwnerIdItems = _context.ApplicationUser.CreateSelectListItems<ApplicationUser>(
u => u.Id, u => u.UserName, project.OwnerId);
ViewBag.ActivityCodeItems = _context.Activities.CreateSelectListItems<Activity>(
a => a.Code, a => a.Name, project.ActivityCode);
ViewBag.PerformerIdItems = _context.Performers.Include(p=>p.Performer).CreateSelectListItems<PerformerProfile>(p => p.PerformerId, p => p.Performer.UserName, project.PerformerId);
ViewBag.PaymentIdItems = _context.PayPalPayment.CreateSelectListItems<PayPalPayment>
(p => p.OrderReference, p => $"{p.Executor.UserName} {p.PaypalPayerId} {p.OrderReference}", project.PaymentId);
return View(project);
}
// GET: Project/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return NotFound();
}
Project project = await _context.Project.SingleAsync(m => m.Id == id);
if (project == null)
{
return NotFound();
}
/* ViewBag.ClientId = new SelectList(_context.ApplicationUser, "Id", "Client", project.ClientId);
ViewBag.ActivityCodeItems = new SelectList(_context.Activities, "Code", "Context", project.ActivityCode);
ViewBag.PerformerId = new SelectList(_context.Performers, "PerformerId", "PerformerProfile", project.PerformerId);
ViewBag.PaymentId = new SelectList(_context.PayPalPayments, "CreationToken", "Regularisation", project.PaymentId);
ViewBag.Name = new SelectList(_context.GitRepositoryReference, "Path", "Repository", project.Name);
*/
ViewBag.Status = Yavsc.Extensions.EnumExtensions.GetSelectList(typeof(QueryStatus), _localizer, project.Status);
ViewBag.Repository = new SelectList(_context.GitRepositoryReference, "Path", "Repository", project.Repository);
return View(project);
}
// POST: Project/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(Project project)
{
if (ModelState.IsValid)
{
_context.Update(project);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(project);
}
// GET: Project/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
return NotFound();
}
Project project = await _context.Project.SingleAsync(m => m.Id == id);
if (project == null)
{
return NotFound();
}
return View(project);
}
// POST: Project/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
Project project = await _context.Project.SingleAsync(m => m.Id == id);
_context.Project.Remove(project);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}