예제 #1
0
        public void EditThread(IndexThreadDTO thread)
        {
            using (var ctx = new WebForumContext())
            {
                var threadToEdit = ctx.Threads.Find(thread.Id);

                if (threadToEdit != null)
                {
                    threadToEdit.Title            = thread.Title;
                    ctx.Entry(threadToEdit).State = EntityState.Modified;
                }
                ctx.SaveChanges();
            }
        }
예제 #2
0
        public void EditPost(PostDTO post)
        {
            using (var ctx = new WebForumContext())
            {
                var postToEdit = ctx.Posts.Find(post.Id);
                if (postToEdit != null)
                {
                    postToEdit.Text = post.Text;

                    ctx.Entry(postToEdit).State = EntityState.Modified;
                }
                ctx.SaveChanges();
            }
        }
예제 #3
0
        public ActionResult Edit([Bind(Include = "Id,Title,Description,CreationDate,Creator")] Topic topic)
        {
            var user = User.Identity.Name;

            if (!string.IsNullOrEmpty(user) && User.Identity.IsAuthenticated && topic.Creator == user)
            {
                if (ModelState.IsValid)
                {
                    db.Entry(topic).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View(topic));
            }
            return(RedirectToAction("LogIn", "Account", null));
        }
예제 #4
0
        public int UpdatePostLikes(Guid postId)
        {
            var likesAmount = 0;

            using (var ctx = new WebForumContext())
            {
                var post = ctx.Posts.Find(postId);
                if (post != null)
                {
                    post.Likes           += 1;
                    likesAmount           = post.Likes;
                    ctx.Entry(post).State = EntityState.Modified;
                }

                ctx.SaveChanges();
            }
            return(likesAmount);
        }
예제 #5
0
        public int UpdateLikes(Guid threadId)
        {
            var likesAmount = 0;

            using (var ctx = new WebForumContext())
            {
                var thread = ctx.Threads.Find(threadId);
                if (thread != null)
                {
                    thread.Likes           += 1;
                    likesAmount             = thread.Likes;
                    ctx.Entry(thread).State = EntityState.Modified;
                }

                ctx.SaveChanges();
            }
            return(likesAmount);
        }