Esempio n. 1
0
 public IActionResult Add(PageAddModel pageadd)
 {
     if (ModelState.IsValid)
     {
         var page = new Page
         {
             AddTime  = pageadd.AddTime,
             Identity = pageadd.Identity,
             Position = pageadd.Position,
             Age      = pageadd.Age,
             Hobby    = pageadd.Hobby,
             Name     = pageadd.Name,
             Content  = pageadd.Content
         };
         myDBContent.Add(page);
         int v = myDBContent.SaveChanges();
         if (v > 0)
         {
             return(RedirectToAction("/Manage/Page/Index"));
         }
         else
         {
             ModelState.AddModelError("Identity", "保存失败!");
         }
     }
     return(View());
 }//增
Esempio n. 2
0
 public IActionResult Add(NewsAddModel newsadd)
 {
     if (ModelState.IsValid)
     {
         var news = new News
         {
             AddTime = DateTime.Now,
             Title   = newsadd.Title,
             Content = newsadd.Content
         };
         myDBContent.Add(news);
         int v = myDBContent.SaveChanges();
         if (v > 0)
         {
             return(Redirect("/Manage/News/Index"));
         }
         else
         {
             ModelState.AddModelError("Title", "保存失败!");
         }
     }
     return(View());
 }