public async Task <bool> SaveComment(TComment comment)
        {
            try
            {
                _context.Add(comment);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
 public bool PostComment(TComment c)
 {
     db.TComment.Add(c);
     try
     {
         db.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         //throw e;
         return(false);
     }
 }
Ejemplo n.º 3
0
        // GET: TComments/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TComment tComment = db.TComments.Find(id);

            if (tComment == null)
            {
                return(HttpNotFound());
            }
            return(View(tComment));
        }
Ejemplo n.º 4
0
        public ActionResult <Result> Publish([FromBody] TComment comment)
        {
            //获取用户信息
            string user_id = Token.GetUserId(HttpContext.Request.Headers["Authorization"].ToString().Substring(7));
            TUser  user    = userServer.Retrieve(new TUser()
            {
                UserId = user_id
            });

            comment.UserId = user.UserId;

            commentServer.Create(comment);

            return(new Result(200, "成功"));
        }
Ejemplo n.º 5
0
        // GET: TComments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TComment tComment = db.TComments.Find(id);

            if (tComment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.TID = new SelectList(db.TVShows, "TID", "Name", tComment.TID);
            return(View(tComment));
        }
Ejemplo n.º 6
0
        public ActionResult <Result> Like([FromRoute] string commentId, [FromRoute] short islike)
        {
            //获取用户信息
            string user_id = Token.GetUserId(HttpContext.Request.Headers["Authorization"].ToString().Substring(7));
            TUser  user    = userServer.Retrieve(new TUser()
            {
                UserId = user_id
            });

            TComment cmt = commentServer.Retrieve(new TComment {
                CommentId = commentId
            });
            TCommentLike tml = commentLikeServer.RetrieveByUserAndComment(user.UserId, commentId);

            if (cmt.UserId == user.UserId)
            {
                throw new ResultException($"不能{(islike == 0 ? "踩" : "赞")}自己的评论");
            }

            if (tml == null)//点赞
            {
                commentLikeServer.Create(new TCommentLike
                {
                    UserId    = user.UserId,
                    CommentId = commentId,
                    Like      = islike
                });
            }
            else if (tml.Like == 1 && islike == 0)//赞改为踩
            {
                tml.Like = 0;
                commentLikeServer.Update(tml);
            }
            else if (tml.Like == 0 && islike == 1)//踩改为赞
            {
                tml.Like = 1;
                commentLikeServer.Update(tml);
            }
            else//取消赞/踩
            {
                commentLikeServer.Delete(tml);
            }

            return(new Result(200, "成功"));
        }
Ejemplo n.º 7
0
        public async Task <bool> MailForComment(TComment comment)
        {
            string header = await FindEntryHeader(comment.EntryId);

            try
            {
                await ConfigureMail();

                MailMessage message = new MailMessage(comment.Email, mailInfo.Mail2,
                                                      comment.Name + " web sitende " + header + " başlıklı yazına yorum yaptı."
                                                      , comment.Email + " adresinden gelen yorum:<br/>" + comment.CommentText);
                message.IsBodyHtml = true;

                emailClient.Send(message);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 8
0
        public ActionResult <Result> Delete([FromBody] TComment comment)
        {
            //获取用户信息
            string user_id = Token.GetUserId(HttpContext.Request.Headers["Authorization"].ToString().Substring(7));
            TUser  user    = userServer.Retrieve(new TUser()
            {
                UserId = user_id
            });

            TComment com = commentServer.Retrieve(new TComment()
            {
                CommentId = comment.CommentId
            });

            if (com.UserId != user.UserId)
            {
                throw new ResultException("不能修改他人的评论");
            }

            commentServer.Update(comment);
            return(new Result(200, "成功"));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 根据ID获取数据
 /// </summary>
 /// <param name="t">HuobiProject.Models</param>
 /// <returns>
 /// Success:T
 /// Failed:NULL
 /// </returns>
 TComment ICURD <TComment> .Retrieve(TComment t)
 {
     return(m_db.TComment.Find(t.CommentId));
 }
Ejemplo n.º 10
0
 public virtual void CaseTComment(TComment node)
 {
     DefaultCase(node);
 }