Ejemplo n.º 1
0
        protected void btnPost_Click(object sender, EventArgs e)
        {
            try
            {
                var newPost = new BLL.Post();
                newPost.Content  = activity.Text;
                newPost.DateTime = DateTime.Now;
                newPost.UserId   = currentUser.Id;
                newPost.CircleId = DropDownList1.SelectedValue;
                newPost.Image    = GeneralHelpers.UploadFile(FileUpload1);
                PostDAO.AddPost(newPost);

                rptUserPosts.DataSource = PostDAO.GetPostsByCircle("gym");
                rptUserPosts.DataBind();

                UserCircleDAO.ChangeUserCirclePoints(
                    userId: currentUser.Id,
                    circleName: newPost.CircleId,
                    points: 30,
                    source: "creating a new post",
                    addNotification: true
                    );
            }
            catch (DbEntityValidationException ex)
            {
                var err = ex.EntityValidationErrors.FirstOrDefault().ValidationErrors.FirstOrDefault().ErrorMessage;
            }
        }
Ejemplo n.º 2
0
        private static BLL.Post comment(BLL.Blog onblog, string content, BLL.User author)
        {
            BLL.Post post = new BLL.Post
            {
                Blog    = onblog,
                BlogId  = onblog.Id,
                Content = content,
                Author  = author
            };
            //onblog.Publish();
            ////面向数据库:
            //new PostRepository(Helper.context).Save(post);

            //面向对象写法:
            onblog.Posts = onblog.Posts ?? new List <BLL.Post>();
            onblog.Posts.Add(post);
            new BlogRepository(Helper.context).Flush();

            return(post);
        }
Ejemplo n.º 3
0
        protected void Comment_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (RepeaterItem item in rptUserPosts.Items)
                {
                    TextBox comment = (TextBox)item.FindControl("hello");
                    var     newPost = new BLL.Post();
                    newPost.Comment  = comment.Text;
                    newPost.UserId   = currentUser.Id;
                    newPost.CircleId = "gym";
                    PostDAO.AddPost(newPost);

                    rptUserPosts.DataSource = PostDAO.GetPostsByCircle("gym");
                    rptUserPosts.DataBind();
                }

                refreshGv();
            }
            catch (DbEntityValidationException ex)
            {
                var err = ex.EntityValidationErrors.FirstOrDefault().ValidationErrors.FirstOrDefault().ErrorMessage;
            }
        }