Пример #1
0
        public ActionResult NewComment(string commentBody, string comUserName, string slug, string pageId)
        {
            List <int> numlist  = new List <int>();
            int        num      = 0;
            var        comments = _blogRepository.GetComments().ToList();

            if (comments.Count() != 0)
            {
                foreach (var cmnt in comments)
                {
                    var comid = cmnt.Id;
                    Int32.TryParse(comid.Replace("cmt", ""), out num);
                    numlist.Add(num);
                }
                numlist.Sort();
                num = numlist.Last();
                num++;
            }
            else
            {
                num = 1;
            }
            var newid = "cmt" + num.ToString();

            Comment comment = new Comment
            {
                Id           = newid,
                PageId       = pageId,
                DateTime     = DateTime.Now,
                UserName     = comUserName,
                Body         = commentBody,
                NetLikeCount = 0,
            };

            _blogRepository.AddNewComment(comment);

            if (pageId.Contains("post"))
            {
                return(RedirectToAction("Post", new { slug = slug }));
            }
            else
            {
                return(RedirectToAction("Index", "Blog"));
            }
        }