本文整理汇总了C#中Nop.Core.Domain.Forums.PrivateMessage类的典型用法代码示例。如果您正苦于以下问题:C# PrivateMessage类的具体用法?C# PrivateMessage怎么用?C# PrivateMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PrivateMessage类属于Nop.Core.Domain.Forums命名空间,在下文中一共展示了PrivateMessage类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_save_and_load_privatemessage
public void Can_save_and_load_privatemessage()
{
var store = GetTestStore();
var storeFromDb = SaveAndLoadEntity(store);
storeFromDb.ShouldNotBeNull();
var customer1 = GetTestCustomer();
var customer1FromDb = SaveAndLoadEntity(customer1);
customer1FromDb.ShouldNotBeNull();
var customer2 = GetTestCustomer();
var customer2FromDb = SaveAndLoadEntity(customer2);
customer2FromDb.ShouldNotBeNull();
var privateMessage = new PrivateMessage
{
Subject = "Private Message 1 Subject",
Text = "Private Message 1 Text",
IsDeletedByAuthor = false,
IsDeletedByRecipient = false,
IsRead = false,
CreatedOnUtc = DateTime.UtcNow,
FromCustomerId = customer1FromDb.Id,
ToCustomerId = customer2FromDb.Id,
StoreId = store.Id,
};
var fromDb = SaveAndLoadEntity(privateMessage);
fromDb.ShouldNotBeNull();
fromDb.Subject.ShouldEqual("Private Message 1 Subject");
fromDb.Text.ShouldEqual("Private Message 1 Text");
fromDb.IsDeletedByAuthor.ShouldBeFalse();
fromDb.IsDeletedByRecipient.ShouldBeFalse();
fromDb.IsRead.ShouldBeFalse();
}
示例2: SendPrivateMessageNotification
/// <summary>
/// Sends a private message notification
/// </summary>
/// <param name="privateMessage">Private message</param>
/// <param name="languageId">Message language identifier</param>
/// <returns>Queued email identifier</returns>
public int SendPrivateMessageNotification(PrivateMessage privateMessage, int languageId)
{
if (privateMessage == null)
{
throw new ArgumentNullException("privateMessage");
}
var messageTemplate = GetLocalizedActiveMessageTemplate("Customer.NewPM", languageId);
if (messageTemplate == null || !messageTemplate.IsActive)
{
return 0;
}
var privateMessageTokens = GenerateTokens(privateMessage);
//event notification
_eventPublisher.MessageTokensAdded(messageTemplate, privateMessageTokens);
var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);
var toEmail = privateMessage.ToCustomer.Email;
var toName = privateMessage.ToCustomer.GetFullName();
return SendNotification(messageTemplate, emailAccount, languageId, privateMessageTokens, toEmail, toName);
}
示例3: GenerateTokens
private IList<Token> GenerateTokens(PrivateMessage privateMessage)
{
var tokens = new List<Token>();
_messageTokenProvider.AddStoreTokens(tokens);
_messageTokenProvider.AddPrivateMessageTokens(tokens, privateMessage);
return tokens;
}
示例4: SendPM
public ActionResult SendPM(SendPrivateMessageModel model)
{
if (!AllowPrivateMessages())
{
return RedirectToRoute("HomePage");
}
if (_workContext.CurrentCustomer.IsGuest())
{
return new HttpUnauthorizedResult();
}
Customer toCustomer = null;
var replyToPM = _forumService.GetPrivateMessageById(model.ReplyToMessageId);
if (replyToPM != null)
{
if (replyToPM.ToCustomerId == _workContext.CurrentCustomer.Id || replyToPM.FromCustomerId == _workContext.CurrentCustomer.Id)
{
toCustomer = replyToPM.FromCustomer;
}
else
{
return RedirectToRoute("PrivateMessages");
}
}
else
{
toCustomer = _customerService.GetCustomerById(model.ToCustomerId);
}
if (toCustomer == null || toCustomer.IsGuest())
{
return RedirectToRoute("PrivateMessages");
}
model.ToCustomerId = toCustomer.Id;
model.CustomerToName = toCustomer.FormatUserName();
model.AllowViewingToProfile = _customerSettings.AllowViewingProfiles && !toCustomer.IsGuest();
if (ModelState.IsValid)
{
try
{
string subject = model.Subject;
if (_forumSettings.PMSubjectMaxLength > 0 && subject.Length > _forumSettings.PMSubjectMaxLength)
{
subject = subject.Substring(0, _forumSettings.PMSubjectMaxLength);
}
var text = model.Message;
if (_forumSettings.PMTextMaxLength > 0 && text.Length > _forumSettings.PMTextMaxLength)
{
text = text.Substring(0, _forumSettings.PMTextMaxLength);
}
var nowUtc = DateTime.UtcNow;
var privateMessage = new PrivateMessage
{
ToCustomerId = toCustomer.Id,
FromCustomerId = _workContext.CurrentCustomer.Id,
Subject = subject,
Text = text,
IsDeletedByAuthor = false,
IsDeletedByRecipient = false,
IsRead = false,
CreatedOnUtc = nowUtc
};
_forumService.InsertPrivateMessage(privateMessage);
//activity log
_customerActivityService.InsertActivity("PublicStore.SendPM", _localizationService.GetResource("ActivityLog.PublicStore.SendPM"), toCustomer.Email);
return RedirectToRoute("PrivateMessages", new { tab = "sent" });
}
catch (Exception ex)
{
ModelState.AddModelError("", ex.Message);
}
}
return View(model);
}
示例5: SendPm
public ActionResult SendPm(CustomerModel model)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
return AccessDeniedView();
var customer = _customerService.GetCustomerById(model.Id);
if (customer == null)
//No customer found with the specified id
return RedirectToAction("List");
try
{
if (!_forumSettings.AllowPrivateMessages)
throw new NopException("Private messages are disabled");
if (customer.IsGuest())
throw new NopException("Customer should be registered");
if (String.IsNullOrWhiteSpace(model.SendPm.Subject))
throw new NopException("PM subject is empty");
if (String.IsNullOrWhiteSpace(model.SendPm.Message))
throw new NopException("PM message is empty");
var privateMessage = new PrivateMessage
{
StoreId = _storeContext.CurrentStore.Id,
ToCustomerId = customer.Id,
FromCustomerId = _workContext.CurrentCustomer.Id,
Subject = model.SendPm.Subject,
Text = model.SendPm.Message,
IsDeletedByAuthor = false,
IsDeletedByRecipient = false,
IsRead = false,
CreatedOnUtc = DateTime.UtcNow
};
_forumService.InsertPrivateMessage(privateMessage);
SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.SendPM.Sent"));
}
catch (Exception exc)
{
ErrorNotification(exc.Message);
}
return RedirectToAction("Edit", new { id = customer.Id });
}
示例6: SendPrivateMessageNotification
/// <summary>
/// Sends a private message notification
/// </summary>
/// <param name="privateMessage">Private message</param>
/// <param name="languageId">Message language identifier</param>
/// <returns>Queued email identifier</returns>
public int SendPrivateMessageNotification(PrivateMessage privateMessage, int languageId)
{
if (privateMessage == null)
{
throw new ArgumentNullException("privateMessage");
}
var store = _storeService.GetStoreById(privateMessage.StoreId) ?? _storeContext.CurrentStore;
var messageTemplate = GetActiveMessageTemplate("Customer.NewPM", 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.AddPrivateMessageTokens(tokens, privateMessage);
_messageTokenProvider.AddCustomerTokens(tokens, privateMessage.ToCustomer);
//event notification
_eventPublisher.MessageTokensAdded(messageTemplate, tokens);
var toEmail = privateMessage.ToCustomer.Email;
var toName = privateMessage.ToCustomer.GetFullName();
return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
}
示例7: DeletePrivateMessage
/// <summary>
/// Deletes a private message
/// </summary>
/// <param name="privateMessage">Private message</param>
public virtual void DeletePrivateMessage(PrivateMessage privateMessage)
{
if (privateMessage == null)
{
throw new ArgumentNullException("privateMessage");
}
_forumPrivateMessageRepository.Delete(privateMessage);
//event notification
_eventPublisher.EntityDeleted(privateMessage);
}
示例8: UpdatePrivateMessage
/// <summary>
/// Updates the private message
/// </summary>
/// <param name="privateMessage">Private message</param>
public virtual void UpdatePrivateMessage(PrivateMessage privateMessage)
{
if (privateMessage == null)
throw new ArgumentNullException("privateMessage");
if (privateMessage.IsDeletedByAuthor && privateMessage.IsDeletedByRecipient)
{
_forumPrivateMessageRepository.Delete(privateMessage);
//event notification
_eventPublisher.EntityDeleted(privateMessage);
}
else
{
_forumPrivateMessageRepository.Update(privateMessage);
//event notification
_eventPublisher.EntityUpdated(privateMessage);
}
}
示例9: InsertPrivateMessage
/// <summary>
/// Inserts a private message
/// </summary>
/// <param name="privateMessage">Private message</param>
public virtual void InsertPrivateMessage(PrivateMessage privateMessage)
{
if (privateMessage == null)
{
throw new ArgumentNullException("privateMessage");
}
_forumPrivateMessageRepository.Insert(privateMessage);
//event notification
_eventPublisher.EntityInserted(privateMessage);
var customerTo = _customerService.GetCustomerById(privateMessage.ToCustomerId);
if (customerTo == null)
{
throw new NopException("Recipient could not be loaded");
}
//UI notification
_genericAttributeService.SaveAttribute(customerTo, SystemCustomerAttributeNames.NotifiedAboutNewPrivateMessages, false, privateMessage.StoreId);
//Email notification
if (_forumSettings.NotifyAboutPrivateMessages)
{
_workflowMessageService.SendPrivateMessageNotification(privateMessage, _workContext.WorkingLanguage.Id);
}
}
示例10: AddPrivateMessageTokens
public virtual void AddPrivateMessageTokens(IList<Token> tokens, PrivateMessage privateMessage)
{
tokens.Add(new Token("PrivateMessage.Subject", privateMessage.Subject));
tokens.Add(new Token("PrivateMessage.Text", privateMessage.FormatPrivateMessageText(), true));
//event notification
_eventPublisher.EntityTokensAdded(privateMessage, tokens);
}
示例11: AddPrivateMessageTokens
public virtual void AddPrivateMessageTokens(IList<Token> tokens, PrivateMessage privateMessage)
{
tokens.Add(new Token("PrivateMessage.Subject", privateMessage.Subject));
tokens.Add(new Token("PrivateMessage.Text", privateMessage.FormatPrivateMessageText(), true));
}
示例12: AUConsignorProductEmailInquiry
//[NopHttpsRequirement(SslRequirement.No)] TODO: where is this decoration?
public ActionResult AUConsignorProductEmailInquiry(AUConsignorProductEmailInquiryModel model)
{
//TODO: Build service to capture AUConsignor settings, one of which tells if product inquiries allowed for this store
//if (!_forumSettings.AllowPrivateMessages)
//{
// return RedirectToRoute("HomePage");
//}
//TODO: add same flow to register user before bid can be entered as have for product inquiry
//TODO: when cancel out of product emailinquiry need to go back to original product view
if (_workContext.CurrentCustomer.IsGuest()) //TODO: Guests can't post product inquiries - don't show button
{
return new HttpUnauthorizedResult();
}
int pmRoleId = _AUcatalogService.GetIdForRole("ProductInquiryMonitor");
int[] customerRoleIds = new int[1];
customerRoleIds[0] = pmRoleId;
//this will only find customers with the Product Inquiry Monitor role
var pmCustomers = _customerService.GetAllCustomers(
customerRoleIds: customerRoleIds,
pageIndex: 0,
pageSize: 500);
//Old way
//Customer toCustomer = null;
//toCustomer = _customerService.GetCustomerById(model.ToCustomerId); //TODO: need to get the Monitor Product Inquiries role
//TODO: GRACEFULLY ERROR IF PRODUCT MONITOR NOT FOUND
Customer toCustomer = pmCustomers.FirstOrDefault();
//TODO: Prouct private message can respond back to admin response
//TODO: Is Inbox only enabled if forums are enabled??
//TODO: ADD FULL AUDIT ATSYSTEM STARTUP AND VIA BUTTON TO CHECK SHITLOAD OF CONDITIONS
//--> Product Monitor not designated and store allows product inquiries
//--> more than one product monitor designated
//var replyToPM = _forumService.GetPrivateMessageById(model.ReplyToMessageId);
//if (replyToPM != null)
//{
// if (replyToPM.ToCustomerId == _workContext.CurrentCustomer.Id || replyToPM.FromCustomerId == _workContext.CurrentCustomer.Id)
// {
// toCustomer = replyToPM.FromCustomer;
// }
// else
// {
// return RedirectToRoute("PrivateMessages");
// }
//}
//else
//{
// toCustomer = _customerService.GetCustomerById(model.ToCustomerId);
//}
//IsGuest found in C:\Users\Nicholas\Documents\My Documents\NopCommerce\Libraries\Nop.Core\Domain\Customers\CustomerExtensions.cs
if (toCustomer == null || toCustomer.IsGuest())
{
return RedirectToRoute("PrivateMessages"); //TODO: CHANGE THIS REDIRECT? seems to be working if guest; test if not guest but no product monitors
}
model.ToCustomerId = toCustomer.Id;
model.CustomerToName = toCustomer.FormatUserName();
model.AllowViewingToProfile = _customerSettings.AllowViewingProfiles && !toCustomer.IsGuest();
if (ModelState.IsValid)
{
try
{
string subject = model.Subject;
if (_forumSettings.PMSubjectMaxLength > 0 && subject.Length > _forumSettings.PMSubjectMaxLength)
{
subject = subject.Substring(0, _forumSettings.PMSubjectMaxLength);
}
var text = model.Message;
if (_forumSettings.PMTextMaxLength > 0 && text.Length > _forumSettings.PMTextMaxLength)
{
text = text.Substring(0, _forumSettings.PMTextMaxLength);
}
var nowUtc = DateTime.UtcNow;
var privateMessage = new PrivateMessage
{
StoreId = _storeContext.CurrentStore.Id,
ToCustomerId = toCustomer.Id,
FromCustomerId = _workContext.CurrentCustomer.Id,
Subject = subject,
Text = text,
IsDeletedByAuthor = false,
//.........这里部分代码省略.........
示例13: SendPM
public ActionResult SendPM(PrivateMessageModel model)
{
if (!AllowPrivateMessages())
{
return RedirectToAction("index", "home");
}
if (_workContext.CurrentCustomer.IsGuest())
{
return new HttpUnauthorizedResult();
}
Customer toCustomer = null;
var replyToPM = _forumService.GetPrivateMessageById(model.ReplyToMessageId);
if (replyToPM != null)
{
if (replyToPM.ToCustomerId == _workContext.CurrentCustomer.Id || replyToPM.FromCustomerId == _workContext.CurrentCustomer.Id)
{
toCustomer = replyToPM.FromCustomer;
}
else
{
return RedirectToAction("Index");
}
}
else
{
toCustomer = _customerService.GetCustomerById(model.ToCustomerId);
}
if (toCustomer == null || toCustomer.IsGuest())
{
return RedirectToAction("Index");
}
model.customerToName = toCustomer.FormatUserName();
if (ModelState.IsValid)
{
try
{
string subject = model.Subject;
var maxSubjectLength = _forumSettings.PMSubjectMaxLength;
if (maxSubjectLength > 0 && subject.Length > maxSubjectLength)
{
subject = subject.Substring(0, maxSubjectLength);
}
var text = model.Message;
var maxPostLength = _forumSettings.PMTextMaxLength;
if (maxPostLength > 0 && text.Length > maxPostLength)
{
text = text.Substring(0, maxPostLength);
}
var nowUtc = DateTime.UtcNow;
var privateMessage = new PrivateMessage
{
ToCustomerId = toCustomer.Id,
FromCustomerId = _workContext.CurrentCustomer.Id,
Subject = subject,
Text = text,
IsDeletedByAuthor = false,
IsDeletedByRecipient = false,
IsRead = false,
CreatedOnUtc = nowUtc
};
_forumService.InsertPrivateMessage(privateMessage);
return RedirectToAction("Index", new {tab = "sent"});
}
catch (Exception ex)
{
ModelState.AddModelError("", ex.Message);
}
}
return View(model);
}
示例14: SendPM
public ActionResult SendPM(PrivateMessageModel model)
{
if (!AllowPrivateMessages())
{
return RedirectToAction("index", "home");
}
if (_workContext.CurrentCustomer.IsGuest())
{
return new HttpUnauthorizedResult();
}
Customer toCustomer = null;
var replyToPM = _forumService.GetPrivateMessageById(model.ReplyToMessageId);
if (replyToPM != null)
{
if (replyToPM.ToCustomerId == _workContext.CurrentCustomer.Id || replyToPM.FromCustomerId == _workContext.CurrentCustomer.Id)
{
toCustomer = replyToPM.FromCustomer;
}
else
{
return RedirectToAction("Index");
}
}
else
{
toCustomer = _customerService.GetCustomerById(model.ToCustomerId);
}
if (toCustomer == null || toCustomer.IsGuest())
{
return RedirectToAction("Index");
}
try
{
string subject = model.Subject;
if (subject != null)
{
subject = subject.Trim();
}
if (String.IsNullOrEmpty(subject))
{
throw new NopException(_localizationService.GetResource("PrivateMessages.SubjectCannotBeEmpty"));
}
var maxSubjectLength = _forumSettings.PMSubjectMaxLength;
if (maxSubjectLength > 0 && subject.Length > maxSubjectLength)
{
subject = subject.Substring(0, maxSubjectLength);
}
var text = model.Message;
if (text != null)
{
text = text.Trim();
}
if (String.IsNullOrEmpty(text))
{
throw new NopException(_localizationService.GetResource("PrivateMessages.MessageCannotBeEmpty"));
}
var maxPostLength = _forumSettings.PMTextMaxLength;
if (maxPostLength > 0 && text.Length > maxPostLength)
{
text = text.Substring(0, maxPostLength);
}
var nowUtc = DateTime.UtcNow;
var privateMessage = new PrivateMessage
{
ToCustomerId = toCustomer.Id,
FromCustomerId = _workContext.CurrentCustomer.Id,
Subject = subject,
Text = text,
IsDeletedByAuthor = false,
IsDeletedByRecipient = false,
IsRead = false,
CreatedOnUtc = nowUtc
};
_forumService.InsertPrivateMessage(privateMessage);
return RedirectToAction("Index", new { tab = "sent" });
}
catch (Exception ex)
{
model.PostError = ex.Message;
}
return View(model);
}