public bool UpdateHomeContent( HomeContent content ) { try { homeRepository.Update(content); Save(); return true; } catch { return false; } }
public int CreateHomeContent( HomeContent content ) { try { homeRepository.Add(content); Save(); return content.ID; } catch { return -1; } }
public JsonResult SubmitNews( string json ) { try { News news = JsonConvert.Import<News>(json); var cates = news.NewsCategories.ToList(); news.NewsCategories.Clear(); foreach (var cate in cates) { var temp = newsService.GetCategory(cate.ID); if (temp != null) news.NewsCategories.Add(temp); } if (string.IsNullOrEmpty(news.WebFrom)) { news.WebFrom = UserContext.Instance.User.NickName; news.WebFromAddress = string.Format("/user/{0}/", UserContext.Instance.UserID); } //if (UserContext.Instance.User.((int)SysRoles.NewsEditor)) { news.State = (int)RecordState.Approved; //} else { // news.CommentsCount = (int)RecordState.Pending; //} if (news.TopicID == 0) { news.TopicID = null; } news.CreateTime = DateTime.Now; news.CreatorID = UserContext.Instance.UserID; news.AnymousComment = false; news.EnableComment = true; news.LastChanged = DateTime.Now; int newsid = newsService.CreateNews(news); bool result = newsid > 0; if (result) { HomeContent content = new HomeContent(); content.Title = news.Title; content.LinkUrl = string.Format("/news/detail/{0}", newsid); content.ContentType = (int)HomeContentType.News; content.ContentData = news.Summary; content.InsertTime = DateTime.Now; homecontentService.CreateHomeContent(content); foreach (var auth in UserContext.Instance.User.OpenAuths) { switch ((OpenAuthType)auth.OpenAuthType) { case OpenAuthType.Sinaweibo: { try { UpdateStatusInfo updateStatusInfo = new UpdateStatusInfo(); updateStatusInfo.Status = string.Format("【{0}】{1}@devtext http://www.devtext.com/news/detail/{2}", news.Title.Length > 30 ? news.Title.Substring(0, 30) : news.Title, news.Summary.Length > 90 ? news.Summary.Substring(0, 90) : news.Summary, newsid); AMicroblogAPI.AMicroblog.PostStatus(updateStatusInfo); } catch (Exception ex) { } break; } case OpenAuthType.QQ: { try { QConnectSDK.QOpenClient qzone = new QOpenClient(new OAuthToken() { AccessToken = auth.AccessTokenKey, OpenId = auth.OpenId }); if (qzone != null) { qzone.AddFeeds(news.Title.Length > 30 ? news.Title.Substring(0, 30) : news.Title, string.Format("http://www.devtext.com/news/detail/{0}", newsid)); } } catch (Exception ex) { } break; } } } } return Json(new { success = result, message = result ? "投递成功" : "投递失败" }); } catch (Exception ex) { //log.Error(ex); return Json(new { success = false, message = "发生异常,投递失败,请稍候再试" }); } }
public JsonResult SubmitPost( string json ) { try { Article article = JsonConvert.Import<Article>(json); if (string.IsNullOrEmpty(article.WebFrom)) { article.WebFrom = UserContext.Instance.User.NickName; article.WebFromAddress = "/user/" + UserContext.Instance.UserID + "/"; } var cates = article.ArticleCategories.ToList(); article.ArticleCategories.Clear(); foreach (var cate in cates) { var temp = articleService.GetArticleCategory(cate.ID); if (temp != null) article.ArticleCategories.Add(temp); } article.State = (int)RecordState.Approved; article.CreateTime = DateTime.Now; article.CreatorID = UserContext.Instance.UserID; article.AnymousComment = false; article.EnableComment = true; article.LastChanged = DateTime.Now; int aritlceid = articleService.CreateArticle(article); bool result = aritlceid > 0; if (result) { HomeContent content = new HomeContent(); content.Title = article.Title; content.LinkUrl = string.Format("/blogs/detail/{0}", aritlceid); content.ContentType = (int)HomeContentType.Article; content.ContentData = article.Summary; content.InsertTime = DateTime.Now; homecontentService.CreateHomeContent(content); foreach (var auth in UserContext.Instance.User.OpenAuths) { switch ((OpenAuthType)auth.OpenAuthType) { case OpenAuthType.Sinaweibo: { try { UpdateStatusInfo updateStatusInfo = new UpdateStatusInfo(); updateStatusInfo.Status = string.Format("【{0}】{1}@devtext http://www.devtext.com/blogs/detail/{2}", article.Title.Length > 30 ? article.Title.Substring(0, 30) : article.Title, article.Summary.Length > 90 ? article.Summary.Substring(0, 90) : article.Summary, aritlceid); AMicroblogAPI.AMicroblog.PostStatus(updateStatusInfo); } catch (Exception ex) { } break; } case OpenAuthType.QQ: { try { QConnectSDK.QOpenClient qzone = new QOpenClient(new OAuthToken() { AccessToken = auth.AccessTokenKey, OpenId = auth.OpenId }); if (qzone != null) { qzone.AddFeeds(article.Title.Length > 30 ? article.Title.Substring(0, 30) : article.Title, string.Format("http://www.devtext.com/blogs/detail/{0}", aritlceid)); } } catch (Exception ex) { } break; } } } } return Json(new { success = result, message = result ? "发布成功" : "发布失败" }); } catch (Exception ex) { //log.Error(ex); return Json(new { success = false, message = "发生异常,请检查收再试" }); } }