Esempio n. 1
0
 public IEnumerable<Post> Get()
 {
     var db = new BlogContext();
     var posts = from p in db.Posts.Include(c => c.Category)
                 select p;
     return posts;
 }
Esempio n. 2
0
        public IEnumerable<Post> Get([FromUri]int id)
        {
            var db = new BlogContext();
            var posts = from p in db.Posts.Include(c => c.Category)
                        where p.Category.Id == id
                        select p;

            return posts;
        }
Esempio n. 3
0
        public void Post([FromBody]Post post)
        {
            var db = new BlogContext();

            if (post.Category != null)
            {
                var category = (from c in db.Categories
                                where c.Name == post.Category.Name
                                select c).FirstOrDefault();

                if (category != null)
                {
                    post.Category = category;
                }
            }

            post.PostDate = DateTime.Now;

            db.Posts.Add(post);
            db.SaveChanges();
        }
 public void Post([FromBody]Category category)
 {
     var db = new BlogContext();
     db.Categories.Add(category);
     db.SaveChanges();
 }
 public IEnumerable<Category> Get()
 {
     var db = new BlogContext();
     return db.Categories.ToList();
 }