Beispiel #1
0
        public ActionResult Create(ArticlesModel article)
        {
            if (ModelState.IsValid)
            {
                var articleDetails = new NewsArticle
                {
                    headline         = article.headline,
                    CategoryID       = article.CategoryID,
                    extract          = article.extract,
                    encoding         = article.encoding,
                    tags             = article.tags,
                    priority         = article.priority,
                    byLine           = article.byLine,
                    source           = article.source,
                    text             = article.text,
                    createdDate      = DateTime.Now,
                    lastModifiedDate = DateTime.Now,
                    publishDate      = DateTime.Now,
                    photoURL         = article.photoURL
                };

                var articlesCategory = new NewsArticleCategory();

                using (var context = new TechFireFlyDbContext())
                {
                    context.NewsArticles.Add(articleDetails);
                    //articlesCategory.newsArticleID = articleDetails.id;
                    //articlesCategory.newsCategoryID = article.newsCategoryID;
                    //context.NewsArticleCategories.Add(articlesCategory);
                    context.SaveChanges();
                };

                if (articleDetails.id > 0)
                {
                    return(RedirectToAction("Index", "NewsArticles"));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm tin tức không thành công!");
                }
            }

            return(View());
        }
Beispiel #2
0
 public long Insert(NewsArticle entity)
 {
     db.NewsArticles.Add(entity);
     db.SaveChanges();
     return(entity.id);
 }
Beispiel #3
0
 public long Insert(User entity)
 {
     db.Users.Add(entity);
     db.SaveChanges();
     return(entity.ID);
 }
Beispiel #4
0
 public long Insert(NewsCategory entity)
 {
     db.NewsCategories.Add(entity);
     db.SaveChanges();
     return(entity.id);
 }