29 lines
918 B
C#
29 lines
918 B
C#
using DigitalOps.Authority.Services;
|
|
using DigitalOps.CQRS.Services.Project.Options;
|
|
using DigitalOps.Dal;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace DigitalOps.CQRS.Services.Project;
|
|
|
|
public class ProjectService(MainDbContext dbContext, UserIdentityService userIdentityService)
|
|
{
|
|
public async Task AddProjectAsync(AddProjectOptions options, CancellationToken cancellationToken)
|
|
{
|
|
var user = await userIdentityService.GetUserOrDefaultAsync(cancellationToken);
|
|
if (null == user)
|
|
return;
|
|
|
|
var client = await dbContext.Clients.FirstOrDefaultAsync(client => client.Id == options.ClientId, cancellationToken);
|
|
if (null == client)
|
|
return;
|
|
|
|
var project = new Dal.DbEntity.Project
|
|
{
|
|
Name = options.Name,
|
|
Client = client
|
|
};
|
|
|
|
await dbContext.Projects.AddAsync(project, cancellationToken);
|
|
await dbContext.SaveChangesAsync(cancellationToken);
|
|
}
|
|
} |