当前位置: 首页>>代码示例>>C#>>正文


C# Forums.PrivateMessage类代码示例

本文整理汇总了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();
        }
开发者ID:jianghaihui,项目名称:nopCommerce,代码行数:35,代码来源:PrivateMessagePersistenceTests.cs

示例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);
        }
开发者ID:btolbert,项目名称:test-commerce,代码行数:30,代码来源:WorkflowMessageService.cs

示例3: GenerateTokens

 private IList<Token> GenerateTokens(PrivateMessage privateMessage)
 {
     var tokens = new List<Token>();
     _messageTokenProvider.AddStoreTokens(tokens);
     _messageTokenProvider.AddPrivateMessageTokens(tokens, privateMessage);
     return tokens;
 }
开发者ID:btolbert,项目名称:test-commerce,代码行数:7,代码来源:WorkflowMessageService.cs

示例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);
        }
开发者ID:emilianionascu,项目名称:NopCommerce,代码行数:83,代码来源:PrivateMessagesController.cs

示例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 });
        }
开发者ID:LaOrigin,项目名称:Leorigin,代码行数:45,代码来源:CustomerController.cs

示例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);
        }
开发者ID:rajendra1809,项目名称:nopCommerce,代码行数:38,代码来源:WorkflowMessageService.cs

示例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);
        }
开发者ID:RobinHoody,项目名称:nopCommerce,代码行数:16,代码来源:ForumService.cs

示例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);
            }
        }
开发者ID:RobinHoody,项目名称:nopCommerce,代码行数:22,代码来源:ForumService.cs

示例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);                
            }
        }
开发者ID:RobinHoody,项目名称:nopCommerce,代码行数:31,代码来源:ForumService.cs

示例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);
        }
开发者ID:jianghaihui,项目名称:nopCommerce,代码行数:8,代码来源:MessageTokenProvider.cs

示例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));
 }
开发者ID:alexgonchar,项目名称:WebArsenal,代码行数:5,代码来源:MessageTokenProvider.cs

示例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,
//.........这里部分代码省略.........
开发者ID:HumanSystems,项目名称:nopcommerce-dev,代码行数:101,代码来源:AUPublicController.cs

示例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);
        }
开发者ID:pquic,项目名称:qCommerce,代码行数:80,代码来源:PrivateMessagesController.cs

示例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);
        }
开发者ID:cmcginn,项目名称:StoreFront,代码行数:96,代码来源:PrivateMessagesController.cs


注:本文中的Nop.Core.Domain.Forums.PrivateMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。