コード例 #1
0
        public IActionResult AddArticlePost(ArticleAddEditModel model)
        {
            Result result = new Result("Makale kaydedildi", true, "");

            try
            {
                ArticleCore.AddEditArticle(model);
            }
            catch (Exception ex)
            {
                result = new Result("Makale kaydedilirken bir hata oluştu", false, ex.Message);
            }
            return(Json(result));
        }
コード例 #2
0
ファイル: ArticleCore.cs プロジェクト: kcakar/Law-Project
        public static void AddEditArticle(ArticleAddEditModel model)
        {
            Contributor contributor = ContributorCore.GetContributorsById(model.contributorID);

            Article article = new Article
            {
                Title         = model.title.CapitaliseFirstLetters(),
                ContributorID = model.contributorID,
                AffiliateID   = contributor.AffiliateID,
                CityID        = contributor.CityID,
                CountryID     = contributor.CountryID,
                CreationDate  = model.CreationDate,
                ID            = model.ID,
                BodyPreview   = model.preview
            };

            article.LanguageID     = "Turkish";
            article.PracticeAreaID = model.practiceAreaID;
            article.Tags           = model.tags;

            foreach (ArticleParagraphRow row in model.paragraphs)
            {
                if (string.IsNullOrEmpty(row.ID))
                {
                    row.ID = Guid.NewGuid().ToString();
                }
                ArticlePiece piece = new ArticlePiece
                {
                    ArticleId = article.ID,
                    ID        = row.ID
                };
                piece.ImagePosition = piece.SetImagePosition(row.imagePosition);
                if (row.imageURL == null)
                {
                    row.imageURL = "";
                }
                piece.ImageUrl  = row.imageURL.Replace("~", "");
                piece.Paragraph = row.content;
                piece.Title     = row.title;

                if (!Tester.TestArticlePieces.Exists(x => x.ID == piece.ID))
                {
                    Tester.TestArticlePieces.Add(piece);
                }
                else
                {
                    //dbde update normalde
                    Tester.TestArticlePieces.RemoveAll(x => x.ID == piece.ID);
                    Tester.TestArticlePieces.Add(piece);
                }
            }

            //ID mevcutsa güncelle, yoksa ekle
            if (!Tester.TestArticles.Exists(x => x.ID != article.ID))
            {
                Tester.TestArticles.Add(article);
            }
            else
            {
                //dbde update normalde
                Tester.TestArticles.RemoveAll(x => x.ID == model.ID);
                Tester.TestArticles.Add(article);
            }
        }