Exemplo n.º 1
0
        public Datacontract.BlogResponse SelectBlog(Datacontract.BlogRequest request)
        {
            if (request.Select.BlogId == null)
            {
                throw new Exception("BlogId must be defined");
            }
            Datacontract.BlogResponse response = new Datacontract.BlogResponse();

            using (MyBlogEntities blog = new MyBlogEntities(GetConnectionStringEF()))
            {

                response.SingleBlog = blog.Blogs.Where(e => e.BlogID == request.Select.BlogId).Select(e => new Datacontract.Blog() { Title = e.Title, Description = e.Description }).First();
            }
            return response;
        }
Exemplo n.º 2
0
        public Datacontract.BlogResponse SelectBlogs(Datacontract.BlogRequest request)
        {
            Datacontract.BlogResponse response = new Datacontract.BlogResponse();
            if (request.SelectBlogs.BlogId == null && request.SelectBlogs.BlogId.Count() <= 0)
            {
                throw new Exception("Blog ids required to get blogs from SelectBlogs");
            }

            using (MyBlogEntities blog = new MyBlogEntities(GetConnectionStringEF()))
            {
                response.BlogList = blog.Blogs.Where(e => request.SelectBlogs.BlogId.Contains(e.BlogID)).Select(e => new Datacontract.Blog() { Title = e.Title, Description = e.Description }).ToList();
            }
            return response;
        }