Пример #1
0
 private dynamic PostComment(dynamic parametrs)
 {
     try
     {
         var db      = new MainContext();
         var user    = GetLoggedUser(db);
         var placeId = (int?)parametrs.id;
         if (placeId == null)
         {
             return(Response.AsJson("Wrong place id.", HttpStatusCode.BadRequest));
         }
         var body = this.Bind <CommentBody>();
         if (string.IsNullOrEmpty(body.Message))
         {
             return(Response.AsJson("Body not complete", HttpStatusCode.BadRequest));
         }
         ModelComment comment = ServicePlace.AddComment(placeId, user, body.Message, db);
         return(Response.AsJson(comment.GetView()));
     }
     catch (NooneLoggedInException)
     {
         return(Response.AsJson("Noone logged in.", HttpStatusCode.Unauthorized));
     }
     catch (LoggedUserDoesNotExists)
     {
         return(Response.AsJson("Logged user with bad userName", HttpStatusCode.InternalServerError));
     }
     catch (PlaceDoesNotExistsException)
     {
         return(Response.AsJson("Place don't exists", HttpStatusCode.BadRequest));
     }
 }
Пример #2
0
 /// <summary>
 /// Добавление комментария
 /// </summary>
 /// <param name="ContentComment">Содержимое комментария</param>
 /// <param name="UserId">ИД пользователя.</param>
 /// <param name="PostId">Ид поста</param>
 public void AddComent(ModelComment model, int UserId, int PostId, int?PareantId)
 {
     using (var db = new DataContext())
     {
         if (PareantId == null)
         {
             var user    = db.Users.FirstOrDefault(x => x.Id == UserId);
             var post    = db.Posts.FirstOrDefault(x => x.PostID == PostId);
             var comment = db.Comments.Add(ConvertComment(model));
             comment.DateAddComment = DateTime.Now;
             comment.Post.Add(post);
             comment.User.Add(user);
             comment.Answer = true;
             db.SaveChanges();
         }
         else
         {
             var user    = db.Users.FirstOrDefault(x => x.Id == UserId);
             var post    = db.Posts.FirstOrDefault(x => x.PostID == PostId);
             var Pareant = db.Comments.FirstOrDefault(x => x.Id == PareantId);
             Pareant.Answer = false;
             var comment = db.Comments.Add(ConvertComment(model));
             comment.Child.Where(_ => _.PareantId == PareantId);
             comment.PareantId      = PareantId;
             comment.DateAddComment = DateTime.Now;
             comment.Post.Add(post);
             comment.User.Add(user);
             db.SaveChanges();
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Get comments for a specific model
        /// </summary>
        /// <param name="context">Live DbContext</param>
        /// <param name="modelName">Model name to get comments for</param>
        /// <returns>IEnumerable&lt;ModelComment&gt;</returns>
        /// <remarks>
        /// context.Comments("Customers");
        /// </remarks>
        public static IEnumerable <ModelComment> Comments(this DbContext context, string modelName)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var entityType = GetEntityType(context, modelName);

            var commentList = new List <ModelComment>();

            IEnumerable <IProperty> properties = context.Model.FindEntityType(entityType ??
                                                                              throw new InvalidOperationException()).GetProperties();

            foreach (IProperty itemProperty in properties)
            {
                var modelComment = new ModelComment
                {
                    Name    = itemProperty.Name,
                    Comment = context.Model.FindEntityType(entityType).FindProperty(itemProperty.Name).GetComment() ?? itemProperty.Name
                };


                commentList.Add(modelComment);
            }

            return(commentList);
        }
Пример #4
0
        protected void commentDeleteClick(object sender, RoutedEventArgs e)
        {
            MenuItem     delete = sender as MenuItem;
            ModelComment items  = delete.DataContext as ModelComment;

            Comment.Delete(items.id);
            listLoader();
        }
Пример #5
0
        protected void commentDeleteClick(object sender, RoutedEventArgs e)
        {
            MenuItem     menuItem = sender as MenuItem;
            ModelComment items    = menuItem.DataContext as ModelComment;

            Comment.Delete(items.id);
            megjegyzes_listBox.ItemsSource = Utility.Data_CommentProject();
        }
        protected void commentDeleteClick(object sender, RoutedEventArgs e)
        {
            MenuItem     item  = sender as MenuItem;
            ModelComment items = item.DataContext as ModelComment;

            Comment.Delete(items.id);
            commentLoader(megjegyzes_listBox);
        }
Пример #7
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int delete(ModelComment model)
        {
            string sql = "delete from Comment where commentid =@commentid ";

            SqlParameter[] sqlpar = new SqlParameter[]
            {
                new SqlParameter("@commentid ", model.commentid)
            };
            return(DBhelp.Notquery(sql, sqlpar));
        }
Пример #8
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int insert(ModelComment model)
        {
            string sql = "insert into Comment values(@commentcontent ,@commenttime ,@Sproductid )";

            SqlParameter[] sqlpar = new SqlParameter[]
            {
                new SqlParameter("@commentcontent", model.commentcontent),
                new SqlParameter("@commenttime", model.commenttime),
                new SqlParameter("@Sproductid", model.Sproductid)
            };
            return(DBhelp.Notquery(sql, sqlpar));
        }
Пример #9
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int update(ModelComment model)
        {
            string sql = "update Comment set commentcontent =@commentcontent ,commenttime =@commenttime ,Sproductid =@Sproductid  where commentid =@commentid ";

            SqlParameter[] sqlpar = new SqlParameter[]
            {
                new SqlParameter("@commentcontent", model.commentcontent),
                new SqlParameter("@commenttime", model.commenttime),
                new SqlParameter("@Sproductid", model.Sproductid),
                new SqlParameter("@commentid", model.commentid)
            };
            return(DBhelp.Notquery(sql, sqlpar));
        }
Пример #10
0
 private static Comment ConvertComment(ModelComment comment)
 {
     return(new Comment
     {
         ContetntComment = comment.ContentComment,
         Answer = comment.Answer,
         DateAddComment = comment.DateAddPost,
         Child = new List <Comment> {
         },
         Post = new List <Post> {
         },
         User = new List <User> {
         }
     });
 }
Пример #11
0
        public static ModelComment AddComment(int?placeId, ModelUser user, string message, MainContext db)
        {
            var place = GetPlaceById(placeId, db);

            if (place == null)
            {
                throw new PlaceDoesNotExistsException();
            }
            ModelComment comment = new ModelComment {
                Author = user, CommentMessage = message, Place = place
            };

            db.Comments.Add(comment);
            place.Comments.Add(comment);
            db.SaveChanges();
            return(comment);
        }
Пример #12
0
        public async Task <bool> Add(ModelComment modelComment)
        {
            int x = 0;

            try
            {
                using var db = new AppDBContext();
                db.Add(modelComment);
                x = await db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                Log.Error(ex, "ModelCommentManager::Add");
                throw;
            }

            return(x > 0);
        }
Пример #13
0
    {/// <summary>
     /// 查询买家评论表
     /// </summary>
     /// <returns></returns>
        public static List <ModelComment> select()
        {
            string              sql  = "select * from Comment";
            SqlDataReader       sdr  = DBhelp.slelect(sql);
            List <ModelComment> list = new List <ModelComment>();

            if (sdr.HasRows)
            {
                while (sdr.Read())
                {
                    ModelComment model = new ModelComment();
                    model.commentid      = Convert.ToInt32(sdr["commentid"]);
                    model.commentcontent = sdr["commentcontent"].ToString();
                    model.commenttime    = sdr["commenttime"].ToString();/*Convert.ToDateTime(sdr[""]).ToString("yyyy-MM-dd");*/
                    model.Sproductid     = Convert.ToInt32(sdr["Sproductid"]);
                    list.Add(model);
                }
            }
            return(list);
        }
Пример #14
0
        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            //获取前台的comm方法名
            string name = e.CommandName;
            //存储model值
            ModelComment model = new ModelComment()
            {
                commentid = Convert.ToInt32(e.CommandArgument)
            };

            //判断方法名来进行相对的操作
            if (name == "delete")
            {
                //执行删除(软删除,将值隐藏)
                int num = BllComment.delete(model);
                if (num > 0)
                {
                    Response.Write("<script>alert('删除成功');location.href='Comment.aspx'</script>");
                }
            }
        }
Пример #15
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text == "")
            {
                Response.Write("<script>alert('请评价')</script>");
            }
            //if (TextBox2.Text=="")
            //{
            //    Response.Write("<script>alert('请输入卖家商品id')</script>");
            //}
            //var qq = Session["Product"] as ModelSproduct;
            ModelComment ins = new ModelComment()
            {
                commentcontent = TextBox1.Text,
                commenttime    = TextBox2.Text
                                 //Sproductid=Convert.ToInt32(TextBox2.Text)
            };

            if (BllComment.insert(ins) > 0)
            {
                Response.Write("<script>alert('添加成功');location.href='Comment.aspx'</script>");
            }
        }
Пример #16
0
 public ActionResult AddComment(ModelComment comment, int UserId, int PostId, int?PareantId)
 {
     Services.Post.AddComent(comment, UserId, PostId, PareantId);
     return(Json("Запрос прошел успешно"));
 }
Пример #17
0
        public List <ModelComment> Data_CommentApplicant()
        {
            string command = "SELECT id, jelolt_id, projekt_id, hr_id, hr_nev, megjegyzes, datum FROM megjegyzesek WHERE jelolt_id=" + Session.ApplicantID;

            return(ModelComment.GetModelComment(command));
        }
Пример #18
0
 public static int delete(ModelComment model)
 {
     return(DalComment.delete(model));
 }
Пример #19
0
 public static int insert(ModelComment model)
 {
     return(DalComment.insert(model));
 }
Пример #20
0
 public static int update(ModelComment model)
 {
     return(DalComment.update(model));
 }
Пример #21
0
 public AdmCommentController()
 {
     _modelComment = new ModelComment();
 }