Ejemplo n.º 1
0
        private static void ListAll(BlogLogic logic)
        {
            Console.WriteLine("\n:: ALL BLOGS ::\n");
            logic.GetAllBlogs()
            .ToList()
            .ForEach(x => Console.WriteLine(x.MainData));

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        private static void GetById(BlogLogic logic)
        {
            Console.Write("ENTERT ID HERE: ");
            int id = int.Parse(Console.ReadLine());

            var q = logic.GetBlogById(id);

            Console.WriteLine("\n:: SELECTED BLOG ::\n");
            Console.WriteLine(q); // tostring

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        public async Task DeleteBlog_deletes_blog()
        {
            IBlogLogic logic         = new BlogLogic(_context);
            var        existingBlogs = await logic.GetAsync();

            var existingBlog = existingBlogs.FirstOrDefault(b => b.Title == "Title2");

            var result = await logic.DeleteAsync(existingBlog.Id);

            result.Should().BeTrue();
            (await logic.GetAsync()).Any(b => b.Id == existingBlog.Id).Should().BeFalse();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            BlogContext    ctx   = new BlogContext();
            BlogRepository repo  = new BlogRepository(ctx);
            BlogLogic      logic = new BlogLogic(repo);

            var menu = new ConsoleMenu()
                       .Add(">> LIST ALL", () => ListAll(logic))
                       .Add(">> GET BY ID", () => GetById(logic))
                       .Add(">> CHANGE TITLE", () => ChangeTitle(logic))
                       .Add(">> EXIT", ConsoleMenu.Close);

            menu.Show();
        }
Ejemplo n.º 5
0
        public async Task UpdateBlog_updates_blog()
        {
            IBlogLogic logic         = new BlogLogic(_context);
            var        existingBlogs = await logic.GetAsync();

            var existingBlog = existingBlogs.FirstOrDefault(b => b.Title == "Title1");

            existingBlog.Title = "UpdatedTitle1";

            var result = await logic.UpdateAsync(existingBlog.Id, existingBlog);

            result.Should().BeTrue();
            (await logic.GetAsync()).FirstOrDefault(b => b.Id == existingBlog.Id).Title.Should().Be("UpdatedTitle1");
        }
Ejemplo n.º 6
0
        public async Task CreateBlog_creates_blog()
        {
            IBlogLogic logic = new BlogLogic(_context);

            var blog = new Blog
            {
                Title   = "CreateBlogTestTitle",
                Content = "CreateBlogTestContent"
            };

            var result = await logic.CreateAsync(blog);

            result.Id.Should().NotBeNullOrEmpty();
        }
Ejemplo n.º 7
0
        private static void ChangeTitle(BlogLogic logic)
        {
            Console.Write("ENTER ID HERE: ");
            int id = int.Parse(Console.ReadLine());

            Console.Write("ENTER NEW TITLE HERE: ");
            string newTitle = Console.ReadLine();

            logic.ChangeBlogTitle(id, newTitle);

            var q = logic.GetBlogById(id);

            Console.WriteLine("\n:: NEW TITLE ::\n");
            Console.WriteLine(q.Title);

            Console.ReadLine();
        }
Ejemplo n.º 8
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();
            }
        }
Ejemplo n.º 9
0
        private static void Main(string[] args)
        {
            using (var db = new BloggingContext())
            {
                BlogLogic newBlog = new BlogLogic();
                //newBlog.createAndSaveBlock();
                //displaying all the blogs
                //newBlog.DisplayBlogs();

                OrganizationLogic newOrg = new OrganizationLogic();
                //newOrg.NewUserForOrg();
                //newOrg.PrintOrganizations();
                //newOrg.PrintOrganizaionsAndTheirUsers();
                //newOrg.MakeOrganization();

                CountryLogic newCountryLogic = new CountryLogic();
                //newCountryLogic.PrintCountriesAndOrgs();

                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
            }
        }
Ejemplo n.º 10
0
 public Api1Controller(Api1Context context)
 {
     _context = context;
     _logic   = new BlogLogic(context);
 }