コード例 #1
0
        /// <summary>
        /// 创建评论
        /// </summary>
        /// <param name="content">评论内容</param>
        /// <param name="movie">评论的电影id</param>
        /// <param name="user">用户id</param>
        /// <returns>评论id</returns>
        public static string Create(string content, string movie, string user)
        {
            //using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext())
            using (MRDataEntities _db = new MRDataEntities())
            {
                tbl_Comment cmt = new tbl_Comment()
                {
                    cmt_Content = content,
                    cmt_User    = user,
                    cmt_Movie   = movie
                };

                string guid;
                do
                {
                    guid = Guid.NewGuid().ToString("N").ToUpper();
                } while (_db.tbl_Comment.Where(p => p.cmt_Id == guid).Count() != 0);
                cmt.cmt_Id = guid;

                //_db.tbl_Comment.InsertOnSubmit(cmt);
                //_db.SubmitChanges();
                //_db.SetCmtTime(guid);
                _db.tbl_Comment.Add(cmt);
                _db.SaveChanges();

                return(cmt.cmt_Id);
            }
        }
コード例 #2
0
        public bool LeaveComment(tbl_Comment comment)
        {
            DealDoubleDBContext context = new DealDoubleDBContext();

            context.tbl_Comment.Add(comment);

            return(context.SaveChanges() > 0);
        }
コード例 #3
0
 public CommentViewModel(tbl_Comment cmt)
 {
     Id          = cmt.cmt_Id;
     Content     = cmt.cmt_Content;
     UserId      = cmt.cmt_User;
     UserAccount = AccountManager.GetAccount(cmt.cmt_User);
     UserAvatar  = AccountManager.GetAvatar(cmt.cmt_User);
     Movie       = cmt.cmt_Movie;
     Time        = ((DateTime)cmt.cmt_Time).Date.ToShortDateString();
 }
        public JsonResult LeaveComment(CommentViewModel model)
        {
            JsonResult result = new JsonResult();

            var comment = new tbl_Comment();

            comment.Text = model.Text;

            comment.Rating = model.Rating;

            comment.EntityID = model.EntityID;

            comment.RecordID = model.RecordID;

            comment.UserID = User.Identity.GetUserId();

            comment.TimpStamp = DateTime.Now;

            var res = services.LeaveComment(comment);


            result.Data = new { Success = res };



            //try
            //{
            //    var comment = new tbl_Comment();

            //    comment.Text = model.Text;

            //    comment.EntityID = model.EntityID;

            //    comment.RecordID = model.RecordID;

            //    comment.UserID = User.Identity.GetUserId();

            //    comment.TimpStamp = DateTime.Now;

            //    var res = services.LeaveComment(comment);


            //    result.Data = new { Success = res };

            //}
            //catch (Exception ex)
            //{

            //    result.Data = new { Success = false, Massage = ex.Message };
            //}

            return(result);
        }