コード例 #1
0
        public async Task <ActionResult <Blog> > PostBlog(Blog blog)
        {
            DateTime tsStamp = DateTime.Now;
            string   usStamp = "testUser";
            string   asStamp = "testApp";

            await _logic.CreateData(blog, tsStamp, usStamp, asStamp);

            return(CreatedAtAction(nameof(GetBlog), new { id = blog.BlogId }, blog));
        }
コード例 #2
0
ファイル: BlogLogicTest.cs プロジェクト: dkatou/WebApiSample2
        public async void ReadDataTest()
        {
            using (var context = new Api1Context(_options))
            {
                var logic = new BlogLogic(context);
                context.Database.EnsureCreated();

                Blog tdBlog = new Blog();
                tdBlog.BlogId = 0;
                tdBlog.Url    = "https://test.test";

                Post tdPost = new Post();
                tdPost.PostId = 0;
                tdPost.Title  = "post0";
                tdPost.BlogId = 0;

                tdBlog.Posts = new List <Post>();
                tdBlog.Posts.Add(tdPost);


                await logic.CreateData(tdBlog, DateTime.Now, "test", "test");

                JoinA tdJoinA = new JoinA();
                tdJoinA.BlogId  = 1;
                tdJoinA.JoinAId = 2;

                context.Entry(tdJoinA).State = EntityState.Added;
                await context.SaveChangesAsync();

                List <BlogJoinA> blogs = await logic.ReadDatas();

                Console.WriteLine(blogs.Count);
                Console.WriteLine(blogs[0].Blog.BlogId);
                Console.WriteLine(blogs[0].JoinA.JoinAId);

                Assert.True(1 == 1);
            }

            using (var context = new Api1Context(_options))
            {
                IQueryable <Blog> blog = context.Blog.Where(b => b.BlogId == 1);


                var sql = blog.ToSqll();
            }
        }