Added tooling
This commit is contained in:
@@ -15,17 +15,6 @@ public sealed class ProjectService(IDbContextFactory<ApplicationDbContext> conte
|
||||
{
|
||||
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||
|
||||
var project = await context.Projects.FirstOrDefaultAsync(p => p.Id == request.ProjectId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
return Result.Fail(NotFoundError.New);
|
||||
|
||||
project.Status = request.Status;
|
||||
project.UpdatedBy = userId;
|
||||
project.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
context.Projects.Update(project);
|
||||
|
||||
var changedTotal = await context.Projects
|
||||
.Where(p => p.Id != request.ProjectId)
|
||||
.ExecuteUpdateAsync(f => f
|
||||
@@ -91,17 +80,21 @@ public sealed class ProjectService(IDbContextFactory<ApplicationDbContext> conte
|
||||
{
|
||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||
|
||||
if (await context.Projects.AnyAsync(p => p.Name == request.Name && p.Sector == request.Sector && p.ProjectType == request.ProjectType, cancellationToken))
|
||||
var name = request.Name.Humanize(LetterCasing.Title).Trim();
|
||||
|
||||
if (await context.Projects.AnyAsync(p => p.Name == name && p.Sector == request.Sector && p.ProjectType == request.ProjectType, cancellationToken))
|
||||
return Result.Fail(ValidationError.Create("A similarly named project exists of the same project type and sector"));
|
||||
|
||||
if (!await context.Programmes.AnyAsync(p => p.Id == request.ProgrammeId, cancellationToken))
|
||||
return Result.Fail(NotFoundError.New);
|
||||
|
||||
var description = request.Description.Humanize(LetterCasing.Sentence).Trim();
|
||||
|
||||
context.Projects.Add(new Domain.Entities.Project
|
||||
{
|
||||
ProgrammeId = request.ProgrammeId,
|
||||
Name = request.Name,
|
||||
Description = request.Description,
|
||||
Name = name,
|
||||
Description = description,
|
||||
Sector = request.Sector,
|
||||
ProjectType = request.ProjectType,
|
||||
Status = ApprovalStatus.Pending,
|
||||
@@ -130,7 +123,7 @@ public sealed class ProjectService(IDbContextFactory<ApplicationDbContext> conte
|
||||
MilestoneId = request.MilestoneId,
|
||||
Category = request.Category,
|
||||
Amount = request.Amount,
|
||||
Title = request.Title,
|
||||
Title = request.Title.Humanize(LetterCasing.Title).Trim(),
|
||||
Description = request.Description,
|
||||
PerformedAt = request.PerformedAt,
|
||||
Status = ApprovalStatus.Pending,
|
||||
@@ -218,7 +211,7 @@ public sealed class ProjectService(IDbContextFactory<ApplicationDbContext> conte
|
||||
|
||||
var changedTotal = await context.Milestones.Where(m => m.Id == request.MilestoneId)
|
||||
.ExecuteUpdateAsync(f => f
|
||||
.SetProperty(u => u.Name, request.Name)
|
||||
.SetProperty(u => u.Name, request.Name.Humanize(LetterCasing.Title).Trim())
|
||||
.SetProperty(u => u.DueAt, request.DueAt)
|
||||
.SetProperty(u => u.Priority, request.Priority)
|
||||
.SetProperty(u => u.Status, request.Status)
|
||||
@@ -235,8 +228,8 @@ public sealed class ProjectService(IDbContextFactory<ApplicationDbContext> conte
|
||||
|
||||
var changedTotal = await context.Projects.Where(p => p.Id == request.ProjectId)
|
||||
.ExecuteUpdateAsync(f => f
|
||||
.SetProperty(u => u.Name, request.Name)
|
||||
.SetProperty(u => u.Description, request.Description)
|
||||
.SetProperty(u => u.Name, request.Name.Humanize(LetterCasing.Title).Trim())
|
||||
.SetProperty(u => u.Description, request.Description.Humanize(LetterCasing.Sentence).Trim())
|
||||
.SetProperty(u => u.StartedAt, request.StartedAt)
|
||||
.SetProperty(u => u.EndedAt, request.EndedAt)
|
||||
.SetProperty(u => u.UpdatedBy, userId)
|
||||
@@ -290,15 +283,15 @@ public sealed class ProjectService(IDbContextFactory<ApplicationDbContext> conte
|
||||
{
|
||||
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||
|
||||
if (!await context.Users.AnyAsync(u => u.Id == userId, cancellationToken))
|
||||
return Result.Fail(NotFoundError.New);
|
||||
var name = request.Name.Humanize(LetterCasing.Title).Trim();
|
||||
|
||||
if (await context.Programmes.AnyAsync(p => p.Name == request.Name, cancellationToken))
|
||||
if (await context.Programmes.AnyAsync(p => p.Name == name, cancellationToken))
|
||||
return Result.Fail(ValidationError.Create("Programme of the same name exists"));
|
||||
|
||||
context.Programmes.Add(new Domain.Entities.Programme
|
||||
{
|
||||
OwnedBy = request.OwnerId,
|
||||
Name = name,
|
||||
CreatedBy = userId,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
Status = ApprovalStatus.Pending
|
||||
@@ -317,7 +310,7 @@ public sealed class ProjectService(IDbContextFactory<ApplicationDbContext> conte
|
||||
|
||||
var changedTotal = await context.Programmes.Where(p => p.Id == request.ProgrammeId)
|
||||
.ExecuteUpdateAsync(f => f
|
||||
.SetProperty(u => u.Name, request.Name)
|
||||
.SetProperty(u => u.Name, request.Name.Humanize(LetterCasing.Title).Trim())
|
||||
.SetProperty(u => u.OwnedBy, request.OwnerId)
|
||||
.SetProperty(u => u.Status, request.Status)
|
||||
.SetProperty(u => u.UpdatedBy, userId)
|
||||
|
||||
Reference in New Issue
Block a user