public async Task <ActionResult <PublicationViewModel> > CreatePublication( PublicationSaveViewModel publication) { return(await _publicationService .CreatePublication(publication) .HandleFailuresOrOk()); }
public IActionResult CreatePublication([FromBody] PublicationInputModel body) { if (!ModelState.IsValid) { throw new ModelFormatException("Model not properly formatted"); } var entity = _publicationService.CreatePublication(body); return(CreatedAtRoute("GetPublicationById", new { publicationId = entity.Id }, null)); }
public async Task <PublicationViewModel> CreatePublication(NewPostRequest request, User user) { var extractor = new X.Web.MetaExtractor.Extractor(); var metadata = await extractor.ExtractAsync(request.Link); var existingPublication = await _publicationService.Get(new Uri(metadata.Url)); if (existingPublication != null) { throw new DuplicateNameException("Publication with this URL already exist"); } var languageCode = _languageAnalyzer.GetTextLanguage(metadata.Description); var languageId = await _localizationService.GetLanguageId(languageCode) ?? Core.Language.EnglishId; var player = EmbeddedPlayerFactory.CreatePlayer(request.Link); var playerCode = player != null ? await player.GetEmbeddedPlayerUrl(request.Link) : null; var publication = await _publicationService.CreatePublication( metadata, user.Id, languageId, playerCode, request.CategoryId, request.Comment); if (publication != null) { var model = new PublicationViewModel(publication, _settings.WebSiteUrl); //If we can embed main content into site page, so we can share this page. var url = string.IsNullOrEmpty(model.EmbeddedPlayerCode) ? model.RedirectUrl : model.ShareUrl; var services = await GetServices(publication); foreach (var service in services) { await service.Send(request.Comment, url, GetTags(request)); } return(model); } throw new Exception("Can't save publication to database"); }
public async Task <ActionResult <PublishResponse> > PublishRepository([FromBody] PublishInfo publishInfo) { IVcsService vcsService; switch (publishInfo.versionControl) { case "git": vcsService = gitHubService; break; case "svn": vcsService = subversionService; break; default: vcsService = gitHubService; break; } Snapshot snapshot; try { snapshot = vcsService.GetRepositorySnapshot(publishInfo.repoURL, publishInfo.repoName, publishInfo.snapshotId, HttpContext.TraceIdentifier.Replace(':', '.')); } catch (Exception e) { return(BadRequest(new ErrorResponse() { message = $"An error occurred while accessing the repository at {publishInfo.repoURL}. Please make sure the repository is publicly accessible." })); } Publication duplicate = publicationService.FindDuplicatePublication(snapshot.checksum); if (duplicate != null) { return(BadRequest(new DuplicatePublicationResponse() { message = $"This repository has already been published.", duplicatePublicationUrl = duplicate.PublicationUrl })); } IPublishingService publishingService; switch (publishInfo.publishingSystem) { case "b2share": publishingService = b2ShareService; break; case "figshare": publishingService = figshareService; break; case "dataverse": publishingService = dataverseService; break; default: publishingService = b2ShareService; break; } Response response = await publishingService.PublishRepository(snapshot.zippedBytes, publishInfo); if (response is PublishResponse) { publicationService.CreatePublication(publishInfo.repoURL, ((PublishResponse)response).publishUrl, publishInfo.metaData.open_access, snapshot.checksum); return(Ok(response)); } else if (response is PublishErrorResponse) { return(BadRequest(response)); } return(BadRequest(new ErrorResponse() { message = "Unknown error occurred." })); }