public void AddComment(NewsComments comment)
        {
            var book = NewsComments.Where(b => b.CommentID == comment.CommentID).FirstOrDefault();

            if (book == null)
            {
                NewsComments.Add(comment);
                NewsDetails.CommentDisplay = (news.CommentCount = news.CommentCount + 1).ToString();
            }
            else
            {
                var index = NewsComments.IndexOf(book);
                NewsComments[index] = comment;
            }
            if (LoadStatus == LoadMoreStatus.StausNodata)
            {
                LoadStatus = LoadMoreStatus.StausEnd;
            }
        }
Beispiel #2
0
        public ActionResult Index(FrontEndCmsPage page, FrontEndNews frontEndNews)
        {
            News news = new News();

            if (page.Parameter.IsNotEmptyOrWhiteSpace())
            {
                SingleNews singleNews = news.GetSingleNews(page.Parameter.Split('-').FirstOrDefault().ConvertTo <int?>(null, true), page.LanguageCode);

                if (singleNews.IsNotNull())
                {
                    NewsComments newsComments = new NewsComments();

                    frontEndNews.LanguageCode      = page.LanguageCode;
                    frontEndNews.NewsList          = null;
                    frontEndNews.FilterCategoryId  = null;
                    frontEndNews.FilterNewsDate    = null;
                    frontEndNews.NewsId            = singleNews.NewsId;
                    frontEndNews.NewsDate          = singleNews.NewsDate;
                    frontEndNews.UserName          = singleNews.UserName;
                    frontEndNews.CategoryId        = singleNews.CategoryId;
                    frontEndNews.CategoryName      = singleNews.CategoryName;
                    frontEndNews.MainImageFilePath = singleNews.MainImageFilePath;
                    frontEndNews.NewsTitle         = singleNews.NewsTitle;
                    frontEndNews.NewsContent       = singleNews.NewsContent;
                    frontEndNews.NewsCommentList   = (newsComments.IsNotNull() ? newsComments.GetNewsComments(singleNews.NewsId, true) : null);
                }
                else
                {
                    frontEndNews = null;
                }
            }

            if (ModelState.IsValidOrRefresh() && frontEndNews.IsNotNull())
            {
                NewsConfiguration newsConfiguration = new NewsConfigurations().GetNewsConfiguration();

                NewsComments newsComments = new NewsComments();
                int?         result       = newsComments.Add((int)frontEndNews.NewsId,
                                                             newsConfiguration.IsCommentAutoApproved,
                                                             frontEndNews.NewsComment,
                                                             DateTime.Now,
                                                             FrontEndSessions.CurrentSubscription.Email);
                switch (result)
                {
                case 0:
                    ModelState.AddResult(ViewData, ModelStateResult.Success, Resources.Strings_News.CommentAdded);
                    ViewData.IsFormVisible(false);

                    GlobalConfiguration globalConfiguration = new GlobalConfigurations().GetGlobalConfiguration();

                    CultureInfoHelper.ForceBackEndLanguage();

                    string subject = Resources.Strings_News.EmailSubject.Replace("{$Url}", globalConfiguration.DomainName.ToUrl());
                    string body    = Resources.Strings_News.EmailBody
                                     .Replace("{$Url}", globalConfiguration.DomainName.ToUrl())
                                     .Replace("{$subscriptionEmail}", FrontEndSessions.CurrentSubscription.Email)
                                     .Replace("{$comment}", frontEndNews.NewsComment)
                                     .Replace("{$ipAddress}", Request.UserHostAddress);

                    CultureInfoHelper.RestoreFrontEndLanguage();

                    EmailHelper email = new EmailHelper(globalConfiguration.NotificationEmail, globalConfiguration.NotificationEmail, subject, body);
                    email.Send();
                    break;

                default:
                    ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.UnexpectedError + " (Database)");
                    break;
                }
            }

            return(View(frontEndNews));
        }