Beispiel #1
0
        public async Task <IActionResult> Autor(long id)
        {
            Autor autor = await _oak.Autors.FirstOrDefaultAsync(a => a.ID == id);

            if (autor == null)
            {
                return(RedirectToAction("Error", "Articles"));
            }

            await _oak.Entry(autor).Collection(a => a.Articles)
            .Query()
            .OrderByDescending(ar => ar.Date)
            .Take(3)
            .Include(ar => ar.Section)
            .Include(ar => ar.ArtTexts.Take(1))
            .Include(ar => ar.ArtImages.Take(1))
            .LoadAsync();

            await _oak.Entry(autor).Collection(a => a.Sections)
            .Query()
            .Include(s => s.Parent)
            .LoadAsync();

            ViewBag.CountOfArticles = _oak.Articles.Where(a => a.AutorID == autor.ID).Count();
            ViewBag.CountOfSections = _oak.Sections.Where(a => a.AutorID == autor.ID).Count();

            ViewBag.Title = $"Автор - {autor.Name}";
            return(View(autor));
        }
Beispiel #2
0
        public async Task <IActionResult> Section(long?id)
        {
            Section model = await _oak.Sections.FirstOrDefaultAsync(s => s.ID == id);

            if (model == null)
            {
                return(RedirectToAction("Error", "Articles"));
            }

            await _oak.Entry(model).Reference(m => m.Parent).LoadAsync();

            await _oak.Entry(model).Reference(m => m.Autor).LoadAsync();

            await _oak.Entry(model).Collection(m => m.Children)
            .Query()
            .OrderByDescending(s => s.Articles.Count)
            .Take(5)
            .Include(s => s.Autor)
            .LoadAsync();

            await _oak.Entry(model).Collection(m => m.Articles)
            .Query()
            .OrderByDescending(a => a.Date)
            .Take(3)
            .Include(a => a.Autor)
            .Include(a => a.ArtTexts.Take(1))
            .Include(a => a.ArtImages.Take(1))
            .LoadAsync();

            ViewBag.CountOfArticles = _oak.Articles.Where(a => a.SectionID == model.ID).Count();

            ViewBag.Title = $"Ветвь - {model.Name}";
            return(View(model));
        }
        public async Task <IActionResult> EditCreate(long?id)
        {
            SectionEditedModel model = new SectionEditedModel();

            if (id != null)
            {
                Autor autor = await _oak.Autors.FirstOrDefaultAsync(a => a.Email == User.Identity.Name);

                if (autor is null)
                {
                    return(RedirectToAction("All", "Articles"));
                }

                Section section = await _oak.Sections.FirstOrDefaultAsync(s => s.ID == id);

                if (section is null)
                {
                    return(RedirectToAction("Error", "Articles"));
                }

                if (section.AutorID != autor.ID)
                {
                    return(RedirectToAction("All", "Articles"));
                }


                await _oak.Entry(section).Reference(s => s.Parent).LoadAsync();

                ViewBag.ParentName = (section.Parent is null) ? "..." : section.Parent.Name;
                model.FromSection(section);
            }
            else
            {
                ViewBag.ParentName = "...";
            }

            ViewBag.Source = -1;
            ViewBag.Title  = "Работа над ветвью";
            return(View(model));
        }
        public async Task <IActionResult> EditCreate(long?id)
        {
            ArticleEditedModel model   = new ArticleEditedModel();
            Section            section = await _oak.Sections.FirstAsync();

            model.Section       = section.ID;
            ViewBag.SectionName = section.Name;

            if (id != null)
            {
                var autor = await _oak.Autors.FirstOrDefaultAsync(a => a.Email == User.Identity.Name);

                if (autor is null)
                {
                    return(RedirectToAction("All", "Articles"));
                }

                var article = await _oak.Articles.FirstOrDefaultAsync(a => a.ID == id);

                if (article is null)
                {
                    return(RedirectToAction("Error", "Articles"));
                }

                if (autor.ID != article.AutorID)
                {
                    return(RedirectToAction("Autor", "Autors", new { autor.ID }));
                }


                _oak.Entry(article).Collection(a => a.ArtTexts).Load();
                _oak.Entry(article).Collection(a => a.ArtSubtitles).Load();
                _oak.Entry(article).Collection(a => a.ArtImages).Load();

                await _oak.Entry(article).Reference(s => s.Section).LoadAsync();

                ViewBag.SectionName = article.Section.Name;

                model.FromArticle(article);
            }
            ViewBag.Source = -1;
            ViewBag.Title  = "Работа над статьей";
            return(View(model));
        }
Beispiel #5
0
        public async Task <IActionResult> Article(long?id)
        {
            var model = await _oak.Articles.FirstOrDefaultAsync(m => m.ID == id);

            if (model is null)
            {
                return(RedirectToAction("Error", "Articles"));
            }

            await _oak.Entry(model).Reference(m => m.Autor).LoadAsync();

            await _oak.Entry(model).Reference(m => m.Section).LoadAsync();

            await _oak.Entry(model).Collection(m => m.ArtTexts).LoadAsync();

            await _oak.Entry(model).Collection(m => m.ArtSubtitles).LoadAsync();

            await _oak.Entry(model).Collection(m => m.ArtImages).LoadAsync();

            List <(string Type, short Number, byte[] Data)> content = new List <(string Type, short Number, byte[] Data)>();

            content.AddRange(model.ArtTexts.Select(at => ("text", at.Number, at.Text)));
            content.AddRange(model.ArtSubtitles.Select(at => ("sub", at.Number, at.Subtitle)));
            content.AddRange(model.ArtImages.Select(at => ("img", at.Number, at.Image)));
            ViewBag.Content = content.OrderBy(e => e.Number).ToList();

            model.Views++;
            await _oak.SaveChangesAsync();

            ViewBag.Title = $"Статья - {model.Name}";
            return(View(model));
        }