public async Task <IActionResult> Edit(int id, [Bind("Id,NewsID,Name,Email,Comment,DateTime")] NewsComments newsComments)
        {
            if (id != newsComments.Id)
            {
                return(NotFound());
            }

            try
            {
                newsComments.NewsID   = id;
                newsComments.DateTime = DateTime.Now;
                _context.Add(newsComments);
                await _context.SaveChangesAsync();

                SendMessage(newsComments);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NewsCommentsExists(newsComments.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            //return RedirectToAction(nameof(Index));

            var comments = await _context.NewsComments.Where(x => x.NewsID == newsComments.NewsID).ToListAsync();

            return(View("Index", comments));
        }
        public ActionResult Update(int ID, NewsComments commentMod)
        {
            if (commentMod.UserID != User.Identity.GetUserId())
            {
                TempData["redirectMessage"]      = "Permission denied";
                TempData["redirectMessageClass"] = "danger";
                return(RedirectToAction("Index"));
            }

            NewsComments comment = db.NewsComments.Find(ID);

            if (TryUpdateModel(comment))
            {
                if (ModelState.IsValid)
                {
                    comment.Content = commentMod.Content;
                    db.SaveChanges();
                    TempData["redirectMessage"]      = "The comment has been modified";
                    TempData["redirectMessageClass"] = "success";
                    return(Redirect("/news/article/" + comment.ArticleID));
                }
                else
                {
                    return(View("Update", comment));
                }
            }
            else
            {
                TempData["redirectMessage"]      = "The comment has not been modified - TryUpdateModel";
                TempData["redirectMessageClass"] = "danger";

                return(View("Update", comment));
            }
        }
 private void SendMessage(NewsComments newsComments)
 {
     try
     {
         MailMessage m = new MailMessage("*****@*****.**", newsComments.Email);
         m.Body = newsComments.Name + " Ваша публикация опубликована, Спасибо Вам";
         SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
         smtp.UseDefaultCredentials = true;
         smtp.Credentials           = new NetworkCredential("sashaberduchev", "SashaVinichuk");
         smtp.EnableSsl             = true;
         smtp.Send(m);
     }
     catch (Exception exp)
     {
         Trace.WriteLine(exp.ToString());
         string     expstr        = exp.ToString();
         FileStream fileStreamLog = new FileStream(@"Mail.log", FileMode.Append);
         for (int i = 0; i < expstr.Length; i++)
         {
             byte[] array = Encoding.Default.GetBytes(expstr.ToString());
             fileStreamLog.Write(array, 0, array.Length);
         }
         fileStreamLog.Close();
     }
 }
        public ActionResult Update(int ID)
        {
            NewsComments comment = db.NewsComments.Find(ID);

            if (TempData.ContainsKey("redirectMessage"))
            {
                ViewBag.notification = TempData["redirectMessage"].ToString();
                if (TempData.ContainsKey("redirectMessageClass"))
                {
                    ViewBag.notificationClass = TempData["redirectMessageClass"].ToString();
                }
                else
                {
                    ViewBag.notificationClass = "info";
                }
            }

            if (comment.UserID == User.Identity.GetUserId())
            {
                return(View("Update", comment));
            }
            else
            {
                TempData["redirectMessage"]      = "Permission denied";
                TempData["redirectMessageClass"] = "danger";
                return(RedirectToAction("Index"));
            }
        }
        public List <NewsComments> GetCommentsByNewsId(string id)
        {
            ISession            session  = SessionManager.GetSession();
            List <NewsComments> comments = new List <NewsComments>();

            if (session == null)
            {
                return(null);
            }

            var guestsData = session.Execute("select * from \"NewsComments\" where \"newsID\"='" + id + "'");

            foreach (var guestData in guestsData)
            {
                NewsComments comment = new NewsComments();
                comment.newsID     = guestData["newsID"] != null ? guestData["newsID"].ToString() : string.Empty;
                comment.commentID  = guestData["commentID"] != null ? guestData["commentID"].ToString() : string.Empty;
                comment.username   = guestData["username"] != null ? guestData["username"].ToString() : string.Empty;
                comment.comment    = guestData["comment"] != null ? guestData["comment"].ToString() : string.Empty;
                comment.authorName = guestData["authorName"] != null ? guestData["authorName"].ToString() : string.Empty;
                comment.dateTime   = guestData["dateTime"] != null ? guestData["dateTime"].ToString() : string.Empty;

                comments.Add(comment);
            }

            return(comments);
        }
        public ActionResult Delete(int ID)
        {
            try
            {
                NewsComments comment = db.NewsComments.Find(ID);
                if (comment.UserID == User.Identity.GetUserId() || User.IsInRole("Administrator"))
                {
                    db.NewsComments.Remove(comment);
                    db.SaveChanges();

                    TempData["redirectMessage"]      = "The comment has been deleted.";
                    TempData["redirectMessageClass"] = "info";
                }
                else
                {
                    TempData["redirectMessage"]      = "Permission denied.";
                    TempData["redirectMessageClass"] = "danger";
                }
                return(Redirect("/news/article/" + comment.ArticleID));
            }
            catch (Exception e)
            {
                TempData["redirectMessage"]      = "The comment has not been deleted " + e.Message;
                TempData["redirectMessageClass"] = "danger";
                return(Redirect("/news"));
            }
        }
        // GET: NewsComments/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var newsComments = await _context.NewsComments.Where(x => x.NewsID == id).FirstOrDefaultAsync();

            if (newsComments == null)
            {
                NewsComments newsComments1 = new NewsComments
                {
                    NewsID   = Convert.ToInt32(id),
                    Comment  = "",
                    DateTime = DateTime.Now,
                    Email    = "",
                    Name     = ""
                };
                _context.NewsComments.Add(newsComments1);
                _context.SaveChanges();
                var news = await _context.NewsComments.Where(x => x.NewsID == id).FirstOrDefaultAsync();

                return(View(news));
            }
            return(View(newsComments));
        }
Esempio n. 8
0
        public NewsComments AddComment([FromBody] NewsComments nc)
        {
            ISession            session  = SessionManager.GetSession();
            List <NewsComments> comments = new List <NewsComments>();


            if (session == null)
            {
                return(null);
            }

            RowSet guest = session.Execute("insert into \"NewsComments\"(\"newsID\", \"commentID\", username, comment, \"authorName\", \"dateTime\") values ('" + nc.newsID + "', '" + nc.commentID + "', '" + nc.username + "', '" + nc.comment + "', '" + nc.authorName + "', '" + nc.dateTime + "')");

            var data = session.Execute("select * from \"NewsComments\"where \"commentID\"='" + nc.commentID + "' and \"newsID\"='" + nc.newsID + "'");

            foreach (var guestData in data)
            {
                NewsComments comment = new NewsComments();
                comment.newsID     = guestData["newsID"] != null ? guestData["newsID"].ToString() : string.Empty;
                comment.commentID  = guestData["commentID"] != null ? guestData["commentID"].ToString() : string.Empty;
                comment.username   = guestData["username"] != null ? guestData["username"].ToString() : string.Empty;
                comment.comment    = guestData["comment"] != null ? guestData["comment"].ToString() : string.Empty;
                comment.authorName = guestData["authorName"] != null ? guestData["authorName"].ToString() : string.Empty;
                comment.dateTime   = guestData["dateTime"] != null ? guestData["dateTime"].ToString() : string.Empty;

                comments.Add(comment);
            }
            return(comments.FirstOrDefault());
        }
        public async Task <bool> DeleteCommentAsync(int id)
        {
            var newsComments = NewsComments.Where(n => n.CommentID == id).FirstOrDefault();
            var result       = await StoreManager.NewsDetailsService.DeleteCommentAsync(newsComments.CommentID);

            if (result.Success)
            {
                var index = NewsComments.IndexOf(newsComments);
                NewsComments.RemoveAt(index);
                if (NewsComments.Count == 0)
                {
                    LoadStatus = LoadMoreStatus.StausNodata;
                }
                NewsDetails.CommentDisplay = (news.CommentCount = news.CommentCount - 1).ToString();
            }
            else
            {
                Crashes.TrackError(new Exception()
                {
                    Source = result.Message
                });
                Toast.SendToast("删除失败");
            }
            return(result.Success);
        }
Esempio n. 10
0
 private async void OnResult(NewsComments result)
 {
     if (result != null)
     {
         ViewModel.EditComment(result);
         await formsWebView.InjectJavascriptAsync("updateComment(" + JsonConvert.SerializeObject(result) + ");");
     }
 }
Esempio n. 11
0
 private void OnResult(NewsComments result)
 {
     if (result != null)
     {
         ViewModel.AddComment(result);
         NewsDetailsView.ScrollTo(ViewModel.NewsComments.Last(), ScrollToPosition.Start, false);
     }
 }
        public async Task <IActionResult> Create([Bind("Id,NewsID,Name,Email,Comment,DateTime")] NewsComments newsComments)
        {
            if (ModelState.IsValid)
            {
                newsComments.DateTime = DateTime.Now;
                _context.Add(newsComments);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(newsComments));
        }
 public NewsCommentPopupPage(News news, Action <NewsComments> result, NewsComments comments = null)
 {
     this.news     = news;
     this.comments = comments;
     this.result   = result;
     InitializeComponent();
     BindingContext = new NewsDetailsViewModel(news);
     if (comments != null)
     {
         this.Comment.Text = comments.CommentContent;
     }
     this.Comment.Focus();
 }
Esempio n. 14
0
        public async Task <List <NewsComments> > ReloadCommentsAsync()
        {
            try
            {
                LoadStatus = LoadMoreStatus.StausLoading;

                var result = await StoreManager.NewsDetailsService.GetCommentAsync(news.Id, pageIndex, pageSize);

                if (result.Success)
                {
                    var newsComments = JsonConvert.DeserializeObject <List <NewsComments> >(result.Message.ToString());
                    if (newsComments.Count > 0)
                    {
                        if (pageIndex == 1)
                        {
                            NewsComments.Clear();
                        }
                        NewsComments.AddRange(newsComments);
                        pageIndex++;
                        if (newsComments.Count < pageSize)
                        {
                            LoadStatus = LoadMoreStatus.StausEnd;
                        }
                        else
                        {
                            LoadStatus = LoadMoreStatus.StausDefault;
                        }
                    }
                    else
                    {
                        LoadStatus = pageIndex > 1 ? LoadMoreStatus.StausEnd : LoadMoreStatus.StausNodata;
                    }
                }
                else
                {
                    Crashes.TrackError(new Exception()
                    {
                        Source = result.Message
                    });
                    LoadStatus = LoadMoreStatus.StausError;
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                LoadStatus = LoadMoreStatus.StausError;
            }
            return(NewsComments);
        }
Esempio n. 15
0
 public NewsCommentPopupPage(News news, Action <NewsComments> result, NewsComments comments = null)
 {
     InitializeComponent();
     Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page.SetUseSafeArea(this, true);
     this.news      = news;
     this.comments  = comments;
     this.result    = result;
     BindingContext = new NewsDetailsViewModel(news);
     if (comments != null)
     {
         this.Comment.Text = comments.CommentContent;
     }
     this.Comment.Focus();
     ViewModel.IsBusy = false;
 }
Esempio n. 16
0
        public ActionResult AddComment(NewsComments comment, int ID, string username)
        {
            ApplicationDbContext db = new ApplicationDbContext();

            if (ModelState.IsValid)
            {
                comment.NewsId  = ID;
                comment.Author  = Author();
                comment.DatePub = DateTime.Now;
                db.NewsCommentss.Add(comment);
                db.SaveChanges();

                return(RedirectToAction("Show"));
            }
            return(View());
        }
Esempio n. 17
0
        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;
            }
        }
Esempio n. 18
0
        async Task ExecuteCommentCommandAsync()
        {
            var result = await StoreManager.NewsDetailsService.GetCommentAsync(news.Id, pageIndex, pageSize);

            if (result.Success)
            {
                var news = JsonConvert.DeserializeObject <List <NewsComments> >(result.Message.ToString());
                if (news.Count > 0)
                {
                    if (pageIndex == 1 && NewsComments.Count > 0)
                    {
                        NewsComments.Clear();
                    }
                    NewsComments.AddRange(news);
                    pageIndex++;
                    if (NewsComments.Count >= pageSize)
                    {
                        LoadStatus  = LoadMoreStatus.StausDefault;
                        CanLoadMore = true;
                    }
                    else
                    {
                        LoadStatus  = LoadMoreStatus.StausEnd;
                        CanLoadMore = false;
                    }
                }
                else
                {
                    CanLoadMore = false;
                    LoadStatus  = pageIndex > 1 ? LoadMoreStatus.StausEnd : LoadMoreStatus.StausNodata;
                }
            }
            else
            {
                Log.SaveLog("NewsDetailsViewModel.GetCommentAsync", new Exception()
                {
                    Source = result.Message
                });
                LoadStatus = pageIndex > 1 ? LoadMoreStatus.StausError : LoadMoreStatus.StausFail;
            }
        }
 private void ClosePopupPage(string result)
 {
     if (result != null)
     {
         if (comments == null)
         {
             comments            = new NewsComments();
             comments.UserName   = UserSettings.Current.DisplayName;
             comments.FaceUrl    = UserSettings.Current.Avatar;
             comments.Floor      = 0;
             comments.CommentID  = 0;
             comments.AgreeCount = 0;
             comments.AntiCount  = 0;
             comments.ContentID  = 0;
             comments.UserGuid   = UserSettings.Current.UserId;
         }
         comments.CommentContent = result;
         comments.DateAdded      = DateTime.Now;
         this.result.Invoke(comments);
     }
     PopupNavigation.PopAsync();
 }
Esempio n. 20
0
        public ActionResult NewsCommentsEdit(int id)
        {
            BackEndNewsCommentsEdit backEndNewsCommentsEdit = new BackEndNewsCommentsEdit();

            NewsComments newsComments = new NewsComments();
            NewsComment  newsComment  = newsComments.GetNewsComment(id);
            SingleNews   singleNews   = new News().GetSingleNews(newsComment.NewsId, ConfigurationManager.AppSettings["AdminLanguageCode"]);

            if (singleNews.IsNotNull() && newsComment.IsNotNull())
            {
                backEndNewsCommentsEdit.NewsId    = newsComment.NewsId;
                backEndNewsCommentsEdit.NewsTitle = singleNews.NewsTitle;
                backEndNewsCommentsEdit.IsActive  = newsComment.IsActive;
                backEndNewsCommentsEdit.Comment   = newsComment.Comment;
            }
            else
            {
                ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.ItemDoesNotExist);
                ViewData.IsFormVisible(false);
            }

            return(View(backEndNewsCommentsEdit));
        }
        public ActionResult Create([Bind(Exclude = "UserID, PublishDate")] NewsComments comment)
        {
            comment.PublishDate = DateTime.Now;
            comment.UserID      = User.Identity.GetUserId();

            try
            {
                Debug.WriteLine(ModelState.IsValid);

                if (ModelState.IsValid)
                {
                    db.NewsComments.Add(comment);
                    db.SaveChanges();
                    TempData["redirectMessage"]      = "The comment has been published.";
                    TempData["redirectMessageClass"] = "success";

                    return(Redirect("/news/article/" + comment.ArticleID));
                }
                else
                {
                    string messages = string.Join("; ", ModelState.Values
                                                  .SelectMany(x => x.Errors)
                                                  .Select(x => x.ErrorMessage));
                    Debug.WriteLine(messages);

                    TempData["redirectMessage"]      = messages + " The comment has not been published.";
                    TempData["redirectMessageClass"] = "danger";
                    return(Redirect("/news/article/" + comment.ArticleID));
                }
            }
            catch (Exception e)
            {
                TempData["redirectMessage"]      = "The comment has not been published.";
                TempData["redirectMessageClass"] = "danger";
                return(Redirect("/news/article/" + comment.ArticleID));
            }
        }
 protected override Func <ServiceOperationResult> DeleteEntityAndReturnOperationResult(NewsComments news, bool onlyChangeFlag = true)
 {
     return(() => _newsCommentService.DeleteNewsComment(news, onlyChangeFlag));
 }
 protected override Func <ServiceOperationResult> UpdateEntityAndReturnOperationResult(NewsComments news)
 {
     return(() => _newsCommentService.UpdateNewsComment(news));
 }
Esempio n. 24
0
        public ActionResult Index(FrontEndCmsPage page, int?p, string c, string d)
        {
            News news = new News();

            FrontEndNews frontEndNews;

            if (page.Parameter.IsEmptyOrWhiteSpace())
            {
                int?   filterCategoryId = c.ConvertTo <int?>(null, true);
                string filterNewsDate   = d;

                List <SingleNews> newsList = news.GetNews(
                    page.LanguageCode,
                    isActive: true,
                    isCategoryActive: true,
                    categoryId: filterCategoryId,
                    newsDate: (filterNewsDate.IsNotEmptyOrWhiteSpace() ? ("1-" + d).ConvertTo <DateTime?>(null, true) : null)
                    ).OrderByDescending(i => i.NewsDate).ToList();

                if (newsList.IsNotNull())
                {
                    frontEndNews = new FrontEndNews()
                    {
                        LanguageCode      = page.LanguageCode,
                        NewsList          = newsList.ToBootstrapPagedList(p, 5),
                        FilterCategoryId  = filterCategoryId,
                        FilterNewsDate    = filterNewsDate,
                        NewsId            = null,
                        NewsDate          = null,
                        UserName          = null,
                        CategoryId        = null,
                        CategoryName      = null,
                        MainImageFilePath = null,
                        NewsTitle         = null,
                        NewsContent       = null
                    };
                }
                else
                {
                    frontEndNews = new FrontEndNews();
                }
            }
            else
            {
                if (page.Parameter.ToLower() == "rss")
                {
                    Server.TransferRequest("~/OutputNews/Rss/?langCode=" + page.LanguageCode);
                    return(null);
                }
                else if (page.Parameter.ToLower() == "atom10")
                {
                    Server.TransferRequest("~/OutputNews/Atom10/?langCode=" + page.LanguageCode);
                    return(null);
                }
                else
                {
                    SingleNews singleNews = news.GetSingleNews(page.Parameter.Split('-').FirstOrDefault().ConvertTo <int?>(null, true), page.LanguageCode);

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

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

            return(View(frontEndNews));
        }
Esempio n. 25
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));
        }