本文整理汇总了C#中Nop.Core.Domain.Forums.ForumTopic类的典型用法代码示例。如果您正苦于以下问题:C# ForumTopic类的具体用法?C# ForumTopic怎么用?C# ForumTopic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ForumTopic类属于Nop.Core.Domain.Forums命名空间,在下文中一共展示了ForumTopic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareForumTopicRowModel
protected ForumTopicRowModel PrepareForumTopicRowModel(ForumTopic topic)
{
var topicModel = new ForumTopicRowModel()
{
Id = topic.Id,
Subject = topic.Subject,
SeName = topic.GetSeName(),
LastPostId = topic.LastPostId,
NumPosts = topic.NumPosts,
Views = topic.Views,
NumReplies = topic.NumReplies,
ForumTopicType = topic.ForumTopicType,
CustomerId = topic.CustomerId,
AllowViewingProfiles = _customerSettings.AllowViewingProfiles,
CustomerName = topic.Customer.FormatUserName(),
IsCustomerGuest = topic.Customer.IsGuest()
};
var forumPosts = _forumService.GetAllPosts(topic.Id, 0, string.Empty, 1, _forumSettings.PostsPageSize);
topicModel.TotalPostPages = forumPosts.TotalPages;
return topicModel;
}
示例2: TopicCreate
public ActionResult TopicCreate(EditForumTopicModel model)
{
if (!_forumSettings.ForumsEnabled)
{
return RedirectToRoute("HomePage");
}
var forum = _forumService.GetForumById(model.ForumId);
if (forum == null)
{
return RedirectToRoute("Boards");
}
if (ModelState.IsValid)
{
try
{
if (!_forumService.IsCustomerAllowedToCreateTopic(_workContext.CurrentCustomer, forum))
{
return new HttpUnauthorizedResult();
}
string subject = model.Subject;
var maxSubjectLength = _forumSettings.TopicSubjectMaxLength;
if (maxSubjectLength > 0 && subject.Length > maxSubjectLength)
{
subject = subject.Substring(0, maxSubjectLength);
}
var text = model.Text;
var maxPostLength = _forumSettings.PostMaxLength;
if (maxPostLength > 0 && text.Length > maxPostLength)
{
text = text.Substring(0, maxPostLength);
}
var topicType = ForumTopicType.Normal;
string ipAddress = _webHelper.GetCurrentIpAddress();
var nowUtc = DateTime.UtcNow;
if (_forumService.IsCustomerAllowedToSetTopicPriority(_workContext.CurrentCustomer))
{
topicType = (ForumTopicType) Enum.ToObject(typeof (ForumTopicType), model.TopicTypeId);
}
//forum topic
var forumTopic = new ForumTopic
{
ForumId = forum.Id,
CustomerId = _workContext.CurrentCustomer.Id,
TopicTypeId = (int) topicType,
Subject = subject,
CreatedOnUtc = nowUtc,
UpdatedOnUtc = nowUtc
};
_forumService.InsertTopic(forumTopic, true);
//forum post
var forumPost = new ForumPost
{
TopicId = forumTopic.Id,
CustomerId = _workContext.CurrentCustomer.Id,
Text = text,
IPAddress = ipAddress,
CreatedOnUtc = nowUtc,
UpdatedOnUtc = nowUtc
};
_forumService.InsertPost(forumPost, false);
//update forum topic
forumTopic.NumPosts = 1;
forumTopic.LastPostId = forumPost.Id;
forumTopic.LastPostCustomerId = forumPost.CustomerId;
forumTopic.LastPostTime = forumPost.CreatedOnUtc;
forumTopic.UpdatedOnUtc = nowUtc;
_forumService.UpdateTopic(forumTopic);
//subscription
if (_forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer))
{
if (model.Subscribed)
{
var forumSubscription = new ForumSubscription
{
SubscriptionGuid = Guid.NewGuid(),
CustomerId = _workContext.CurrentCustomer.Id,
TopicId = forumTopic.Id,
CreatedOnUtc = nowUtc
};
_forumService.InsertSubscription(forumSubscription);
}
}
return RedirectToRoute("TopicSlug", new {id = forumTopic.Id, slug = forumTopic.GetSeName()});
}
catch (Exception ex)
//.........这里部分代码省略.........
示例3: SendNewForumTopicMessage
/// <summary>
/// Sends a forum subscription message to a customer
/// </summary>
/// <param name="customer">Customer instance</param>
/// <param name="forumTopic">Forum Topic</param>
/// <param name="forum">Forum</param>
/// <param name="languageId">Message language identifier</param>
/// <returns>Queued email identifier</returns>
public int SendNewForumTopicMessage(Customer customer,
ForumTopic forumTopic, Forum forum, int languageId)
{
if (customer == null)
{
throw new ArgumentNullException("customer");
}
var messageTemplate = GetLocalizedActiveMessageTemplate("Forums.NewForumTopic", languageId);
if (messageTemplate == null || !messageTemplate.IsActive)
{
return 0;
}
var tokens = GenerateTokens(forumTopic);
//event notification
_eventPublisher.MessageTokensAdded(messageTemplate, tokens);
var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);
var toEmail = customer.Email;
var toName = customer.GetFullName();
return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
}
示例4: GenerateTokens
private IList<Token> GenerateTokens(ForumTopic forumTopic)
{
var tokens = new List<Token>();
_messageTokenProvider.AddStoreTokens(tokens);
_messageTokenProvider.AddForumTopicTokens(tokens, forumTopic);
_messageTokenProvider.AddForumTokens(tokens, forumTopic.Forum);
return tokens;
}
示例5: Can_save_and_load_forumpost
public void Can_save_and_load_forumpost()
{
var customer = GetTestCustomer();
var customerFromDb = SaveAndLoadEntity(customer);
customerFromDb.ShouldNotBeNull();
var forumGroup = new ForumGroup
{
Name = "Forum Group 1",
DisplayOrder = 1,
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow
};
var forumGroupFromDb = SaveAndLoadEntity(forumGroup);
forumGroupFromDb.ShouldNotBeNull();
forumGroupFromDb.Name.ShouldEqual("Forum Group 1");
forumGroupFromDb.DisplayOrder.ShouldEqual(1);
var forum = new Forum
{
ForumGroup = forumGroupFromDb,
Name = "Forum 1",
Description = "Forum 1 Description",
ForumGroupId = forumGroupFromDb.Id,
DisplayOrder = 10,
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow,
NumPosts = 25,
NumTopics = 15
};
forumGroup.Forums.Add(forum);
var forumFromDb = SaveAndLoadEntity(forum);
forumFromDb.ShouldNotBeNull();
forumFromDb.Name.ShouldEqual("Forum 1");
forumFromDb.Description.ShouldEqual("Forum 1 Description");
forumFromDb.DisplayOrder.ShouldEqual(10);
forumFromDb.NumTopics.ShouldEqual(15);
forumFromDb.NumPosts.ShouldEqual(25);
forumFromDb.ForumGroupId.ShouldEqual(forumGroupFromDb.Id);
var forumTopic = new ForumTopic
{
Subject = "Forum Topic 1",
ForumId = forumFromDb.Id,
TopicTypeId = (int)ForumTopicType.Sticky,
Views = 123,
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow,
NumPosts = 100,
CustomerId = customerFromDb.Id,
};
var forumTopicFromDb = SaveAndLoadEntity(forumTopic);
forumTopicFromDb.ShouldNotBeNull();
forumTopicFromDb.Subject.ShouldEqual("Forum Topic 1");
forumTopicFromDb.Views.ShouldEqual(123);
forumTopicFromDb.NumPosts.ShouldEqual(100);
forumTopicFromDb.TopicTypeId.ShouldEqual((int)ForumTopicType.Sticky);
forumTopicFromDb.ForumId.ShouldEqual(forumFromDb.Id);
var forumPost = new ForumPost
{
Text = "Forum Post 1 Text",
ForumTopic = forumTopicFromDb,
TopicId = forumTopicFromDb.Id,
IPAddress = "127.0.0.1",
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow,
CustomerId = customerFromDb.Id,
};
var forumPostFromDb = SaveAndLoadEntity(forumPost);
forumPostFromDb.ShouldNotBeNull();
forumPostFromDb.Text.ShouldEqual("Forum Post 1 Text");
forumPostFromDb.IPAddress.ShouldEqual("127.0.0.1");
forumPostFromDb.TopicId.ShouldEqual(forumTopicFromDb.Id);
}
示例6: SendNewForumPostMessage
/// <summary>
/// Sends a forum subscription message to a customer
/// </summary>
/// <param name="customer">Customer instance</param>
/// <param name="forumPost">Forum post</param>
/// <param name="forumTopic">Forum Topic</param>
/// <param name="forum">Forum</param>
/// <param name="friendlyForumTopicPageIndex">Friendly (starts with 1) forum topic page to use for URL generation</param>
/// <param name="languageId">Message language identifier</param>
/// <returns>Queued email identifier</returns>
public int SendNewForumPostMessage(Customer customer,
ForumPost forumPost, ForumTopic forumTopic,
Forum forum, int friendlyForumTopicPageIndex, int languageId)
{
if (customer == null)
{
throw new ArgumentNullException("customer");
}
var store = _storeContext.CurrentStore;
var messageTemplate = GetActiveMessageTemplate("Forums.NewForumPost", store.Id);
if (messageTemplate == null )
{
return 0;
}
//email account
var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);
//tokens
var tokens = new List<Token>();
_messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
_messageTokenProvider.AddForumPostTokens(tokens, forumPost);
_messageTokenProvider.AddForumTopicTokens(tokens, forumPost.ForumTopic,
friendlyForumTopicPageIndex, forumPost.Id);
_messageTokenProvider.AddForumTokens(tokens, forumPost.ForumTopic.Forum);
_messageTokenProvider.AddCustomerTokens(tokens, customer);
//event notification
_eventPublisher.MessageTokensAdded(messageTemplate, tokens);
var toEmail = customer.Email;
var toName = customer.GetFullName();
return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
}
示例7: UpdateTopic
/// <summary>
/// Updates the forum topic
/// </summary>
/// <param name="forumTopic">Forum topic</param>
public virtual void UpdateTopic(ForumTopic forumTopic)
{
if (forumTopic == null)
{
throw new ArgumentNullException("forumTopic");
}
_forumTopicRepository.Update(forumTopic);
_cacheManager.RemoveByPattern(FORUMGROUP_PATTERN_KEY);
_cacheManager.RemoveByPattern(FORUM_PATTERN_KEY);
//event notification
_eventPublisher.EntityUpdated(forumTopic);
}
示例8: InsertTopic
/// <summary>
/// Inserts a forum topic
/// </summary>
/// <param name="forumTopic">Forum topic</param>
/// <param name="sendNotifications">A value indicating whether to send notifications to subscribed customers</param>
public virtual void InsertTopic(ForumTopic forumTopic, bool sendNotifications)
{
if (forumTopic == null)
{
throw new ArgumentNullException("forumTopic");
}
_forumTopicRepository.Insert(forumTopic);
//update stats
UpdateForumStats(forumTopic.ForumId);
//cache
_cacheManager.RemoveByPattern(FORUMGROUP_PATTERN_KEY);
_cacheManager.RemoveByPattern(FORUM_PATTERN_KEY);
//event notification
_eventPublisher.EntityInserted(forumTopic);
//send notifications
if (sendNotifications)
{
var forum = forumTopic.Forum;
var subscriptions = GetAllSubscriptions(forumId: forum.Id);
var languageId = _workContext.WorkingLanguage.Id;
foreach (var subscription in subscriptions)
{
if (subscription.CustomerId == forumTopic.CustomerId)
{
continue;
}
if (!String.IsNullOrEmpty(subscription.Customer.Email))
{
_workflowMessageService.SendNewForumTopicMessage(subscription.Customer, forumTopic,
forum, languageId);
}
}
}
}
示例9: DeleteTopic
/// <summary>
/// Deletes a forum topic
/// </summary>
/// <param name="forumTopic">Forum topic</param>
public virtual void DeleteTopic(ForumTopic forumTopic)
{
if (forumTopic == null)
{
throw new ArgumentNullException("forumTopic");
}
int customerId = forumTopic.CustomerId;
int forumId = forumTopic.ForumId;
//delete topic
_forumTopicRepository.Delete(forumTopic);
//delete forum subscriptions
var queryFs = from ft in _forumSubscriptionRepository.Table
where ft.TopicId == forumTopic.Id
select ft;
var forumSubscriptions = queryFs.ToList();
foreach (var fs in forumSubscriptions)
{
_forumSubscriptionRepository.Delete(fs);
//event notification
_eventPublisher.EntityDeleted(fs);
}
//update stats
UpdateForumStats(forumId);
UpdateCustomerStats(customerId);
_cacheManager.RemoveByPattern(FORUMGROUP_PATTERN_KEY);
_cacheManager.RemoveByPattern(FORUM_PATTERN_KEY);
//event notification
_eventPublisher.EntityDeleted(forumTopic);
}
示例10: IsCustomerAllowedToCreatePost
/// <summary>
/// Check whether customer is allowed to create new post
/// </summary>
/// <param name="customer">Customer</param>
/// <param name="topic">Topic</param>
/// <returns>True if allowed, otherwise false</returns>
public virtual bool IsCustomerAllowedToCreatePost(Customer customer, ForumTopic topic)
{
if (topic == null)
{
return false;
}
if (customer == null)
{
return false;
}
if (customer.IsGuest() && !_forumSettings.AllowGuestsToCreatePosts)
{
return false;
}
return true;
}
示例11: IsCustomerAllowedToDeleteTopic
/// <summary>
/// Check whether customer is allowed to delete topic
/// </summary>
/// <param name="customer">Customer</param>
/// <param name="topic">Topic</param>
/// <returns>True if allowed, otherwise false</returns>
public virtual bool IsCustomerAllowedToDeleteTopic(Customer customer, ForumTopic topic)
{
if (topic == null)
{
return false;
}
if (customer == null)
{
return false;
}
if (customer.IsGuest())
{
return false;
}
if (IsForumModerator(customer))
{
return true;
}
if (_forumSettings.AllowCustomersToDeletePosts)
{
bool ownTopic = customer.Id == topic.CustomerId;
return ownTopic;
}
return false;
}
示例12: IsCustomerAllowedToMoveTopic
/// <summary>
/// Check whether customer is allowed to move topic
/// </summary>
/// <param name="customer">Customer</param>
/// <param name="topic">Topic</param>
/// <returns>True if allowed, otherwise false</returns>
public virtual bool IsCustomerAllowedToMoveTopic(Customer customer, ForumTopic topic)
{
if (topic == null)
{
return false;
}
if (customer == null)
{
return false;
}
if (customer.IsGuest())
{
return false;
}
if (IsForumModerator(customer))
{
return true;
}
return false;
}
示例13: AddForumTopicTokens
public virtual void AddForumTopicTokens(IList<Token> tokens, ForumTopic forumTopic,
int? friendlyForumTopicPageIndex = null, int? appendedPostIdentifierAnchor = null)
{
//TODO add a method for getting URL (use routing because it handles all SEO friendly URLs)
string topicUrl;
if (friendlyForumTopicPageIndex.HasValue && friendlyForumTopicPageIndex.Value > 1)
topicUrl = string.Format("{0}boards/topic/{1}/{2}/page/{3}", GetStoreUrl(), forumTopic.Id, forumTopic.GetSeName(), friendlyForumTopicPageIndex.Value);
else
topicUrl = string.Format("{0}boards/topic/{1}/{2}", GetStoreUrl(), forumTopic.Id, forumTopic.GetSeName());
if (appendedPostIdentifierAnchor.HasValue && appendedPostIdentifierAnchor.Value > 0)
topicUrl = string.Format("{0}#{1}", topicUrl, appendedPostIdentifierAnchor.Value);
tokens.Add(new Token("Forums.TopicURL", topicUrl, true));
tokens.Add(new Token("Forums.TopicName", forumTopic.Subject));
//event notification
_eventPublisher.EntityTokensAdded(forumTopic, tokens);
}
示例14: SendNewForumPostMessage
/// <summary>
/// Sends a forum subscription message to a customer
/// </summary>
/// <param name="customer">Customer instance</param>
/// <param name="forumPost">Forum post</param>
/// <param name="forumTopic">Forum Topic</param>
/// <param name="forum">Forum</param>
/// <param name="friendlyForumTopicPageIndex">Friendly (starts with 1) forum topic page to use for URL generation</param>
/// <param name="languageId">Message language identifier</param>
/// <returns>Queued email identifier</returns>
public int SendNewForumPostMessage(Customer customer,
ForumPost forumPost, ForumTopic forumTopic,
Forum forum, int friendlyForumTopicPageIndex, int languageId)
{
if (customer == null)
{
throw new ArgumentNullException("customer");
}
var messageTemplate = GetLocalizedActiveMessageTemplate("Forums.NewForumPost", languageId);
if (messageTemplate == null || !messageTemplate.IsActive)
{
return 0;
}
var tokens = GenerateTokens(forumPost, friendlyForumTopicPageIndex, forumPost.Id);
var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);
var toEmail = customer.Email;
var toName = customer.GetFullName();
return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
}
示例15: Can_save_and_load_forum_subscription_topic_subscribed
public void Can_save_and_load_forum_subscription_topic_subscribed()
{
var customer = GetTestCustomer();
var customerFromDb = SaveAndLoadEntity(customer);
customerFromDb.ShouldNotBeNull();
var forumGroup = new ForumGroup
{
Name = "Forum Group 1",
Description = "Forum Group 1 Description",
DisplayOrder = 1,
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow
};
var forumGroupFromDb = SaveAndLoadEntity(forumGroup);
forumGroupFromDb.ShouldNotBeNull();
forumGroupFromDb.Name.ShouldEqual("Forum Group 1");
forumGroupFromDb.Description.ShouldEqual("Forum Group 1 Description");
forumGroupFromDb.DisplayOrder.ShouldEqual(1);
var forum = new Forum
{
ForumGroup = forumGroupFromDb,
Name = "Forum 1",
Description = "Forum 1 Description",
ForumGroupId = forumGroupFromDb.Id,
DisplayOrder = 10,
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow,
NumPosts = 25,
NumTopics = 15
};
forumGroup.Forums.Add(forum);
var forumFromDb = SaveAndLoadEntity(forum);
forumFromDb.ShouldNotBeNull();
forumFromDb.Name.ShouldEqual("Forum 1");
forumFromDb.Description.ShouldEqual("Forum 1 Description");
forumFromDb.DisplayOrder.ShouldEqual(10);
forumFromDb.NumTopics.ShouldEqual(15);
forumFromDb.NumPosts.ShouldEqual(25);
forumFromDb.ForumGroupId.ShouldEqual(forumGroupFromDb.Id);
var forumTopic = new ForumTopic
{
Subject = "Forum Topic 1",
Forum = forumFromDb,
ForumId = forumFromDb.Id,
TopicTypeId = (int)ForumTopicType.Sticky,
Views = 123,
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow,
NumPosts = 100,
CustomerId = customerFromDb.Id,
};
var forumTopicFromDb = SaveAndLoadEntity(forumTopic);
forumTopicFromDb.ShouldNotBeNull();
forumTopicFromDb.Subject.ShouldEqual("Forum Topic 1");
forumTopicFromDb.Views.ShouldEqual(123);
forumTopicFromDb.NumPosts.ShouldEqual(100);
forumTopicFromDb.TopicTypeId.ShouldEqual((int)ForumTopicType.Sticky);
forumTopicFromDb.ForumId.ShouldEqual(forumFromDb.Id);
var forumSubscription = new ForumSubscription
{
CreatedOnUtc = DateTime.UtcNow,
SubscriptionGuid = new Guid("11111111-2222-3333-4444-555555555555"),
TopicId = forumTopicFromDb.Id,
CustomerId = customerFromDb.Id,
};
var forumSubscriptionFromDb = SaveAndLoadEntity(forumSubscription);
forumSubscriptionFromDb.ShouldNotBeNull();
forumSubscriptionFromDb.SubscriptionGuid.ToString().ShouldEqual("11111111-2222-3333-4444-555555555555");
forumSubscriptionFromDb.TopicId.ShouldEqual(forumTopicFromDb.Id);
forumSubscriptionFromDb.ForumId.ShouldEqual(0);
}