public ActionResult Comment([Bind(Include = "ArticleId, Comment")] ArticleComments artComment)
 {
     if (artComment.ArticleId <= 0)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "You have passed an invalid article."));
     }
     if (db.Articles.Any((art => art.Id == artComment.ArticleId)))
     {
         if (string.IsNullOrWhiteSpace(artComment.Comment))
         {
             TempData["EmptyComment"] = true;
         }
         else
         {
             artComment.Date   = DateTime.Now;
             artComment.UserId = User.Identity.Name;
             db.Comments.Add(artComment);
             db.SaveChanges();
         }
     }
     else
     {
         return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Article does not exist."));
     }
     return(RedirectToAction("Details", new { id = artComment.ArticleId }));
 }
Пример #2
0
        public ActionResult Edit(ArticleComment comment)
        {
            try
            {
                comment.LastUpdate = DateTime.Now;

                ViewBag.Success = true;

                if (comment.ID == -1)
                {
                    ArticleComments.Insert(comment);

                    UserNotifications.Send(UserID, String.Format("ویرایش نظر '{0}'", comment.Subject), "/Admin/ArticleComments/Edit/" + comment.ID, NotificationType.Success);

                    comment = new ArticleComment();
                }
                else
                {
                    ArticleComments.Update(comment);
                }
            }
            catch (Exception ex)
            {
                SetErrors(ex);
            }

            return(ClearView(model: comment));
        }
Пример #3
0
        public async Task AddComment(string firstName, string lastName, string email, string message, int id)
        {
            var com = new ArticleComments
            {
                Author   = firstName + " " + lastName,
                Company  = email,
                Created  = DateTime.Now,
                Dislikes = 0,
                Likes    = 0,
                Text     = message
            };
            var arc = _ctx.Article.First(x => x.Id == id);

            var list = new List <ArticleComments> {
                com
            };

            if (arc.ArticleComments != null)
            {
                list.AddRange(arc.ArticleComments);
            }
            IEnumerable <ArticleComments> allCom = list;

            arc.ArticleComments = allCom;

            _ctx.Update(arc);
            await _ctx.SaveChangesAsync();
        }
Пример #4
0
        public ActionResult CommentUpdateView(int CommentID)
        {
            ArticleComments   ac   = new ArticleComments();
            ArticleCommentsVO acvo = ac.OneSelect(CommentID);

            ViewBag.Comments  = acvo.Comments;
            ViewBag.CommentID = acvo.CommentID;
            return(View());
        }
Пример #5
0
        // GET: ArticleCommnets
        public ActionResult CommentList(string ArticleIDX, string pageNum, string start)
        {
            ArticleComments ac = new ArticleComments();

            ViewBag.ArticleIDX = ArticleIDX;
            ViewBag.pN         = pageNum;
            ViewBag.start      = start;
            ViewBag.end        = start + 9;
            return(View());
        }
Пример #6
0
        public ActionResult List(string groupTitle = "", int pageIndex = 0)
        {
            groupTitle = groupTitle.DeNormalizeForUrl();

            var group   = Groups.GetByTitle(groupTitle, _groupType);
            int?groupID = null;

            if (group != null)
            {
                groupID = group.ID;
            }

            if (pageIndex > 0)
            {
                pageIndex = pageIndex - 1;
            }
            else
            {
                pageIndex = 0;
            }

            var list           = Articles.GetBlogList(pageIndex, pageSize, OnlineStore.Models.Enums.ArticleType.Blog, DateTime.Now, groupID);
            var latestPosts    = Articles.GetLatestPosts(groupID.HasValue ? groupID.Value : (int?)null);
            var latestComments = ArticleComments.GetLatestComments(ArticleType.Blog, 6);

            var count      = Articles.CountBlogList(OnlineStore.Models.Enums.ArticleType.Blog, DateTime.Now, groupID);
            var totalPages = (int)Math.Ceiling((decimal)count / pageSize);
            var paging     = Utilities.MakePaging(totalPages, pageIndex + 1);

            foreach (var item in list)
            {
                try
                {
                    var user = Identity.OSUsers.GetByID(item.UserID);
                    item.UserTitle = user.Firstname + " " + user.Lastname;
                }
                catch (Exception ex)
                {
                    item.UserTitle = StaticValues.HomeTitle;
                }
            }

            var model = new BlogList
            {
                DataList         = list,
                GroupID          = groupID,
                Paging           = paging,
                TotalPages       = totalPages,
                CurrentPageIndex = pageIndex,
                LatestPosts      = latestPosts,
                LatestComments   = latestComments
            };

            return(View(url + "Index.cshtml", model: model));
        }
Пример #7
0
        public async Task <JsonResult> Get(int pageIndex, int pageSize, string pageOrder, int?articleID, string email, sbyte?articleCommentStatus)
        {
            if (pageOrder.Trim() == "ID")
            {
                pageOrder = "LastUpdate desc";
            }
            ArticleCommentStatus?status = null;

            if (articleCommentStatus.HasValue && articleCommentStatus != -1)
            {
                status = (ArticleCommentStatus)articleCommentStatus;
            }
            var list = ArticleComments.Get(pageIndex,
                                           pageSize,
                                           pageOrder,
                                           articleID,
                                           email,
                                           status);

            foreach (var item in list)
            {
                item.UserFullName = item.UserID != null
                                 ? (await UserManager.FindByIdAsync(item.UserID)).Firstname + " " + (await UserManager.FindByIdAsync(item.UserID)).Lastname
                                 : item.UserName;
            }

            int total     = ArticleComments.Count(articleID, email, status);
            int totalPage = (int)Math.Ceiling((decimal)total / pageSize);

            if (pageSize > total)
            {
                pageSize = total;
            }

            if (list.Count < pageSize)
            {
                pageSize = list.Count;
            }

            JsonResult result = new JsonResult()
            {
                Data = new
                {
                    TotalPages = totalPage,
                    PageIndex  = pageIndex,
                    PageSize   = pageSize,
                    Rows       = list
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            return(result);
        }
Пример #8
0
        public IActionResult CreateComment(int idArticle, ArticleComments comment)
        {
            var article = _context.Articles.Find(idArticle);

            if (article == null)
            {
                return(NotFound());
            }

            comment.ArticleID = idArticle;
            _context.ArticleComments.Add(comment);
            _context.SaveChanges();
            return(Ok());
        }
Пример #9
0
        public JsonResult AddComment(int id, string userName, string email, string subject, string text)
        {
            var jsonSuccessResult = new JsonSuccessResult();

            try
            {
                ArticleComment comment = new ArticleComment
                {
                    ArticleID     = id,
                    CommentStatus = ArticleCommentStatus.NotChecked,
                    UserName      = userName,
                    Email         = email,
                    Subject       = subject,
                    Text          = text,
                    LastUpdate    = DateTime.Now,
                    UserID        = User.Identity.IsAuthenticated ? UserID : null
                };

                ArticleComments.Insert(comment);

                // اطلاع رسانی به مدیر
                #region Apprise Admin

                string body = "مدیریت محترم، در بخش نظرات وبلاگ، نظر جدیدی ثبت شد:";
                body += "<br/>";
                body += String.Format("ایمیل: {0} <br/> موضوع: {1} <br/> پیام: {2}", email, subject, text);

                EmailServices.NotifyAdminsByEmail(AdminEmailType.NewBlogComment, body, null);

                #endregion Apprise Admin

                jsonSuccessResult.Success = true;
            }
            catch (DbException ex)
            {
                jsonSuccessResult.Errors  = ex.Errors.ToArray();
                jsonSuccessResult.Success = false;
            }
            catch (Exception ex)
            {
                jsonSuccessResult.Errors  = new string[] { ex.Message };
                jsonSuccessResult.Success = false;
            }

            return(new JsonResult()
            {
                Data = jsonSuccessResult
            });
        }
Пример #10
0
        public IActionResult UpdateComment(int idArticle, int idComment, ArticleComments comment)
        {
            var commentToFind = _context.ArticleComments
                                .SingleOrDefault(c => c.ArticleID == idArticle && c.CommentID == idComment);

            if (commentToFind == null)
            {
                return(NotFound());
            }

            commentToFind.Content = comment.Content;
            _context.ArticleComments.Update(commentToFind);
            _context.SaveChanges();
            return(Ok());
        }
Пример #11
0
        public ActionResult Edit(int?id)
        {
            ArticleComment comment;

            if (id.HasValue)
            {
                comment = ArticleComments.GetByID(id.Value);
            }
            else
            {
                comment = new ArticleComment();
            }

            return(View(model: comment));
        }
Пример #12
0
        public JsonResult CommentCreate(string ArticleIDX, string Contents)
        {
            string          result = string.Empty;
            ArticleComments ac     = new ArticleComments();
            string          ID     = Session["ID"].ToString();
            Boolean         check  = ac.CommentCreate(ArticleIDX, Contents, ID);

            ViewBag.ID = ID;
            if (check)
            {
                result = "OK";
            }
            else
            {
                result = "FAIL";
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #13
0
        public JsonResult UpdateCheck(string Comment, int CommentID)
        {
            string          result = string.Empty;
            ArticleComments ac     = new ArticleComments();
            Boolean         check  = ac.Update(Comment, CommentID);

            if (check)
            {
                result = "OK";
            }
            else
            {
                result = "FAIL";
            }


            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #14
0
        public JsonResult Delete(int id)
        {
            var jsonSuccessResult = new JsonSuccessResult();

            try
            {
                ArticleComments.Delete(id);
                jsonSuccessResult.Success = true;
            }
            catch (Exception ex)
            {
                jsonSuccessResult.Errors  = new string[] { ex.Message };
                jsonSuccessResult.Success = false;
            }

            return(new JsonResult()
            {
                Data = jsonSuccessResult
            });
        }
Пример #15
0
        public JsonResult Confirm(List <int> ids)
        {
            var jsonSuccessResult = new JsonSuccessResult();

            try
            {
                ArticleComments.Confirm(ids);

                jsonSuccessResult.Success = true;
            }
            catch (Exception ex)
            {
                jsonSuccessResult.Errors  = new string[] { ex.Message };
                jsonSuccessResult.Success = false;
            }

            return(new JsonResult()
            {
                Data = jsonSuccessResult
            });
        }
Пример #16
0
        public ActionResult SearchDetail(string KeyWord, string No, int pN, int start)
        {
            Articles          ar      = new Articles();
            ArticlesVO        article = ar.SearchDetail(KeyWord, No);
            List <ArticlesVO> list    = ar.SearchList(1, KeyWord);

            ViewBag.Max = list.First().Total;
            System.Diagnostics.Debug.WriteLine("SearchDetail.Max : " + list.First().Total);
            ViewBag.Contents       = article.Contents;
            ViewBag.Subject        = article.Title;
            ViewBag.ViewCount      = article.ViewCount;
            ViewBag.RegistMemberID = article.RegistMemberID;
            ViewBag.RegistDate     = article.RegistDate;
            ViewBag.No             = article.No;
            ViewBag.ArticleIDX     = article.ArticleIDX;
            ViewBag.sessionID      = Session["ID"];
            ViewBag.KeyWord        = KeyWord;

            //댓글

            ArticleComments          ac          = new ArticleComments();
            List <ArticleCommentsVO> CommentList = ac.CommentList(article.ArticleIDX, pN);

            if (CommentList.Count == 0)
            {
                ViewBag.Total = 0;
            }
            else
            {
                ViewBag.Total = CommentList.First().Total;
            }

            ViewBag.ArticleIDX = article.ArticleIDX;
            ViewBag.pN         = pN;
            ViewBag.start      = start;
            ViewBag.end        = start + 9;
            return(View(CommentList));
        }
Пример #17
0
        //게시판 글 단일 뷰
        public ActionResult Detail(string No, int pN, int start)
        {
            Articles          ar      = new Articles();
            ArticlesVO        article = ar.Detail(No);
            List <ArticlesVO> list    = ar.ArticleList(1);

            ViewBag.Max            = list.First().Total;
            ViewBag.Contents       = article.Contents;
            ViewBag.Subject        = article.Title;
            ViewBag.ViewCount      = article.ViewCount;
            ViewBag.RegistMemberID = article.RegistMemberID;
            ViewBag.RegistDate     = article.RegistDate;
            ViewBag.No             = article.No;
            ViewBag.ArticleIDX     = article.ArticleIDX;
            ViewBag.sessionID      = Session["ID"];

            //댓글

            ArticleComments          ac          = new ArticleComments();
            List <ArticleCommentsVO> CommentList = ac.CommentList(article.ArticleIDX, pN);

            if (CommentList.Count == 0)
            {
                ViewBag.Total = 0;
            }
            else
            {
                ViewBag.Total = CommentList.First().Total;
            }

            ViewBag.ArticleIDX = article.ArticleIDX;
            ViewBag.pN         = pN;
            ViewBag.start      = start;
            ViewBag.end        = start + 9;
            return(View(CommentList));
        }
Пример #18
0
        public ResultModel SaveComment(ArticleCommentDto ArticleComment)
        {
            var article = _ArticleRepository.GetById(ArticleComment.ArticleId);

            if (article == null)
            {
                return(new ResultModel(false, "Makale bulunamadı."));
            }

            if (ArticleComment.Id > 0)
            {
                var ArticleEntity = new ArticleComments
                {
                    Id        = ArticleComment.Id,
                    Email     = ArticleComment.Email,
                    Text      = ArticleComment.Text,
                    ArticleId = ArticleComment.ArticleId
                };

                _ArticleCommentRepository.Update(ArticleEntity);
            }
            else
            {
                var ArticleEntity = new ArticleComments
                {
                    Email     = ArticleComment.Email,
                    Text      = ArticleComment.Text,
                    ArticleId = ArticleComment.ArticleId
                };

                _ArticleCommentRepository.Create(ArticleEntity);
            }


            return(_unitOfWork.Commit());
        }
Пример #19
0
        public ActionResult Details(int id)
        {
            #region Details

            var blogDetails = Articles.GetBlogByID(id);

            if (blogDetails == null)
            {
                return(HttpNotFound());
            }

            try
            {
                var user = Identity.OSUsers.GetByID(blogDetails.UserID);
                blogDetails.UserTitle = user.Firstname + " " + user.Lastname;
            }
            catch (Exception)
            {
                blogDetails.UserTitle = StaticValues.HomeTitle;
            }

            blogDetails.Text = HttpUtility.HtmlDecode(blogDetails.Text);

            #endregion Details

            var latestPosts    = Articles.GetLatestPosts(blogDetails.GroupID);
            var latestComments = ArticleComments.GetLatestComments(ArticleType.Blog, 6, blogDetails.GroupID);
            var comments       = ArticleComments.GetByArticleID(id);
            var relatedPosts   = RelatedArticles.GetRelatedArticles(id);
            var group          = Groups.GetByID(blogDetails.GroupID);

            #region Products

            var products = Products.GetRandom();
            Products.FillProductItems(UserID, products, StaticValues.RelatedProductImageSize);

            var shopProducts = new RelatedProductSettings
            {
                Products = products,
                Title    = "فروشگاه آنلاین استور"
            };

            #endregion Products

            // increase Visits
            increaseVisits(id);

            BlogDetail model = new BlogDetail
            {
                BlogDetails    = blogDetails,
                LatestComments = latestComments,
                LatestPosts    = latestPosts,
                Comments       = comments,
                RelatedPosts   = relatedPosts,
                Products       = shopProducts
            };

            ViewBag.Title       = blogDetails.Title;
            ViewBag.Description = blogDetails.Summary;
            ViewBag.Keywords    = group.Title + ", " + group.TitleEn +
                                  ", " + blogDetails.Title.Split(' ').Aggregate((a, b) => b + ", " + a);
            ViewBag.OGType  = "article";
            ViewBag.OGImage = StaticValues.WebsiteUrl + StaticPaths.ArticleImages + blogDetails.Image;

            return(View(url + "Details.cshtml", model: model));
        }
        public ActionResult InsertComment(string Comment)
        {
            VwArticlesModel model = new VwArticlesModel();
            if (Session["User"] != null)
            {
                if (!string.IsNullOrEmpty(Comment))
                {
                    user = (Users)Session["User"];
                    string articleID = RouteData.Values["Id"].ToString();

                    double dblReplyID = 0;
                    ArticleComments articleComments = new ArticleComments();
                    SqlConnection LclConn = new SqlConnection();
                    SqlTransaction SetTransaction = null;
                    bool IsinTransaction = false;
                    if (LclConn.State != ConnectionState.Open)
                    {
                        articleComments.SetConnection = articleComments.OpenConnection(LclConn);
                        SetTransaction = LclConn.BeginTransaction(IsolationLevel.ReadCommitted);
                        IsinTransaction = true;
                    }
                    else
                    {
                        articleComments.SetConnection = LclConn;
                    }

                    articleComments.OptionID = 1;
                    articleComments.ReplyUserId = user.UserId;
                    articleComments.ArticleId = double.Parse(articleID.ToString());
                    articleComments.ReplyText = Comment;

                    articleComments.InsertedDate = DateTime.Now;

                    bool result = articleComments.CreateArticleComments(ref dblReplyID, SetTransaction);

                    if (IsinTransaction && result)
                    {
                        SetTransaction.Commit();

                        if (!Session["AskedUserEMail"].ToString().Contains("codeanalyze.com"))
                        {
                            Mail mail = new Mail();
                            string strLink = "www.codeanalyze.com/VA.aspx?QId=" + articleID.ToString() + "&QT=" + model.ArticleTitle + "";
                            mail.Body = "<a href=" + strLink + "\\>Click here to view solution to: " + model.ArticleTitle + "</a>";
                            mail.FromAdd = "*****@*****.**";
                            mail.Subject = "Code Analyze - Received response for " + model.ArticleTitle;
                            mail.ToAdd = Session["AskedUserEMail"].ToString();
                            mail.CCAdds = "*****@*****.**";
                            mail.IsBodyHtml = true;
                            mail.SendMail();
                        }
                    }
                    else
                    {
                        SetTransaction.Rollback();
                    }
                    articleComments.CloseConnection(LclConn);
                    ViewBag.ReplyId = dblReplyID;
                    model = SetDefaults();
                }
                else
                {
                    ViewBag.lblAck = "Please sign in to post your comment.";
                }

            }
            return View("../Articles/Details", model);
        }