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 <PublicationTitleViewModel> > GetPublicationTitle(string slug)
 {
     return(await _publicationService.Get(slug)
            .OnSuccess(p => new PublicationTitleViewModel
     {
         Id = p.Id,
         Title = p.Title,
     })
            .HandleFailuresOrOk());
 }
        public async Task <Either <ActionResult, ReleaseViewModel> > Get(string publicationSlug, string?releaseSlug = null)
        {
            return(await _publicationService.Get(publicationSlug)
                   .OnSuccessCombineWith(publication => _methodologyService.GetSummariesByPublication(publication.Id))
                   .OnSuccess(async tuple =>
            {
                var(publication, methodologies) = tuple;
                return await GetCachedRelease(publicationSlug, releaseSlug)
                .OnSuccess(cachedRelease =>
                {
                    var result = new ReleaseViewModel(
                        _mapper.Map <CachedReleaseViewModel>(cachedRelease),
                        _mapper.Map <PublicationViewModel>(publication)
                        );

                    result.Publication.Methodologies = methodologies;
                    return result;
                });
            }));
        }
        public ActionResult Upsert(PublicationType?type = null, Guid?id = null, string sessionId = null)
        {
            PublicationUpsertViewModel model;

            if (id.HasValue)
            {
                using (ContextManager.NewConnection())
                {
                    model = Mapper.Map <PublicationUpsertViewModel>(publicationService.Get(id.Value, true));
                }

                sessionStorageService.Upsert(model);
            }
            else if (sessionId.IsNotNullOrEmpty())
            {
                model = sessionStorageService.Get <PublicationUpsertViewModel>(sessionId);
            }
            else if (type.HasValue)
            {
                if (!EnumHelper.PublicationTypes.ContainsKey(type.Value) || type.Value == PublicationType.None)
                {
                    throw new ArgumentOutOfRangeException("type");
                }

                model = new PublicationUpsertViewModel
                {
                    Type = new Nomenclature
                    {
                        Id = EnumHelper.GetPublicationType(type.Value)
                    }
                };
            }
            else
            {
                throw new WarningException(Resource.NoDataFound);
            }

            InitUpsertBreadcrumb(model);
            return(View(model));
        }
Exemplo n.º 5
0
 private async Task <ActionResult <PreReleaseAccessListViewModel> > GetViewModel(
     string publicationSlug,
     string?releaseSlug = null)
 {
     return(await _publicationService.Get(publicationSlug)
            .OnSuccessCombineWith(_ => _releaseService.GetCachedRelease(publicationSlug, releaseSlug))
            .OnSuccess(publicationAndRelease =>
     {
         var(publication, release) = publicationAndRelease;
         return new PreReleaseAccessListViewModel(release !, publication);
     })
            .HandleFailuresOrOk());
 }
Exemplo n.º 6
0
        public async Task <IActionResult> Post(int id)
        {
            var publication = await _publicationService.Get(id);

            await _publicationService.IncreaseViewCount(id);

            if (publication == null)
            {
                return(NotFound());
            }

            var categories = await _publicationService.GetCategories();

            var model = new PublicationViewModel(publication, _settings.WebSiteUrl, categories);

            ViewData["Title"] = model.Title;

            return(View("~/Views/Home/Post.cshtml", model));
        }
Exemplo n.º 7
0
        public async Task UpdatePublication(PublishContext context, Guid publicationId)
        {
            var publication = await _publicationService.Get(publicationId);

            await CacheTrees(context);
            await CachePublication(publication.Id, context);

            await _publicationService.SetPublishedDate(publication.Id, context.Published);

            if (publication.MethodologyId.HasValue)
            {
                var methodology = await _methodologyService.Get(publication.MethodologyId.Value);

                if (!methodology.Live)
                {
                    await CacheMethodology(methodology.Id, context);

                    await _methodologyService.SetPublishedDate(methodology.Id, context.Published);
                }
            }
        }