本文整理汇总了C#中Nop.Core.Domain.Forums.ForumSubscription类的典型用法代码示例。如果您正苦于以下问题:C# ForumSubscription类的具体用法?C# ForumSubscription怎么用?C# ForumSubscription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ForumSubscription类属于Nop.Core.Domain.Forums命名空间,在下文中一共展示了ForumSubscription类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ForumWatch
public ActionResult ForumWatch(int id)
{
string watchTopic = _localizationService.GetResource("Forum.WatchForum");
string unwatchTopic = _localizationService.GetResource("Forum.UnwatchForum");
string returnText = watchTopic;
var forum = _forumService.GetForumById(id);
if (forum == null)
{
return Json(new { Subscribed = false, Text = returnText, Error = true });
}
if (!_forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer))
{
return Json(new { Subscribed = false, Text = returnText, Error = true });
}
var forumSubscription = _forumService.GetAllSubscriptions(_workContext.CurrentCustomer.Id,
forum.Id, 0, 0, 1).FirstOrDefault();
bool subscribed;
if (forumSubscription == null)
{
forumSubscription = new ForumSubscription
{
SubscriptionGuid = Guid.NewGuid(),
CustomerId = _workContext.CurrentCustomer.Id,
ForumId = forum.Id,
CreatedOnUtc = DateTime.UtcNow
};
_forumService.InsertSubscription(forumSubscription);
subscribed = true;
returnText = unwatchTopic;
}
else
{
_forumService.DeleteSubscription(forumSubscription);
subscribed = false;
}
return Json(new { Subscribed = subscribed, Text = returnText, Error = false });
}
示例2: PostEdit
public ActionResult PostEdit(EditForumPostModel model)
{
if (!_forumSettings.ForumsEnabled)
{
return RedirectToRoute("HomePage");
}
var forumPost = _forumService.GetPostById(model.Id);
if (forumPost == null)
{
return RedirectToRoute("Boards");
}
if (!_forumService.IsCustomerAllowedToEditPost(_workContext.CurrentCustomer, forumPost))
{
return new HttpUnauthorizedResult();
}
var forumTopic = forumPost.ForumTopic;
if (forumTopic == null)
{
return RedirectToRoute("Boards");
}
var forum = forumTopic.Forum;
if (forum == null)
{
return RedirectToRoute("Boards");
}
if (ModelState.IsValid)
{
try
{
DateTime nowUtc = DateTime.UtcNow;
var text = model.Text;
var maxPostLength = _forumSettings.PostMaxLength;
if (maxPostLength > 0 && text.Length > maxPostLength)
{
text = text.Substring(0, maxPostLength);
}
forumPost.UpdatedOnUtc = nowUtc;
forumPost.Text = text;
_forumService.UpdatePost(forumPost);
//subscription
if (_forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer))
{
var forumSubscription = _forumService.GetAllSubscriptions(_workContext.CurrentCustomer.Id,
0, forumPost.TopicId, 0, 1).FirstOrDefault();
if (model.Subscribed)
{
if (forumSubscription == null)
{
forumSubscription = new ForumSubscription
{
SubscriptionGuid = Guid.NewGuid(),
CustomerId = _workContext.CurrentCustomer.Id,
TopicId = forumPost.TopicId,
CreatedOnUtc = nowUtc
};
_forumService.InsertSubscription(forumSubscription);
}
}
else
{
if (forumSubscription != null)
{
_forumService.DeleteSubscription(forumSubscription);
}
}
}
int pageSize = 10;
if (_forumSettings.PostsPageSize > 0)
{
pageSize = _forumSettings.PostsPageSize;
}
int pageIndex = (_forumService.CalculateTopicPageIndex(forumPost.TopicId, pageSize, forumPost.Id) + 1);
var url = string.Empty;
if (pageIndex > 1)
{
url = Url.RouteUrl("TopicSlugPaged", new { id = forumPost.TopicId, slug = forumPost.ForumTopic.GetSeName(), page = pageIndex });
}
else
{
url = Url.RouteUrl("TopicSlug", new { id = forumPost.TopicId, slug = forumPost.ForumTopic.GetSeName() });
}
return Redirect(string.Format("{0}#{1}", url, forumPost.Id));
}
catch (Exception ex)
{
ModelState.AddModelError("", ex.Message);
}
}
//redisplay form
model.IsEdit = true;
//.........这里部分代码省略.........
示例3: TopicEdit
public ActionResult TopicEdit(EditForumTopicModel model)
{
if (!_forumSettings.ForumsEnabled)
{
return RedirectToRoute("HomePage");
}
var forumTopic = _forumService.GetTopicById(model.Id);
if (forumTopic == null)
{
return RedirectToRoute("Boards");
}
var forum = forumTopic.Forum;
if (forum == null)
{
return RedirectToRoute("Boards");
}
if (ModelState.IsValid)
{
try
{
if (!_forumService.IsCustomerAllowedToEditTopic(_workContext.CurrentCustomer, forumTopic))
{
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();
DateTime nowUtc = DateTime.UtcNow;
if (_forumService.IsCustomerAllowedToSetTopicPriority(_workContext.CurrentCustomer))
{
topicType = (ForumTopicType) Enum.ToObject(typeof (ForumTopicType), model.TopicTypeId);
}
//forum topic
forumTopic.TopicTypeId = (int) topicType;
forumTopic.Subject = subject;
forumTopic.UpdatedOnUtc = nowUtc;
_forumService.UpdateTopic(forumTopic);
//forum post
var firstPost = forumTopic.GetFirstPost(_forumService);
if (firstPost != null)
{
firstPost.Text = text;
firstPost.UpdatedOnUtc = nowUtc;
_forumService.UpdatePost(firstPost);
}
else
{
//error (not possible)
firstPost = new ForumPost
{
TopicId = forumTopic.Id,
CustomerId = forumTopic.CustomerId,
Text = text,
IPAddress = ipAddress,
UpdatedOnUtc = nowUtc
};
_forumService.InsertPost(firstPost, false);
}
//subscription
if (_forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer))
{
var forumSubscription = _forumService.GetAllSubscriptions(_workContext.CurrentCustomer.Id,
0, forumTopic.Id, 0, 1).FirstOrDefault();
if (model.Subscribed)
{
if (forumSubscription == null)
{
forumSubscription = new ForumSubscription
{
SubscriptionGuid = Guid.NewGuid(),
CustomerId = _workContext.CurrentCustomer.Id,
TopicId = forumTopic.Id,
CreatedOnUtc = nowUtc
};
_forumService.InsertSubscription(forumSubscription);
//.........这里部分代码省略.........
示例4: 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)
//.........这里部分代码省略.........
示例5: UpdateSubscription
/// <summary>
/// Updates the forum subscription
/// </summary>
/// <param name="forumSubscription">Forum subscription</param>
public virtual void UpdateSubscription(ForumSubscription forumSubscription)
{
if (forumSubscription == null)
{
throw new ArgumentNullException("forumSubscription");
}
_forumSubscriptionRepository.Update(forumSubscription);
//event notification
_eventPublisher.EntityUpdated(forumSubscription);
}
示例6: 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);
}
示例7: PostCreate
public ActionResult PostCreate(EditForumPostModel model)
{
if (!_forumSettings.ForumsEnabled)
{
return RedirectToRoute("HomePage");
}
var forumTopic = _forumService.GetTopicById(model.ForumTopicId);
if (forumTopic == null)
{
return RedirectToRoute("Boards");
}
if (ModelState.IsValid)
{
try
{
if (!_forumService.IsCustomerAllowedToCreatePost(_workContext.CurrentCustomer, forumTopic))
return new HttpUnauthorizedResult();
var text = model.Text;
var maxPostLength = _forumSettings.PostMaxLength;
if (maxPostLength > 0 && text.Length > maxPostLength)
text = text.Substring(0, maxPostLength);
string ipAddress = _webHelper.GetCurrentIpAddress();
DateTime nowUtc = DateTime.UtcNow;
var forumPost = new ForumPost
{
TopicId = forumTopic.Id,
ForumId = forumTopic.ForumId,
ForumGroupId = forumTopic.ForumGroupId,
CustomerId = _workContext.CurrentCustomer.Id,
Text = text,
IPAddress = ipAddress,
CreatedOnUtc = nowUtc,
UpdatedOnUtc = nowUtc
};
_forumService.InsertPost(forumPost, true);
if (!_workContext.CurrentCustomer.IsHasForumPost)
{
_workContext.CurrentCustomer.IsHasForumPost = true;
EngineContext.Current.Resolve<ICustomerService>().UpdateHasForumPost(_workContext.CurrentCustomer.Id);
}
//subscription
if (_forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer))
{
var forumSubscription = _forumService.GetAllSubscriptions(_workContext.CurrentCustomer.Id,
0, forumPost.TopicId, 0, 1).FirstOrDefault();
if (model.Subscribed)
{
if (forumSubscription == null)
{
forumSubscription = new ForumSubscription
{
SubscriptionGuid = Guid.NewGuid(),
CustomerId = _workContext.CurrentCustomer.Id,
TopicId = forumPost.TopicId,
CreatedOnUtc = nowUtc
};
_forumService.InsertSubscription(forumSubscription);
}
}
else
{
if (forumSubscription != null)
{
_forumService.DeleteSubscription(forumSubscription);
}
}
}
int pageSize =_forumSettings.PostsPageSize > 0 ? _forumSettings.PostsPageSize : 10;
int pageIndex = (_forumService.CalculateTopicPageIndex(forumPost.TopicId, pageSize, forumPost.Id) + 1);
var url = string.Empty;
var _forumTopic = _forumService.GetTopicById(forumPost.TopicId);
if (pageIndex > 1)
{
url = Url.RouteUrl("TopicSlugPaged", new { id = forumPost.TopicId, slug = _forumTopic.GetSeName(), page = pageIndex });
}
else
{
url = Url.RouteUrl("TopicSlug", new { id = forumPost.TopicId, slug = _forumTopic.GetSeName() });
}
return Redirect(string.Format("{0}#{1}", url, forumPost.Id));
}
catch (Exception ex)
{
ModelState.AddModelError("", ex.Message);
}
}
// redisplay form
var forum = _forumService.GetForumById(forumTopic.ForumId);
if (forum == null)
//.........这里部分代码省略.........