Exemplo n.º 1
0
        public BlogPost UpdateBlogPost(BlogPost post)
        {
            using (BlogContext context = new BlogContext())
            {
                context.Entry(post).State = EntityState.Modified;
                context.SaveChanges();
            }

            return post;
        }
Exemplo n.º 2
0
        public BlogPost CreateBlogPost(BlogPost post)
        {
            using (BlogContext context = new BlogContext())
            {
                context.BlogPosts.Add(post);
                context.SaveChanges();
            }

            return post;
        }
Exemplo n.º 3
0
 public void DeleteBlogPost(string id)
 {
     int identifier;
     if (int.TryParse(id, out identifier))
     {
         using (BlogContext context = new BlogContext())
         {
             var entity = context.BlogPosts.FirstOrDefault(blogPost => blogPost.Id == identifier);
             if (entity != null)
             {
                 context.BlogPosts.Remove(entity);
                 context.SaveChanges();
             }
         }
     }
 }