Beispiel #1
0
 public IActionResult Add(T_BLOG_CONTENT content)
 {
     try
     {
         //if (!ModelState.IsValid)
         //    return Content("<script> alert('博客内容有误,请检查博客内容!'); location.href='/Admin/Blog/Add'</script>", "text/html");
         int blogId = 0;
         //int userId = HttpContext.Session.GetInt32("userid") == null
         //    ? 1
         //    : int.Parse(HttpContext.Session.GetInt32("userid").ToString());
         int userId = int.Parse(User.Identities.First(u => u.IsAuthenticated)
                                .FindFirst(ClaimTypes.PrimarySid).Value);
         if (content.BlogID == 0)
         {
             content.CreateTIme  = DateTime.Now;
             content.CreateUser  = userId;
             content.LastUptTime = DateTime.Now;
             content.BlogState   = 1;
             blogId = _contentService.Insert(content);
         }
         else
         {
             blogId              = content.BlogID;
             content.UpdateUser  = userId;
             content.LastUptTime = DateTime.Now;
             content.BlogState   = 1;
             bool isSuccess = _contentService.Update(content);
             if (isSuccess)
             {
                 _relCateg.Delete(content.BlogID);
             }
         }
         if (blogId > 0)
         {
             _relCateg.Insert(blogId, content.CatelogID);
         }
         return(Redirect("/Admin/Blog/Index"));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(null);
     }
 }