Exemplo n.º 1
0
        public async Task PostPosts(List <Post> posts, DateTime tsStamp, string usStamp, string asStamp)
        {
            posts.ForEach(post =>
            {
                post.SetBaseData(tsStamp, usStamp, asStamp);
                _context.Entry(post).State = EntityState.Added;
            });

            await _context.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutBlog(int id, Blog blog)
        {
            if (id != blog.BlogId)
            {
                return(BadRequest());
            }

            DateTime tsStamp = DateTime.Now;
            string   usStamp = "testUser";
            string   asStamp = "testApp";

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

            try
            {
                _context.Entry(blog).State = EntityState.Modified;
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_logic.BlogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutBlog(int id, Blog blog)
        {
            if (id != blog.BlogId)
            {
                return(BadRequest());
            }

            _context.Entry(blog).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BlogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 4
0
        public async Task UpdateData(List <CompanyChild> companyChildren, DateTime tsStamp, string usStamp, string asStamp)
        {
            companyChildren.ForEach(a =>
            {
                a.SetBaseData(tsStamp, usStamp, asStamp);
                _context.Entry(a).State = EntityState.Modified;
            });

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
Exemplo n.º 5
0
        public async Task PutBlog(Blog blog, DateTime tsStamp, string usStamp, string asStamp)
        {
            PostLogic postLogic = new PostLogic(_context);

            blog.SetBaseData(tsStamp, usStamp, asStamp);
            _context.Entry(blog).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                await postLogic.PutPosts(blog.Posts, tsStamp, usStamp, asStamp);
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        public async Task Update(Company company, DateTime tsStamp, string usStamp, string asStamp)
        {
            company.SetBaseData(tsStamp, usStamp, asStamp);
            _context.Entry(company).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                CompanyChildLogic companyChildLogic = new CompanyChildLogic(_context);
                await companyChildLogic.Update(company.CompanyParentChilds, tsStamp, usStamp, asStamp);

                await companyChildLogic.Update(company.CompanyChildChilds, tsStamp, usStamp, asStamp);
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
Exemplo n.º 7
0
        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();
            }
        }