Exemplo n.º 1
0
    public async Task <Publication> CreatePublication(
        Metadata metadata,
        int userId,
        int languageId,
        string playerCode,
        int categoryId,
        string comment)
    {
        var image = metadata.Images.FirstOrDefault();

        var publication = new DAL.Publication
        {
            Title             = metadata.Title,
            Description       = X.Text.TextHelper.Substring(metadata?.Description, 4500, "..."),
            Link              = metadata.Url,
            Image             = string.IsNullOrWhiteSpace(image) || image.Length > 250 ? string.Empty : image,
            Type              = "article",
            DateTime          = DateTime.Now,
            UserId            = userId,
            CategoryId        = categoryId,
            Comment           = comment,
            LanguageId        = languageId,
            EmbededPlayerCode = playerCode
        };

        return(await _repository.Save(publication));
    }
Exemplo n.º 2
0
        public PublicationViewModel(DAL.Publication publication, string websiteUrl, IEnumerable <DAL.Category> categories = null)
        {
            _websiteUrl = websiteUrl;

            Id          = publication.Id;
            Title       = publication.Title;
            Description = publication.Description;
            Image       = publication.Image;
            Link        = publication.Link;
            DateTime    = publication.DateTime;
            Type        = publication.Type;
            Content     = publication.Content;

            if (publication.CategoryId.HasValue && categories != null && categories.Any())
            {
                var categoryName = categories
                                   .Where(o => o.Id == publication.CategoryId)
                                   .Select(o => o.Name)
                                   .FirstOrDefault();

                Category = new CategoryViewModel
                {
                    Id   = publication.CategoryId.Value,
                    Name = categoryName
                };
            }
        }