public TopicStorage(IDataLayer topicConnection, IDataLayer messageConnection, int topicTypeId, int topicId) { this.TopicId = topicId; this.topicCache = new Cache <LightKin, long>( delegate { return(DataBox.LoadKin(topicConnection, topicTypeId, topicId)); }, delegate { return(topicChangeTick); } ); this.messageLinkCache = new Cache <Tuple <TableLink, Dictionary <int, string> >, long>( delegate { TableLink messageLink = MessageHlp.LoadMessageLink(messageConnection, topicId); Dictionary <int, string> htmlRepresentById = new Dictionary <int, string>(messageLink.AllRows.Length); foreach (RowLink message in messageLink.AllRows) { int messageId = message.Get(MessageType.Id); string content = message.Get(MessageType.Content); string htmlRepresent = BasketballHlp.PreViewComment(content); htmlRepresentById[messageId] = htmlRepresent; } return(_.Tuple(messageLink, htmlRepresentById)); }, delegate { return(messageChangeTick); } ); }
static IHtmlControl GetNewsEditPanel(SiteState state, TopicStorage topic) { LightObject news = topic.Topic; string blockHint = string.Format("news_edit_{0}", news.Id); IHtmlControl redoPanel = null; if (state.BlockHint == blockHint) { IHtmlControl deletePanel = null; if (state.ModeratorMode) { deletePanel = DeleteTopicPanel(state, topic); } if (state.Tag == null) { state.Tag = ViewTagHlp.GetTopicDisplayTags(context.Tags.TagBox, topic.Topic); } redoPanel = new HPanel( deletePanel, Decor.PropertyEdit("newsTitle", "Заголовок новости", news.Get(NewsType.Title)), new HPanel( HtmlHlp.CKEditorCreate("newsText", news.Get(NewsType.Text), "300px", true) ), ViewTagHlp.GetEditTagsPanel(state, context.Tags.TagBox, state.Tag as List <string>, false), Decor.PropertyEdit("newsOriginName", "Источник", news.Get(NewsType.OriginName)), Decor.PropertyEdit("newsOriginUrl", "Ссылка", news.Get(NewsType.OriginUrl)), Decor.Button("Изменить новость").CKEditorOnUpdateAll().MarginTop(10) .Event("save_news_edit", "editNewsData", delegate(JsonData json) { string title = json.GetText("newsTitle"); string text = json.GetText("newsText"); string originName = json.GetText("newsOriginName"); string originUrl = json.GetText("newsOriginUrl"); WebOperation operation = state.Operation; if (!operation.Validate(title, "Не задан заголовок")) { return; } if (!operation.Validate(text, "Не задан текст")) { return; } LightKin editNews = DataBox.LoadKin(context.FabricConnection, NewsType.News, news.Id); editNews.SetWithoutCheck(NewsType.Title, title); editNews.Set(NewsType.Text, text); editNews.Set(NewsType.OriginName, originName); editNews.Set(NewsType.OriginUrl, originUrl); editNews.Set(ObjectType.ActTill, DateTime.UtcNow); ViewTagHlp.SaveTags(context, state, editNews); editNews.Box.Update(); context.UpdateNews(); context.NewsStorages.ForTopic(news.Id).UpdateTopic(); state.BlockHint = ""; }, news.Id ) ).EditContainer("editNewsData") .Padding(5, 10).MarginTop(10).Background(Decor.pageBackground); } return(new HPanel( Decor.Button("Редактировать") .Event("news_edit", "", delegate { state.SetBlockHint(blockHint); } ), redoPanel ).MarginTop(10)); }