コード例 #1
0
        public override async Task <Article> CreateArticle(string authedUsername, NewArticle newArticle)
        {
            var transaction = _context.Database.BeginTransaction();

            try
            {
                IdentityUser author = await _userManager.FindByNameAsync(authedUsername);

                String     authorId       = author.Id;
                ArticleDAO createdArticle = _articleRepository.CreateArticle(
                    title: newArticle.Title,
                    description: newArticle.Description,
                    body: newArticle.Body,
                    authorId: authorId);
                _context.SaveChanges();
                List <TagDAO> tags = _tagsRepository.SaveTags(newArticle.TagList);
                _context.SaveChanges();
                _articleTagsRepository.SaveArticleTags(tags.Select(e => e.Id).ToList(), createdArticle.Id);
                _context.SaveChanges();
                Article article = await CreateArticleFromDAO(createdArticle, authedUsername);

                transaction.Commit();
                return(article);
            } catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
        }
            public void OnActionExecuting(ActionExecutingContext context)
            {
                NewArticleHolder articleHolder = context.ActionArguments["newArticle"] as NewArticleHolder;

                if (null == articleHolder)
                {
                    InvalidateRequest(context, "No article holder is present", _logger, 422);
                    return;
                }
                NewArticle article = articleHolder.Article;

                if (null == article)
                {
                    InvalidateRequest(context, "There is no article in the holder", _logger, 422);
                    return;
                }
                if (!context.ModelState.IsValid)
                {
                    List <string> errors = context
                                           .ModelState
                                           .Values
                                           .SelectMany(e => e.Errors)
                                           .Select(e => e.ErrorMessage)
                                           .Distinct()
                                           .Cast <string>()
                                           .ToList();
                    InvalidateRequest(context, errors, _logger, 422);
                }
            }
コード例 #3
0
        public ActionResult Create(NewArticle newArticle)
        {
            DataBaseTegs          dataBaseTeg           = new DataBaseTegs();
            DataBaseArticles      dataBaseArticles      = new DataBaseArticles();
            DataBaseArticles_Tegs dataBaseArticles_Tegs = new DataBaseArticles_Tegs();

            newArticle.Article.Category_Id = newArticle.CategoryId;
            newArticle.Article.DateTime    = DateTime.Now;
            int id_article = dataBaseArticles.Insert(newArticle.Article);

            string[] tegs = newArticle.Tegs.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string teg in tegs)
            {
                int id_teg = dataBaseTeg.Insert("#" + teg);
                dataBaseArticles_Tegs.Insert(id_article, id_teg);
            }

            DataBaseCategories dataBaseCategory = new DataBaseCategories();
            NewArticle         newArticle1      = new NewArticle
            {
                Categories = new SelectList(dataBaseCategory.Select(), "Category_Id", "Name")
            };

            return(RedirectToAction("Index", "Home"));
        }
コード例 #4
0
        private void SelectedItem(object sender, MouseButtonEventArgs e)
        {
            var index = listBox1.SelectedIndex;

            var newStory = new NewArticle();

            newStory.brzr.Navigate(articlesParsed.articles[index].url.ToString());

            newStory.Show();
        }
コード例 #5
0
        public ViewResult Create()
        {
            DataBaseCategories dataBaseCategory = new DataBaseCategories();
            NewArticle         newArticle       = new NewArticle
            {
                Categories = new SelectList(dataBaseCategory.Select(), "Category_Id", "Name")
            };

            return(View(newArticle));
        }
コード例 #6
0
 public ActionResult Create(NewArticle article)
 {
     if (ModelState.IsValid)
     {
         // add model to database
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("New", new Article {
             Title = article.Title, Url = article.Url, Tags = article.Tags
         }));
     }
 }
コード例 #7
0
        private void SelectedItem(object sender, MouseButtonEventArgs e)
        {
            for (int i = 0; i < articlesParsed.articles.Count(); i++)
            {
                if ((string)listBox1.SelectedItem == articlesParsed.articles[i].title.ToString())
                {
                    var newStory = new NewArticle();

                    newStory.brzr.Navigate(articlesParsed.articles[i].url.ToString());

                    newStory.Show();
                    index = i;
                }
            }
        }
コード例 #8
0
        public async Task <Article> CreateArticleAsync(NewArticle article, string token, CancellationToken cancellationToken = default)
        {
            var body = new NewArticleRequest {
                Article = article
            };
            var requestBody = JsonSerializer.Serialize(body, _jsonSerializerOptions);
            var httpRequest = new HttpRequestMessage(HttpMethod.Post, new Uri($"api/articles", UriKind.Relative))
            {
                Content = new StringContent(requestBody, Encoding.UTF8, "application/json")
            };

            httpRequest.Headers.Add("Authorization", $"Token {token}");

            var response = await HandleRequest <ArticleObject>(httpRequest, cancellationToken);

            return(response.Article);
        }
コード例 #9
0
        public ActionResult Add(NewArticle data)
        {
            if (ModelState.IsValid)
            {
                ArticleModel art = new ArticleModel();
                art.Name    = data.Name;
                art.Title   = data.Title;
                art.Content = data.Content;
                art.Time    = DateTime.Now;

                ArticleOperate artOp      = new ArticleOperate();
                int            Article_Id = artOp.addArticle(art);

                ArticleToTagModel artTag = new ArticleToTagModel();
                artTag.Article_Id = Article_Id;
                artTag.Tag_Id     = data.Tag_Id;

                ArticleToTagOperate artToTag = new ArticleToTagOperate();
                artToTag.insert(artTag);
            }
            return(RedirectToAction("Index", "TagClass", new { id = data.Tag_Id }));
        }
コード例 #10
0
 public abstract Task <Article> CreateArticle(String authedUsername, NewArticle newArticle);
コード例 #11
0
 public NewArticleHolder(NewArticle article)
 {
     Article = article;
 }