Пример #1
0
        /// <summary>
        /// Gets a news comment
        /// </summary>
        /// <param name="NewsCommentID">News comment identifer</param>
        /// <returns>News comment</returns>
        public static NewsComment GetNewsCommentByID(int NewsCommentID)
        {
            if (NewsCommentID == 0)
            {
                return(null);
            }

            DBNewsComment dbItem = DBProviderManager <DBNewsProvider> .Provider.GetNewsCommentByID(NewsCommentID);

            NewsComment newsComment = DBMapping(dbItem);

            return(newsComment);
        }
Пример #2
0
        private static NewsCommentCollection DBMapping(DBNewsCommentCollection dbCollection)
        {
            if (dbCollection == null)
            {
                return(null);
            }

            NewsCommentCollection collection = new NewsCommentCollection();

            foreach (DBNewsComment dbItem in dbCollection)
            {
                NewsComment item = DBMapping(dbItem);
                collection.Add(item);
            }

            return(collection);
        }
Пример #3
0
        /// <summary>
        /// Inserts a news comment
        /// </summary>
        /// <param name="NewsID">The news identifier</param>
        /// <param name="CustomerID">The customer identifier</param>
        /// <param name="Title">The title</param>
        /// <param name="Comment">The comment</param>
        /// <param name="CreatedOn">The date and time of instance creation</param>
        /// <param name="notify">A value indicating whether to notify the store owner</param>
        /// <returns>News comment</returns>
        public static NewsComment InsertNewsComment(int NewsID, int CustomerID, string Title,
                                                    string Comment, DateTime CreatedOn, bool notify)
        {
            CreatedOn = DateTimeHelper.ConvertToUtcTime(CreatedOn);

            DBNewsComment dbItem = DBProviderManager <DBNewsProvider> .Provider.InsertNewsComment(NewsID, CustomerID, Title,
                                                                                                  Comment, CreatedOn);

            NewsComment newsComment = DBMapping(dbItem);

            if (notify)
            {
                MessageManager.SendNewsCommentNotificationMessage(newsComment, LocalizationManager.DefaultAdminLanguage.LanguageID);
            }

            return(newsComment);
        }
Пример #4
0
        private static NewsComment DBMapping(DBNewsComment dbItem)
        {
            if (dbItem == null)
            {
                return(null);
            }

            NewsComment item = new NewsComment();

            item.NewsCommentID = dbItem.NewsCommentID;
            item.NewsID        = dbItem.NewsID;
            item.CustomerID    = dbItem.CustomerID;
            item.Title         = dbItem.Title;
            item.Comment       = dbItem.Comment;
            item.CreatedOn     = dbItem.CreatedOn;

            return(item);
        }
Пример #5
0
        private static NewsComment DBMapping(DBNewsComment dbItem)
        {
            if (dbItem == null)
            {
                return(null);
            }

            var item = new NewsComment();

            item.NewsCommentId = dbItem.NewsCommentId;
            item.NewsId        = dbItem.NewsId;
            item.CustomerId    = dbItem.CustomerId;
            item.IPAddress     = dbItem.IPAddress;
            item.Title         = dbItem.Title;
            item.Comment       = dbItem.Comment;
            item.CreatedOn     = dbItem.CreatedOn;

            return(item);
        }
Пример #6
0
        /// <summary>
        /// Updates the news comment
        /// </summary>
        /// <param name="newsComment">News comment</param>
        public void UpdateNewsComment(NewsComment newsComment)
        {
            if (newsComment == null)
            {
                throw new ArgumentNullException("newsComment");
            }

            newsComment.IPAddress = CommonHelper.EnsureNotNull(newsComment.IPAddress);
            newsComment.IPAddress = CommonHelper.EnsureMaximumLength(newsComment.IPAddress, 100);
            newsComment.Title     = CommonHelper.EnsureNotNull(newsComment.Title);
            newsComment.Title     = CommonHelper.EnsureMaximumLength(newsComment.Title, 1000);
            newsComment.Comment   = CommonHelper.EnsureNotNull(newsComment.Comment);


            if (!_context.IsAttached(newsComment))
            {
                _context.NewsComments.Attach(newsComment);
            }

            _context.SaveChanges();
        }
Пример #7
0
        /// <summary>
        /// Replaces a message template tokens
        /// </summary>
        /// <param name="newsComment">News comment</param>
        /// <param name="template">Template</param>
        /// <returns>New template</returns>
        private string ReplaceMessageTemplateTokens(NewsComment newsComment,
            string template)
        {
            var tokens = new NameValueCollection();
            tokens.Add("Store.Name", IoC.Resolve<ISettingManager>().StoreName);
            tokens.Add("Store.URL", IoC.Resolve<ISettingManager>().StoreUrl);
            tokens.Add("Store.Email", this.DefaultEmailAccount.Email);

            tokens.Add("NewsComment.NewsTitle", HttpUtility.HtmlEncode(newsComment.News.Title));

            foreach (string token in tokens.Keys)
            {
                template = Replace(template, String.Format(@"%{0}%", token), tokens[token]);
            }

            return template;
        }
Пример #8
0
        /// <summary>
        /// Sends a news comment notification message to a store owner
        /// </summary>
        /// <param name="newsComment">News comment</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public int SendNewsCommentNotificationMessage(NewsComment newsComment, int languageId)
        {
            if (newsComment == null)
                throw new ArgumentNullException("newsComment");

            string templateName = "News.NewsComment";
            var localizedMessageTemplate = this.GetLocalizedMessageTemplate(templateName, languageId);
            if(localizedMessageTemplate == null || !localizedMessageTemplate.IsActive)
                return 0;

            var emailAccount = localizedMessageTemplate.EmailAccount;

            string subject = ReplaceMessageTemplateTokens(newsComment, localizedMessageTemplate.Subject);
            string body = ReplaceMessageTemplateTokens(newsComment, localizedMessageTemplate.Body);
            string bcc = localizedMessageTemplate.BccEmailAddresses;
            var from = new MailAddress(emailAccount.Email, emailAccount.DisplayName);
            var to = new MailAddress(emailAccount.Email, emailAccount.DisplayName);
            var queuedEmail = InsertQueuedEmail(5, from, to, string.Empty, bcc, subject, body,
                DateTime.UtcNow, 0, null, emailAccount.EmailAccountId);
            return queuedEmail.QueuedEmailId;
        }
Пример #9
0
        /// <summary>
        /// Updates the news comment
        /// </summary>
        /// <param name="newsComment">News comment</param>
        public void UpdateNewsComment(NewsComment newsComment)
        {
            if (newsComment == null)
                throw new ArgumentNullException("newsComment");

            newsComment.IPAddress = CommonHelper.EnsureNotNull(newsComment.IPAddress);
            newsComment.IPAddress = CommonHelper.EnsureMaximumLength(newsComment.IPAddress, 100);
            newsComment.Title = CommonHelper.EnsureNotNull(newsComment.Title);
            newsComment.Title = CommonHelper.EnsureMaximumLength(newsComment.Title, 1000);
            newsComment.Comment = CommonHelper.EnsureNotNull(newsComment.Comment);

            if (!_context.IsAttached(newsComment))
                _context.NewsComments.Attach(newsComment);

            _context.SaveChanges();
        }