public async Task <IActionResult> Edit(int id, [Bind("ArticleAuthorId,AuthorId,ArticleId,AuthorPart")] ArticleAuthor articleAuthor)
        {
            if (id != articleAuthor.ArticleAuthorId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(articleAuthor);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ArticleAuthorExists(articleAuthor.ArticleAuthorId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ArticleId"] = new SelectList(_context.Articles, "ArticleId", "ArticleId", articleAuthor.ArticleId);
            ViewData["AuthorId"]  = new SelectList(_context.Author, "AuthorId", "AuthorId", articleAuthor.AuthorId);
            return(View(articleAuthor));
        }
Пример #2
0
        internal static ArticleAuthor Deserialize(XElement element)
        {
            if (element == null)
            {
                return(null);
            }

            var ns     = element.GetDefaultNamespace();
            var name   = element.Element(ns + "name");
            var uri    = element.Element(ns + "uri");
            var avatar = element.Element(ns + "avatar");

            if (name == null || uri == null)
            {
                return(null);
            }

            var articleAuthor = new ArticleAuthor
            {
                Name = name.Value,
                Uri  = new Uri(uri.Value, UriKind.Absolute)
            };

            if (avatar != null && avatar.IsEmpty == false)
            {
                articleAuthor.Avator = new Uri(avatar.Value, UriKind.Absolute);
            }
            return(articleAuthor);
        }
        public async Task <IActionResult> Create([Bind("ArticleAuthorId,AuthorId,ArticleId,AuthorPart")] ArticleAuthor articleAuthor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(articleAuthor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ArticleId"] = new SelectList(_context.Articles, "ArticleId", "ArticleId", articleAuthor.ArticleId);
            ViewData["AuthorId"]  = new SelectList(_context.Author, "AuthorId", "AuthorId", articleAuthor.AuthorId);
            return(View(articleAuthor));
        }
        /// <summary>
        /// Добавляет статью пользователя userName
        /// </summary>
        /// <param name="article"></param>
        /// <param name="userName"></param>
        public void CreateArticle(Article article, string userName)
        {
            if (article.ArticleId != 0)
            {
                return;
            }

            AppUser appUser = GetAppUser(userName);
            Author  author  = appUser.Author.FirstOrDefault();

            if (author == null)
            {
                author = new Author
                {
                    AppUserId  = appUser.Id,
                    AuthorName = appUser.GetFullName
                };
                _context.Author.Add(author);
                //_context.SaveChanges();
            }
            if (author.AuthorId == 0)
            {
                return;
            }

            _context.Articles.Add(article);

            ArticleAuthor articleAuthor = new ArticleAuthor
            {
                ArticleId  = article.ArticleId,
                AuthorId   = author.AuthorId,
                AuthorPart = 1
            };

            _context.ArticleAuthors.Add(articleAuthor);
            _context.SaveChanges();
        }
Пример #5
0
        private void Blogreader()
        {
            ContextFactory         cfact   = new ContextFactory();
            AggregatorDBContext    adbcont = cfact.CreateDbContext(new string[] { "", "" });
            ICollection <Author>   authors = new List <Author>();
            ICollection <Category> cats    = new List <Category>();

            List <Blog> blogs = new List <Blog>();

            blogs = adbcont.Blogs.ToList();
            foreach (Blog b in blogs)
            {
                string blogURL = b.BlogURL;
                var    reader  = XmlReader.Create(blogURL);
                var    feed    = SyndicationFeed.Load(reader);

                foreach (SyndicationItem article in feed.Items)
                {
                    Post post = adbcont.Posts.FirstOrDefault(a => a.PostTitle == article.Title.Text && a.Lastupdated == article.LastUpdatedTime);

                    if (post == null)
                    {
                        Post post1 = new Post();
                        List <ArticleAuthor>   aa = new List <ArticleAuthor>();
                        List <ArticleCategory> ac = new List <ArticleCategory>();
                        post1.ArticleAuthors    = aa;
                        post1.ArticleCategories = ac;


                        post1.Lastupdated     = article.LastUpdatedTime.UtcDateTime;
                        post1.PostDateCreated = article.PublishDate.UtcDateTime;
                        ICollection <SyndicationLink> links = new List <SyndicationLink>();
                        links = article.Links;
                        foreach (SyndicationLink l in links)
                        {
                            post1.absURI = l.GetAbsoluteUri().AbsoluteUri;
                        }
                        if (article.Title.Text.Length >= 60)
                        {
                            post1.PostTitle = article.Title.Text.Substring(0, 59);
                        }
                        else
                        {
                            post1.PostTitle = article.Title.Text;
                        }
                        post1.BlogID = b.BlogID;

                        if (article.Summary.Text.Length > 999)
                        {
                            post1.Summary = article.Summary.Text.Substring(0, 998);
                        }
                        else
                        {
                            post1.Summary = article.Summary.Text;
                        }


                        foreach (SyndicationPerson author in article.Authors)
                        {
                            Author        author1 = (Author)adbcont.Authors.FirstOrDefault(a => a.AuthorName == author.Name && a.AuthorEmail == author.Email);
                            ArticleAuthor aaa     = new ArticleAuthor();

                            if (author1 == null)
                            {
                                author1             = new Author();
                                author1.AuthorEmail = author.Email;
                                author1.AuthorName  = author.Name;
                                author1.AuthorURI   = author.Uri;
                                adbcont.Authors.Add(author1);
                            }

                            aaa.Posts   = post;
                            aaa.Authors = author1;
                            post1.ArticleAuthors.Add(aaa);
                        }
                        foreach (SyndicationCategory cat in article.Categories)
                        {
                            if (cat != null && !string.IsNullOrEmpty(cat.Name) && cat.Name != "NULL")
                            {
                                Category        category1 = adbcont.Categories.FirstOrDefault(a => a.CategoryName == cat.Name && a.Label == cat.Label);
                                ArticleCategory acc       = new ArticleCategory();

                                if (category1 == null)
                                {
                                    Category category = new Category();
                                    category.CategoryName = cat.Name;
                                    category.Label        = cat.Label;
                                    adbcont.Categories.Add(category);
                                    acc.Categories = category;
                                    acc.Posts      = post1;
                                    post1.ArticleCategories.Add(acc);
                                }
                            }
                        }
                        adbcont.Posts.Add(post1);
                        adbcont.SaveChanges();
                    }
                }
            }
        }