Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions backend/LexBoxApi/Services/ProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,33 @@ public async Task<Guid> CreateProject(CreateProjectInput input)
FlexProjectMetadata = input.Type == ProjectType.FLEx ? new() : null
});
// Also delete draft project, if any
await dbContext.DraftProjects.Where(dp => dp.Id == projectId).ExecuteDeleteAsync();
if (draftProject is not null)
{
dbContext.DraftProjects.Remove(draftProject);
}

var manager = input.ProjectManagerId.HasValue ? await dbContext.Users.FindAsync(input.ProjectManagerId.Value) : null;
manager?.UpdateCreateProjectsPermission(ProjectRole.Manager);

await dbContext.SaveChangesAsync();
await hgService.InitRepo(input.Code);
InvalidateProjectOrgIdsCache(projectId);
InvalidateProjectConfidentialityCache(projectId);
InvalidateProjectCodeCache(input.Code);
try
{
await hgService.InitRepo(input.Code);
InvalidateProjectOrgIdsCache(projectId);
InvalidateProjectConfidentialityCache(projectId);
InvalidateProjectCodeCache(input.Code);
await transaction.CommitAsync();
}
catch
{
// CommitAsync() did not run [successfully], so we don't want a repo to exist
await hgService.DeleteRepo(input.Code);
throw;
}
if (draftProject != null && manager != null)
{
await emailService.SendApproveProjectRequestEmail(manager, input);
}
await transaction.CommitAsync();
return projectId;
}

Expand Down
Loading