Пример #1
0
        public async Task <IActionResult> OnGet(int textid)
        {
            await SetupFilter(new int[0]);

            if (textid != 0)
            {
                var article = await articleService.GetAsync(textid);

                if (!httpContextAccessor.HttpContext.User.IsInRole("Read") && article.Master.Status.Id != 1 && article.Master.Author.Id != userId)
                {
                    return(Page());
                }
                Article = new ViewModels.Article
                {
                    ArticleId = article.Id,
                    TextId    = article.Master.Id,
                    Category  = new ViewModels.CategoryFilter
                    {
                        Id       = article.Category.Id,
                        Category = article.Category.Category
                    },
                    Content = article.Master.Content,
                    Status  = new ViewModels.StatusFilter
                    {
                        Id     = article.Master.Status.Id,
                        Status = article.Master.Status.Status
                    },
                    Title  = article.Master.Title,
                    Author = new Author
                    {
                        Id    = article.Master.Author.Id,
                        Email = article.Master.Author.Email
                    },
                    Avatar = String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(article.Master.Avatar))
                };
                var tags = new List <TagFilter>();
                foreach (var tag in article.Master.Tags)
                {
                    tags.Add(new TagFilter
                    {
                        Id      = tag.Id,
                        Tag     = tag.Tag,
                        Checked = true
                    });
                    Filter.Tags.Where(x => x.Value == tag.Id.ToString()).Single().Selected = true;
                }
                Article.Tags    = tags;
                Article.Content = article.Master.Content;
                Article.Title   = article.Master.Title;
                Editing         = true;
            }
            else
            {
                Editing = false;
            }
            return(Page());
        }
Пример #2
0
        private Article CreateArticle(ArticleDetailsDto newArt)
        {
            Article article = new ViewModels.Article
            {
                ArticleId = newArt.Id,
                TextId    = newArt.Master.Id,
                Version   = newArt.Master.Version,
                Comment   = newArt.Master.TextComment,
                CreatedAt = newArt.Master.CreatedAt,
                Content   = newArt.Master.Content,
                Status    = new ViewModels.StatusFilter
                {
                    Id     = newArt.Master.Status.Id,
                    Status = newArt.Master.Status.Status
                },
                Title  = newArt.Master.Title,
                Author = new Author
                {
                    Id    = newArt.Master.Author.Id,
                    Email = newArt.Master.Author.Email
                }
            };

            if (newArt.Category != null)
            {
                article.Category = new CategoryFilter
                {
                    Id       = newArt.Category.Id,
                    Category = newArt.Category.Category
                };
            }
            if (newArt.Master.Avatar.Length != 0)
            {
                article.Avatar = String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(newArt.Master.Avatar));
            }
            if (newArt.Master.Supervisor != null)
            {
                article.Supervisor = new User
                {
                    Id    = newArt.Master.Supervisor.Id,
                    Email = newArt.Master.Supervisor.Email
                };
            }
            var tags = new List <TagFilter>();

            foreach (var tag in newArt.Master.Tags)
            {
                tags.Add(new TagFilter
                {
                    Id  = tag.Id,
                    Tag = tag.Tag
                });
            }
            article.Tags = tags;
            return(article);
        }
Пример #3
0
        public ActionResult Article(string article_link)
        {
            var dataModel = new DataModel();

            ViewModels.Article article = dataModel.Articles
                                         .Where(a => a.link == article_link.Replace(".aspx", ""))
                                         .Select(a => new ViewModels.Article(a))
                                         .FirstOrDefault();
            return(View(article));
        }