internal BusinessObjectActionReport <DataRepositoryActionStatus> Delete(CMSContent cmsContent, bool deleteLinkedThreads) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsContent); if (businessObjectActionReport.ValidationResult.IsValid) { int num = this.Delete(cmsContent.CMSContentId, deleteLinkedThreads); if (num == 0 || num == -1003) { businessObjectActionReport.Status = DataRepositoryActionStatus.NoRecordRowAffected; } else if (num < 0) { businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError; _Log.WarnFormat("CMSContent {0} was not deleted from the database (ErrorCode: {1})." , DebugUtility.GetObjectString(cmsContent) , num); } else { businessObjectActionReport.Status = DataRepositoryActionStatus.Success; } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSContent {0} was not deleted from the database because the validation failed.\nReport: {1}" , DebugUtility.GetObjectString(cmsContent) , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
internal bool IncreaseTotalViews(CMSContent content, int viewsToAdd) { int num = 0; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_Contents_IncreaseTotalViews(content.CMSContentId, viewsToAdd); } } catch (Exception ex) { _Log.Error("Error at cms_Contents_IncreaseTotalViews", ex); throw new DataStoreException(ex, true); } if (num == 1) { content.TotalViews += viewsToAdd; return(true); } else { _Log.WarnFormat("Unable to increase total views for ConentId {0}. No record rows affected", content.CMSBaseContentId); return(false); } }
public void Test_CreateTempFileAndMove() { IUserBasic userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager); CMSSection section = Test_CMSSections.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, null, this.Random); CMSThread thread = Test_CMSThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, section, this.Random); CMSContent content = Test_CMSContents.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic.UserId, thread, this.Random); CMSFileManager manager = new CMSFileManager(this.DataStore); ASCIIEncoding encoding = new ASCIIEncoding(); string contentString = "Some String " + this.Random.Next(1000000, 10000000); CMSFile tempFile = CreateTemporaryFile(this.DataStore, this.Application.ApplicationId, userBasic, encoding.GetBytes(contentString), this.Random); int fileId; manager.MoveTemporaryFileToFiles(tempFile.CMSFileId, content.CMSContentId, "FileName", "FriendlyFileName", null, out fileId); CMSFile file = manager.GetFile(fileId); Assert.IsNotNull(file); // TODO (Roman): do all the value asserts Assert.AreEqual(contentString, encoding.GetString(file.Content)); // TODO (Roman): check that tempFile doesn't exist any more Test_CMSSections.Delete(this.DataStore, section); // deleting the section should also delete the file Assert.IsNull(manager.GetFile(file.CMSFileId)); }
public Article GetArticle(string friendlyName, string articleGroupName, string articleGroupThreadName) { CMSContent content = _CMSContentManager.GetContent(friendlyName, articleGroupThreadName, articleGroupName, null); Article record = null; if (content != null) { CMSThread thread = null; CMSSection section = null; thread = _CMSThreadManager.GetThread(CMSSectionType.Article, content.CMSThreadId); section = _CMSSectionManager.GetSection(CMSSectionType.Article, thread.CMSSectionId); // this should only ever be used for testing List <string> contentLevelNodeNames = new List <string>(); if (content.ContentLevelNodeId.HasValue) { var lookup = _CMSContentLevelNodeManager.GetContentLevelNodes(); if (lookup.ContainsKey(content.ContentLevelNodeId.Value)) { ICMSContentLevelNode node = lookup[content.ContentLevelNodeId.Value]; contentLevelNodeNames.Add(node.Name); while (node.Parent != null) { node = node.Parent; contentLevelNodeNames.Insert(0, node.Name); } } } record = new Article(content, thread, section, _CMSTagManager.GetTagsByContentId(content.CMSContentId), contentLevelNodeNames); } return(record); }
// Inserts or updates the Contents based on the id value inserted. public async Task <CMSContent> InsertOrUpdateCMSContent(CreateContentInput input) { try { var exists = await _contentRepository .GetAll() .AnyAsync(e => e.Id == input.Id); if (!exists) { var @content = CMSContent.CreateContent(input.PageName, input.PageContent); return(await _contentRepository.InsertAsync(@content)); } else { var @content = CMSContent.CreateContent(input.Id, input.PageName, input.PageContent); return(await _contentRepository.UpdateAsync(@content)); } } catch (Exception e) { // To do :Log the message somewhere throw new UserFriendlyException($"There was an error while inserting/updating the contect . Please contact Us {0}", e.StackTrace); } }
internal static CMSContent Create(IDataStore dataStore, IApplicationSettings applicationSettings, IApplication application , int authorUserId, CMSThread thread, Random random) { CMSContentManager manager = new CMSContentManager(dataStore); CMSContent content = new CMSContent( authorUserId , thread , 0 , 0 , "Content Status" + random.Next(1000000, 10000000) , "Content Body" + random.Next(1000000, 10000000) , true); BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Create(content, null, null, false, false, null, null, null); Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status); Assert.Greater(content.CMSContentId, 0); CMSContent dsContent = manager.GetContent(content.CMSContentId); Assert.IsNotNull(dsContent); return(dsContent); }
public void Test_ContentRatingCaluclations() { IUserBasic userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager); CMSSection section = Test_CMSSections.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, null, this.Random); CMSThread thread = Test_CMSThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, section, this.Random); CMSContent content = Test_CMSContents.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic.UserId, thread, this.Random); CMSContentRatingManager manager = new CMSContentRatingManager(this.DataStore); for (int i = 0; i < 10; i++) { userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager); CMSContentRating record = new CMSContentRating(userBasic, content, (short)i); BusinessObjectActionReport <RatingDataRepositoryActionStatus> report = manager.Create(record); Assert.AreEqual(RatingDataRepositoryActionStatus.Success, report.Status); } CMSContentManager contentManager = new CMSContentManager(this.DataStore); content = contentManager.GetContent(content.CMSContentId); Assert.AreEqual(10, content.CMSTotalRatings); Assert.AreEqual(45, content.CMSRatingSum); Test_CMSSections.Delete(this.DataStore, section); // deleting the section should also delete the file }
public void Test_CreateUpdateDeleteContent() { IUserBasic userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager); CMSSection section = Test_CMSSections.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, null, this.Random); CMSThread thread = Test_CMSThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, section, this.Random); CMSContentManager manager = new CMSContentManager(this.DataStore); CMSContent record = Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic.UserId, thread, this.Random); CMSContent recordToCompare; for (int i = 0; i < this.DefaultUpdateTestIterations; i++) { PopulateWithRandomValues(record, this.DummyDataManager, this.Random); recordToCompare = record; manager.Update(record); record = manager.GetContent(record.CMSContentId); string errors = string.Empty; // TODO (Roman): relax datetime comparisons Assert.IsTrue(DebugUtility.ArePropertyValuesEqual(record, recordToCompare, out errors), errors); Trace.WriteLine("Update test successfull."); } Delete(this.DataStore, record); Test_CMSSections.Delete(this.DataStore, section); }
internal PrivateMessage(CMSContent cmsContent, CMSThread cmsThread, CMSSection cmsSection) { this._CMSContent = cmsContent; if (cmsThread != null) { this.Folder = new Folder(cmsThread, cmsSection); } }
internal ContentBlock(CMSContent cmsContent, CMSThread cmsThread, CMSSection cmsSection) { this._CMSContent = cmsContent; if (cmsThread != null) { this.ContentPlaceholderHistory = new ContentPlaceholderHistory(cmsThread, cmsSection); } }
internal Message(CMSContent cmsContent, CMSThread cmsThread, CMSSection cmsSection) { this._CMSContent = cmsContent; if (cmsThread != null) { this.MessageBoardThread = new MessageBoardThread(cmsThread, cmsSection); } }
public Message(IUserBasic author, MessageBoardThread messageBoardThread, string subject, string formattedBody, int?parentMessageId, short messageLevel) { this._CMSContent = new CMSContent(author.UserId, messageBoardThread.CMSThread, 0, 0, subject, formattedBody, true); this.MessageBoardThread = messageBoardThread; this.ParentMessageId = parentMessageId; this.MessageLevel = messageLevel; }
internal static void Delete(IDataStore dataStore, CMSContent content, IUserBasic userBasic) { CMSContentUserManager manager = new CMSContentUserManager(dataStore); BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Delete(new CMSContentUser(userBasic, content)); Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status); Trace.WriteLine("Successfully deleted contentUser " + content.CMSContentId + " -> " + userBasic.UserId); }
internal static void PopulateWithRandomValues(CMSContent record, DummyDataManager dtm, Random random) { record.CMSContentStatus = (byte)random.Next(1, 256); record.CMSContentType = (byte)random.Next(1, 256); record.FormattedBody = "Content Body" + random.Next(1000000, 10000000); record.IsApproved = DebugUtility.FlipCoin(random); record.IsLocked = DebugUtility.FlipCoin(random); record.Subject = "Content Status" + random.Next(1000000, 10000000); record.UrlFriendlyName = record.Subject; }
internal static void Delete(IDataStore dataStore, CMSContent content) { CMSContentManager manager = new CMSContentManager(dataStore); BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Delete(content, true); Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status); Assert.IsNull(manager.GetContent(content.CMSContentId)); Trace.WriteLine("Successfully deleted content " + content.Subject); }
public void Post([FromBody] CMSContent value) { CMSContent values = new CMSContent() { content = new ContentBlock() { contentId = new Random().Next(100, 1000), description = "Sample description " + DateTime.Now, text = "Sample text " + DateTime.Now, title = "Sample title " + DateTime.Now } }; CMSRepo.Add(values); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> Update(CMSContent cmsContent, string[] tags, bool doReindex) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsContent); if (businessObjectActionReport.ValidationResult.IsValid) { int num = 0; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_Contents_Update( cmsContent.CMSContentId , cmsContent.CMSThreadId , cmsContent.CMSParentContentId , cmsContent.AuthorUserId , cmsContent.CMSContentLevel , cmsContent.Subject , cmsContent.FormattedBody , cmsContent.IsApproved , cmsContent.IsLocked , cmsContent.CMSContentType , cmsContent.CMSContentStatus , cmsContent.CMSExtraInfo , cmsContent.CMSBaseContentId , cmsContent.UrlFriendlyName , tags); } } catch (Exception ex) { _Log.Error("Error at cms_Contents_Update", ex); throw new DataStoreException(ex, true); } if (num != 0) { businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError; _Log.ErrorFormat("CMSContent {0} was not updated from the database (ErrorCode: {1})." , DebugUtility.GetObjectString(cmsContent) , num); } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSContent {0} was not updated at the database because the validation failed.\nReport: {1}" , DebugUtility.GetObjectString(cmsContent) , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
public PrivateMessage(IUserBasic author, Folder folder, MessageStatus messageStatus, MessageType messageType, string subject, string formattedBody) { this._CMSContent = new CMSContent( author.UserId , folder.CMSThread , (byte)messageStatus , (byte)messageType , subject , formattedBody , true); this.Folder = folder; }
internal static void Delete(IDataStore dataStore, CMSContent content, IUserBasic userBasic) { CMSContentRatingManager manager = new CMSContentRatingManager(dataStore); CMSContentRating contentRating = manager.GetContentRating(content, userBasic); BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Delete(contentRating); Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status); Assert.IsNull(manager.GetContentRating(content, userBasic)); Trace.WriteLine("Successfully deleted contentRating " + contentRating.CMSContentId + " -> " + contentRating.CMSUserId); }
public void Test_Delete_Section() { IUserBasic userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager); CMSSection section = Test_CMSSections.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, null, this.Random); CMSThread thread = Test_CMSThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, section, this.Random); CMSContent content = Test_CMSContents.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic.UserId, thread, this.Random); Test_CMSSections.Delete(this.DataStore, section); CMSThreadManager threadManager = new CMSThreadManager(this.DataStore); CMSContentManager contentManager = new CMSContentManager(this.DataStore); Assert.IsNull(threadManager.GetThread(section.CMSSectionType, thread.CMSThreadId)); Assert.IsNull(contentManager.GetContent(content.CMSContentId)); }
internal List <CMSContentRating> GetRatingsForContent(CMSContent content) { try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { return(dataStoreContext.cms_ContentRatings_Get(content.CMSContentId).ToList()); } } catch (Exception ex) { _Log.Error("Error at cms_ContentRatings_Get", ex); throw new DataStoreException(ex, true); } }
internal CMSContentRating GetContentRating(CMSContent content, IUserBasic userBasic) { try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { return(dataStoreContext.cms_ContentRatings_Get(userBasic.UserId, content.CMSContentId)); } } catch (Exception ex) { _Log.Error("Error at cms_ContentRatings_Get", ex); throw new DataStoreException(ex, true); } }
public void Test_SelfRatingConstraint() { IUserBasic userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager); CMSSection section = Test_CMSSections.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, null, this.Random); CMSThread thread = Test_CMSThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, section, this.Random); CMSContent content = Test_CMSContents.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic.UserId, thread, this.Random); CMSContentRatingManager manager = new CMSContentRatingManager(this.DataStore); CMSContentRating record = new CMSContentRating(userBasic, content, 1); BaseRatingInfo baseRatingInfo; BusinessObjectActionReport <RatingDataRepositoryActionStatus> report = manager.Create(record, true, false, out baseRatingInfo); Assert.AreEqual(RatingDataRepositoryActionStatus.SelfRatingNotAllowed, report.Status); Test_CMSSections.Delete(this.DataStore, section); // deleting the section should also delete the file }
private static void _addToLuceneIndex(CMSContent cmsContent, IndexWriter writer) { // remove older index entry var searchQuery = new TermQuery(new Term("Id", cmsContent.Id.ToString())); writer.DeleteDocuments(searchQuery); // add new index entry var doc = new Document(); // add lucene fields mapped to db fields doc.Add(new Field("Id", cmsContent.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Header", cmsContent.Header, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("Body", cmsContent.Body, Field.Store.YES, Field.Index.ANALYZED)); // add entry to index writer.AddDocument(doc); }
public void Test_CreateUpdateDeleteContentUser() { IUserBasic userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager); CMSSection section = Test_CMSSections.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, null, this.Random); CMSThread thread = Test_CMSThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, section, this.Random); CMSContent content = Test_CMSContents.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic.UserId, thread, this.Random); CMSContentUserManager manager = new CMSContentUserManager(this.DataStore); CMSContentUser record = new CMSContentUser(userBasic, content); BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Create(record); Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status); Delete(this.DataStore, content, userBasic); Test_CMSSections.Delete(this.DataStore, section); // deleting the section should also delete the file }
public Article(IUserBasic author, ArticleGroupThread articleGroupThread, ArticleStatus articleStatus, ArticleType articleType, string subject, string formattedBody, string urlFriendlyName, bool isApproved, List <string> tags, List <KeyValuePair <string, string> > tripleTags, List <string> contentLevelNodeNames) { this._CMSContent = new CMSContent(author.UserId, articleGroupThread.CMSThread, (byte)articleStatus , (byte)articleType, subject, formattedBody, isApproved); this.ArticleGroupThread = articleGroupThread; _CMSContent.CMSExtraInfo = new XElement("i"); _CMSContent.CMSParentContentId = null; _CMSContent.CMSContentLevel = 0; _CMSContent.UrlFriendlyName = urlFriendlyName; this.ContentLevelNodeNames = (contentLevelNodeNames ?? new List <string>()); this.Tags = (tags ?? new List <string>()); if (tripleTags != null) { this.AddTripleTagsToTagCollection(tripleTags); } }
public PrivateMessage GetPrivateMessage(int privateMessageId) { CMSContent content = _CMSContentManager.GetContent(privateMessageId); PrivateMessage record = null; if (content != null) { CMSThread thread = null; CMSSection section = null; thread = _CMSThreadManager.GetThread(CMSSectionType.PrivateMessageInbox, content.CMSThreadId); section = _CMSSectionManager.GetSection(CMSSectionType.PrivateMessageInbox, thread.CMSSectionId); record = new PrivateMessage(content, thread, section); } return(record); }
public ContentBlock GetContentBlock(int contentBlockId) { CMSContent content = _CMSContentManager.GetContent(contentBlockId); ContentBlock record = null; if (content != null) { CMSThread thread = null; CMSSection section = null; thread = _CMSThreadManager.GetThread(CMSSectionType.Content, content.CMSThreadId); section = _CMSSectionManager.GetSection(CMSSectionType.Content, thread.CMSSectionId); record = new ContentBlock(content, thread, section); } return(record); }
public Message GetMessage(int messageId) { CMSContent content = _CMSContentManager.GetContent(messageId); Message record = null; if (content != null) { CMSThread thread = null; CMSSection section = null; thread = _CMSThreadManager.GetThread(CMSSectionType.MessageBoard, content.CMSThreadId); section = _CMSSectionManager.GetSection(CMSSectionType.MessageBoard, thread.CMSSectionId); record = new Message(content, thread, section); } return(record); }
public void Test_CreateUpdateDeleteContentRating() { IUserBasic userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager); CMSSection section = Test_CMSSections.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, null, this.Random); CMSThread thread = Test_CMSThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, section, this.Random); CMSContent content = Test_CMSContents.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic.UserId, thread, this.Random); CMSContentRatingManager manager = new CMSContentRatingManager(this.DataStore); CMSContentRating record = new CMSContentRating(userBasic, content, 1); BaseRatingInfo baseRatingInfo; BusinessObjectActionReport <RatingDataRepositoryActionStatus> report = manager.Create(record, true, true, out baseRatingInfo); Assert.AreEqual(RatingDataRepositoryActionStatus.Success, report.Status); Assert.AreEqual(1, baseRatingInfo.RatingSum); Assert.AreEqual(1, baseRatingInfo.TotalRatings); CMSContentRating recordToCompare; for (int i = 0; i < this.DefaultUpdateTestIterations; i++) { PopulateWithRandomValues(record, this.DummyDataManager, this.Random); recordToCompare = record; manager.Update(record); record = manager.GetContentRating(content, userBasic); string errors = string.Empty; // TODO (Roman): relax datetime comparisons Assert.IsTrue(DebugUtility.ArePropertyValuesEqual(record, recordToCompare, out errors), errors); Trace.WriteLine("Update test successfull."); } Delete(this.DataStore, content, userBasic); Test_CMSSections.Delete(this.DataStore, section); // deleting the section should also delete the file }