Example #1
0
        public Datacontract.PostResponse SelectPosts(Datacontract.PostRequest request)
        {
            bool result = false;
            Datacontract.PostResponse response = new Datacontract.PostResponse();

            if (request.SelectPost.PostID == null && request.DeletePost.PostID.HasValue)
                throw new Exception("Post Id cannot be null");

            using (MyBlogEntities blog = new MyBlogEntities(GetConnectionStringEF()))
            {
                try
                {
                    List<int> cPost = request.SelectPosts.PostIds;

                    response.Posts = blog.BlogPosts.Where(e => cPost.Contains(e.BlogID)).Select(e => new Datacontract.Post() { BlogID = e.BlogID, Name = e.Name, Email = e.Email, PostDetail = e.Post }).ToList();
                    
                    result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return new Datacontract.PostResponse() { Result = result ? Datacontract.DBResult.Success : Datacontract.DBResult.Fail, Posts = response.Posts };
        }
Example #2
0
        public Datacontract.PostResponse SelectPost(Datacontract.PostRequest request)
        {
            bool result = false;
            Datacontract.PostResponse response = new Datacontract.PostResponse();

            if (request.DeletePost.PostID == null && request.DeletePost.PostID.HasValue)
                throw new Exception("Post Id cannot be null");

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

                    Datacontract.IPost cPost = request.DeletePost;

                    BlogPost post = blog.BlogPosts.Where(e => e.BlogID == cPost.PostID).Select(e => e).FirstOrDefault();
                    response.Post = new Datacontract.Post() { BlogID = post.BlogID, PostDetail = post.Post, Name = post.Name, Email = post.Email };

                    result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return new Datacontract.PostResponse() { Result = result ? Datacontract.DBResult.Success : Datacontract.DBResult.Fail, Post = response.Post };
        }