public Result <CreateProjectResponse> CreateProject(CreateProjectRequest request) { using var session = _apiDatabase.SessionFactory().OpenSession(); using var transaction = session.BeginTransaction(IsolationLevel.ReadCommitted); var urlSlug = SlugService.FromText(request.Title, request.UrlSlug); if (urlSlug.IsFailure) { return(Result <CreateProjectResponse> .From(urlSlug)); } var project = new ProjectRecord { Reference = Guid.NewGuid(), Title = request.Title, UrlSlug = urlSlug.Value, StartedAt = request.StartedAt, Summary = request.Summary, Description = request.Description, SourceCodeUrl = request.SourceCodeUrl, PreviewImageUrl = request.PreviewImageUrl, DisplayOrder = request.DisplayOrder, CreatedAt = DateTime.UtcNow, ViewUrl = request.ViewUrl, Tags = request.Tags }; session.Save(project); transaction.Commit(); var settingsResult = _projectsSettingsService.GetProjectsSettings(); if (settingsResult.IsFailure) { return(Result <CreateProjectResponse> .From(settingsResult)); } _projectsSettingsService.UpdateProjectsSettings(new UpdateProjectsSettingsRequest { DisplayOrder = settingsResult.Value.DisplayOrder .Select(x => x.Reference) .Concat(new [] { project.Reference }) .ToList() }); return(Result <CreateProjectResponse> .Of(new CreateProjectResponse { Reference = project.Reference, Title = project.Title, UrlSlug = project.UrlSlug, StartedAt = project.StartedAt, Summary = project.Summary, Description = project.Description, SourceCodeUrl = project.SourceCodeUrl, PreviewImageUrl = project.PreviewImageUrl, DisplayOrder = project.DisplayOrder, CreatedAt = project.CreatedAt, ViewUrl = project.ViewUrl, Tags = project.Tags })); }
public IActionResult GetProjectsSettings() { var result = _projectsSettingsService.GetProjectsSettings(); return(ToApiResponse(result)); }