Exemplo n.º 1
0
 public override string ToString()
 {
     return($"{{Id: {Id};\n" +
            $"Title: {Title};\n" +
            $"Posts Count: {Posts.Count()};\n" +
            $"ViewCounter: {ViewCounter}}}");
 }
Exemplo n.º 2
0
        public override string ToString()
        {
            string result = $"Id:{Id} Created:{CreatedAt.ToShortDateString()}\nName:{Name}\nEmail:{Email}\nAddress:{MyAddress}\n";

            if (Todos != null && Todos.Count() > 0)
            {
                result += "\tToDos list:\n";
                foreach (var item in Todos)
                {
                    result += item.ToString();
                }
                result += "\n";
            }
            if (Posts != null && Posts.Count() > 0)
            {
                result += "\tPosts list:\n";
                foreach (var item in Posts)
                {
                    result += item.ToString();
                }
                result += "\n";
            }
            if (Comments != null && Comments.Count() > 0)
            {
                result += "\tComments list:\n";
                foreach (var item in Comments)
                {
                    result += item.ToString();
                }
                result += "\n";
            }
            return(result);
        }
Exemplo n.º 3
0
        public PostContext(DbContextOptions <PostContext> options) : base(options)
        {
            Database.EnsureCreated();

            if (Posts.Count() == 0)
            {
                Posts.AddRange(
                    new Post()
                {
                    Id    = 1,
                    Title = "Davids nya kärra",
                    Url   = "https://st.mascus.com/imagetilewm/product/5a5a5da2/other-karra-10,0734675c.jpg"
                },
                    new Post()
                {
                    Id    = 2,
                    Title = "Willes otroliga bantningstips",
                    Url   = "https://i.imgur.com/QeWNgWT.jpg"
                },
                    new Post()
                {
                    Id    = 3,
                    Title = "Gratis pengar: Se knepet bankerna inte vill att du ska veta om!",
                    Url   = "https://www.forsakringskassan.se/"
                }
                    );
                SaveChanges();
            }
        }
Exemplo n.º 4
0
        object publish_list(string key, string category)
        {
            var site = (Site)jc["site"];

            WebQuery q = new WebQuery();

            q.Id = "posts.publish_list";
            q.LoadCondidtion();

            if (!string.IsNullOrEmpty(key))
            {
                q["key"] = key;
            }
            if (!string.IsNullOrEmpty(category))
            {
                q["category"] = category;
            }

            q.TotalCount = Posts.Count(q);
            if (q.PageIndex1 > q.PageCount)
            {
                q.PageIndex = Math.Max(q.PageCount - 1, 0);
            }

            q["siteId"] = site.Id;

            var dt   = Posts.GetDataTable(q);
            var data = new ArrayList();

            foreach (DataRow item in dt.Rows)
            {
                data.Add(new
                {
                    id             = item["id"].ToString(),
                    site_id        = site.Id,
                    title          = item["title"].ToString(),
                    category       = item["category"] is DBNull ? string.Empty : item["category"].ToString(),
                    date_created   = item["dateCreated"].ToDateTime(),
                    view_count     = item["viewCount"].ToInt(),
                    sort_order     = item["sortOrder"].ToInt(),
                    date_published = item["datePublished"].ToDateTime()
                });
            }

            return(new
            {
                code = 1,
                data = data,
                paging = new
                {
                    total_count = q.TotalCount,
                    page_size = q.PageSize,
                    page_index = q.PageIndex1
                },
                orderbys = q.orderbys
            });
        }
Exemplo n.º 5
0
        object trash(string key)
        {
            var site = (Site)jc["site"];

            WebQuery q = new WebQuery();

            q.Id = "trash.list";
            q.LoadCondidtion();

            if (!string.IsNullOrEmpty(key))
            {
                q["key"] = key;
            }

            q["siteId"] = site.Id;
            q["userId"] = jc.UserName;

            q.TotalCount = Posts.Count(q);
            if (q.PageIndex1 > q.PageCount)
            {
                q.PageIndex = Math.Max(q.PageCount - 1, 0);
            }

            var dt   = Posts.GetDataTable(q);
            var data = new ArrayList();

            foreach (DataRow item in dt.Rows)
            {
                data.Add(new
                {
                    id             = item["id"].ToString(),
                    title          = item["title"].ToString(),
                    category       = item["category"] is DBNull ? string.Empty : item["category"].ToString(),
                    date_created   = item["dateCreated"].ToDateTime(),
                    view_count     = item["viewCount"].ToInt(),
                    sort_order     = item["sortOrder"].ToInt(),
                    status         = StringEnum <Status> .ToString(StringEnum <Status> .SafeParse(item["status"].ToString())),
                    display_name   = item["displayName"] is DBNull ? "未知用户" : item["displayName"].ToString(),
                    date_published = item["datePublished"].ToDateTime()
                });
            }

            return(new
            {
                code = 1,
                data = data,
                paging = new
                {
                    total_count = q.TotalCount,
                    page_size = q.PageSize,
                    page_index = q.PageIndex1
                },
                orderbys = q.orderbys
            });
        }
Exemplo n.º 6
0
        public void DeletePost()
        {
            var post = new Post {
                Id = 1, UserId = 1
            };

            Posts.Add(post);
            var result = Repository.Object.DeletePost(1, 1);

            Assert.IsTrue(result);
            Assert.AreEqual(0, Posts.Count());
        }
        public void Populate()
        {
            if (Authors.Count() > 0 || Posts.Count() > 0 || SocialNetworkProfiles.Count() > 0)
            {
                return;
            }

            string jsonData = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/initial-data.json");
            var    authors  = JsonConvert.DeserializeObject <List <Author> >(jsonData);

            Authors.AddRange(authors);

            this.SaveChanges();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            logger.Info("Program started");

            try
            {
                string choice;
                do
                {
                    Console.WriteLine("Choose an option:");
                    Console.WriteLine("1) Display all blogs");
                    Console.WriteLine("2) Add Blog");
                    Console.WriteLine("3) Create Post");
                    Console.WriteLine("4) Display Posts");
                    Console.WriteLine("Enter q to quit");
                    choice = Console.ReadLine();
                    Console.Clear();

                    if (choice == "1")
                    {
                        // display blogs
                        var db    = new BloggingContext();
                        var query = db.Blogs.OrderBy(b => b.Name);

                        Console.WriteLine($"{query.Count()} Blogs returned");
                        foreach (var item in query)
                        {
                            Console.WriteLine(item.Name);
                        }
                    }
                    else if (choice == "2")
                    {
                        Console.Write("Enter a name for a new Blog: ");
                        var blog = new Blog {
                            Name = Console.ReadLine()
                        };

                        ValidationContext       context = new ValidationContext(blog, null, null);
                        List <ValidationResult> results = new List <ValidationResult>();

                        var isValid = Validator.TryValidateObject(blog, context, results, true);
                        if (isValid)
                        {
                            var db = new BloggingContext();
                            if (db.Blogs.Any(b => b.Name == blog.Name))
                            {
                                isValid = false;
                                results.Add(new ValidationResult("Blog name exists", new string[] { "Name" }));
                            }
                            else
                            {
                                logger.Info("Validation passed");
                                db.AddBlog(blog);
                                logger.Info("Blog added - {name}", blog.Name);
                            }
                        }
                        if (!isValid)
                        {
                            foreach (var result in results)
                            {
                                logger.Error($"{result.MemberNames.First()} : {result.ErrorMessage}");
                            }
                        }
                    }
                    else if (choice == "3")
                    {
                        var db    = new BloggingContext();
                        var query = db.Blogs.OrderBy(b => b.BlogId);

                        Console.WriteLine("Select the blog you would to post to:");
                        foreach (var item in query)
                        {
                            Console.WriteLine($"{item.BlogId}) {item.Name}");
                        }
                        if (int.TryParse(Console.ReadLine(), out int BlogId))
                        {
                            if (db.Blogs.Any(b => b.BlogId == BlogId))
                            {
                                Post post = CreatePost(db);
                                if (post != null)
                                {
                                    post.BlogId = BlogId;
                                    db.AddPost(post);
                                    logger.Info("Post added - {title}", post.Title);
                                }
                            }
                            else
                            {
                                logger.Error("There are no Blogs saved with that Id");
                            }
                        }
                        else
                        {
                            logger.Error("Invalid Blog Id");
                        }
                    }
                    else if (choice == "4")
                    {
                        var db    = new BloggingContext();
                        var query = db.Blogs.OrderBy(b => b.BlogId);
                        foreach (var item in query)
                        {
                            Console.WriteLine($"{item.BlogId}) Posts from {item.Name}");
                        }

                        if (int.TryParse("0", out int BlogId))
                        {
                            IEnumerable <Post> Posts;
                            if (BlogId != 0 && db.Blogs.Count(b => b.BlogId == BlogId) == 0)
                            {
                                logger.Error("No matching Blogs");
                            }
                            else
                            {
                                Posts = db.Posts.OrderBy(p => p.Title);
                                if (BlogId == 0)
                                {
                                    Posts = db.Posts.OrderBy(p => p.Title);
                                }
                                else
                                {
                                    Posts = db.Posts.Where(p => p.BlogId == BlogId).OrderBy(p => p.Title);
                                }
                                Console.WriteLine($"{Posts.Count()} post(s) returned");
                                foreach (var item in Posts)
                                {
                                    Console.WriteLine($"Blog: {item.Blog.Name}\nTitle: {item.Title}\nContent: {item.Content}\n");
                                }
                            }
                        }
                        else
                        {
                            logger.Error("Invalid Blog Id");
                        }
                    }
                    Console.WriteLine();
                } while (choice.ToLower() != "q");
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }

            logger.Info("Program ended");
        }
Exemplo n.º 9
0
        public void SeedData()
        {
            if (Members.Count() == 0 && Prices.Count() == 0 && Competitions.Count() == 0 && Threads.Count() == 0 && Posts.Count() == 0)
            {
                Console.Write("Seeding Opening Hours... ");
                CreateOpeningTime(0, 7, 19);
                CreateOpeningTime(1, 8, 20);
                CreateOpeningTime(2, 8, 20);
                CreateOpeningTime(3, 8, 20);
                CreateOpeningTime(4, 8, 21);
                CreateOpeningTime(5, 13, 22);
                CreateOpeningTime(6, 13, 22);
                Console.WriteLine("ok");
                SaveChanges();

                Console.Write("Seeding members... ");
                var admin     = CreateMember("admin", "admin", "", "", "*****@*****.**", new DateTime(1980, 01, 01), Role.Admin, "admin.jpg");
                var ben       = CreateMember("ben", "ben", "Benoit", "Penelle", "*****@*****.**", new DateTime(1980, 01, 01), Role.Professor, "ben.jpg");
                var bruno     = CreateMember("bruno", "bruno", "Bruno", "Lacroix", "*****@*****.**", new DateTime(1980, 01, 01), Role.Professor, "donald.jpg");
                var quentin   = CreateMember("quentin", "quentin", "Quentin", "Locht", "*****@*****.**", new DateTime(1995, 01, 01), Role.Climber, "Quentin.jpg");
                var gautier   = CreateMember("gautier", "gautier", "Gautier", "Kiss", "*****@*****.**", new DateTime(1996, 01, 01), Role.Climber, "Gautier.jpg");
                var guillaume = CreateMember("guillaume", "guillaume", "Guillaume", "Rigaux", "*****@*****.**", new DateTime(1997, 01, 01), Role.Climber, "Guillaume.jpg");
                Console.WriteLine("ok");
                SaveChanges();

                Console.Write("Seeding prices... ");
                // Prix pour les competitions
                Price comp8140  = CreatePrice(PassType.Competition, SubscriptionType.DailyPass, "08-14", 2);
                Price comp14180 = CreatePrice(PassType.Competition, SubscriptionType.DailyPass, "14-18", 5);
                Price comp18990 = CreatePrice(PassType.Competition, SubscriptionType.DailyPass, "18-99", 7);
                Price comp8141  = CreatePrice(PassType.Competition, SubscriptionType.WeeklyPass, "08-14", 8);
                Price comp14181 = CreatePrice(PassType.Competition, SubscriptionType.WeeklyPass, "14-18", 13);
                Price comp18991 = CreatePrice(PassType.Competition, SubscriptionType.WeeklyPass, "18-99", 15);
                Price comp8142  = CreatePrice(PassType.Competition, SubscriptionType.MonthlyPass, "08-14", 10);
                Price comp14182 = CreatePrice(PassType.Competition, SubscriptionType.MonthlyPass, "14-18", 20);
                Price comp18992 = CreatePrice(PassType.Competition, SubscriptionType.MonthlyPass, "18-99", 25);
                Price comp8143  = CreatePrice(PassType.Competition, SubscriptionType.QuarterlyPass, "08-14", 28);
                Price comp14183 = CreatePrice(PassType.Competition, SubscriptionType.QuarterlyPass, "14-18", 55);
                Price comp18993 = CreatePrice(PassType.Competition, SubscriptionType.QuarterlyPass, "18-99", 65);
                Price comp8144  = CreatePrice(PassType.Competition, SubscriptionType.YearlyPass, "08-14", 110);
                Price comp14184 = CreatePrice(PassType.Competition, SubscriptionType.YearlyPass, "14-18", 130);
                Price comp18994 = CreatePrice(PassType.Competition, SubscriptionType.YearlyPass, "18-99", 150);
                // Prix pour les abonnements des 0-10 ans
                Price sub0010Daily     = CreatePrice(PassType.Pass, SubscriptionType.DailyPass, "0-10", 7);
                Price sub0010Weekly    = CreatePrice(PassType.Pass, SubscriptionType.WeeklyPass, "0-10", 25);
                Price sub0010Monthly   = CreatePrice(PassType.Pass, SubscriptionType.MonthlyPass, "0-10", 40);
                Price sub0010Quarterly = CreatePrice(PassType.Pass, SubscriptionType.QuarterlyPass, "0-10", 100);
                Price sub0010Yearly    = CreatePrice(PassType.Pass, SubscriptionType.YearlyPass, "0-10", 250);
                // Prix pour les abonnements des 11-15 ans
                Price sub1115Daily     = CreatePrice(PassType.Pass, SubscriptionType.DailyPass, "11-15", 9);
                Price sub1115Weekly    = CreatePrice(PassType.Pass, SubscriptionType.WeeklyPass, "11-15", 30);
                Price sub1115Monthly   = CreatePrice(PassType.Pass, SubscriptionType.MonthlyPass, "11-15", 51);
                Price sub1115Quarterly = CreatePrice(PassType.Pass, SubscriptionType.QuarterlyPass, "11-15", 128);
                Price sub1115Yearly    = CreatePrice(PassType.Pass, SubscriptionType.YearlyPass, "11-15", 320);
                // Prix pour les abonnements des 16-21 ans
                Price sub1621Daily     = CreatePrice(PassType.Pass, SubscriptionType.DailyPass, "16-21", 11);
                Price sub1621Weekly    = CreatePrice(PassType.Pass, SubscriptionType.WeeklyPass, "16-21", 40);
                Price sub1621Monthly   = CreatePrice(PassType.Pass, SubscriptionType.MonthlyPass, "16-21", 63);
                Price sub1621Quarterly = CreatePrice(PassType.Pass, SubscriptionType.QuarterlyPass, "16-21", 157);
                Price sub1621Yearly    = CreatePrice(PassType.Pass, SubscriptionType.YearlyPass, "16-21", 393);
                // Prix pour les abonnements des 21-99 ans
                Price sub2199Daily     = CreatePrice(PassType.Pass, SubscriptionType.DailyPass, "21-99", 15);
                Price sub2199Weekly    = CreatePrice(PassType.Pass, SubscriptionType.WeeklyPass, "21-99", 50);
                Price sub2199Monthly   = CreatePrice(PassType.Pass, SubscriptionType.MonthlyPass, "21-99", 85);
                Price sub2199Quarterly = CreatePrice(PassType.Pass, SubscriptionType.QuarterlyPass, "21-99", 214);
                Price sub2199Yearly    = CreatePrice(PassType.Pass, SubscriptionType.YearlyPass, "21-99", 535);
                // Prix pour les cours
                Price priceCourses10120 = CreatePrice(PassType.Course, SubscriptionType.DailyPass, "10-12", 5);
                Price PriceCourses12140 = CreatePrice(PassType.Course, SubscriptionType.DailyPass, "12-14", 5);
                Price PriceCourses14160 = CreatePrice(PassType.Course, SubscriptionType.DailyPass, "14-16", 5);
                Price PriceCourses16180 = CreatePrice(PassType.Course, SubscriptionType.DailyPass, "16-18", 5);
                Price PriceCourses18200 = CreatePrice(PassType.Course, SubscriptionType.DailyPass, "18-20", 5);
                Price PriceCourses20990 = CreatePrice(PassType.Course, SubscriptionType.DailyPass, "20-99", 5);
                Price priceCourses10121 = CreatePrice(PassType.Course, SubscriptionType.WeeklyPass, "10-12", 7);
                Price PriceCourses12141 = CreatePrice(PassType.Course, SubscriptionType.WeeklyPass, "12-14", 8);
                Price PriceCourses14161 = CreatePrice(PassType.Course, SubscriptionType.WeeklyPass, "14-16", 9);
                Price PriceCourses16181 = CreatePrice(PassType.Course, SubscriptionType.WeeklyPass, "16-18", 11);
                Price PriceCourses18201 = CreatePrice(PassType.Course, SubscriptionType.WeeklyPass, "18-20", 12);
                Price PriceCourses20991 = CreatePrice(PassType.Course, SubscriptionType.WeeklyPass, "20-99", 15);
                Price priceCourses10122 = CreatePrice(PassType.Course, SubscriptionType.MonthlyPass, "10-12", 18);
                Price PriceCourses12142 = CreatePrice(PassType.Course, SubscriptionType.MonthlyPass, "12-14", 22);
                Price PriceCourses14162 = CreatePrice(PassType.Course, SubscriptionType.MonthlyPass, "14-16", 24);
                Price PriceCourses16182 = CreatePrice(PassType.Course, SubscriptionType.MonthlyPass, "16-18", 28);
                Price PriceCourses18202 = CreatePrice(PassType.Course, SubscriptionType.MonthlyPass, "18-20", 30);
                Price PriceCourses20992 = CreatePrice(PassType.Course, SubscriptionType.MonthlyPass, "20-99", 36);
                Price priceCourses10123 = CreatePrice(PassType.Course, SubscriptionType.QuarterlyPass, "10-12", 45);
                Price PriceCourses12143 = CreatePrice(PassType.Course, SubscriptionType.QuarterlyPass, "12-14", 53);
                Price PriceCourses14163 = CreatePrice(PassType.Course, SubscriptionType.QuarterlyPass, "14-16", 60);
                Price PriceCourses16183 = CreatePrice(PassType.Course, SubscriptionType.QuarterlyPass, "16-18", 68);
                Price PriceCourses18203 = CreatePrice(PassType.Course, SubscriptionType.QuarterlyPass, "18-20", 75);
                Price PriceCourses20993 = CreatePrice(PassType.Course, SubscriptionType.QuarterlyPass, "20-99", 90);
                Price priceCourses10124 = CreatePrice(PassType.Course, SubscriptionType.YearlyPass, "10-12", 150);
                Price PriceCourses12144 = CreatePrice(PassType.Course, SubscriptionType.YearlyPass, "12-14", 175);
                Price PriceCourses14164 = CreatePrice(PassType.Course, SubscriptionType.YearlyPass, "14-16", 200);
                Price PriceCourses16184 = CreatePrice(PassType.Course, SubscriptionType.YearlyPass, "16-18", 225);
                Price PriceCourses18204 = CreatePrice(PassType.Course, SubscriptionType.YearlyPass, "18-20", 250);
                Price PriceCourses20994 = CreatePrice(PassType.Course, SubscriptionType.YearlyPass, "20-99", 300);
                Console.WriteLine("ok");
                SaveChanges();

                Console.Write("Seeding competitions... ");

                var compet1 = CreateCompetition(new DateTime(2020, 02, 22, 10, 00, 00), 20, "Grimp'EPFC", CompetitionType.Swiftness, "18-99");
                compet1.DeclareWinner(guillaume);
                var compet2 = CreateCompetition(new DateTime(2020, 02, 23, 10, 00, 00), 20, "Grimp'EPFC", CompetitionType.Swiftness, "14-18");
                var compet3 = CreateCompetition(new DateTime(2020, 03, 21, 10, 00, 00), 15, "Grimp'EPFC", CompetitionType.Block, "14-18");
                var compet4 = CreateCompetition(new DateTime(2020, 03, 22, 10, 00, 00), 10, "Grimp'EPFC", CompetitionType.Difficulty, "08-14");
                var compet5 = CreateCompetition(new DateTime(2020, 04, 18, 10, 00, 00), 20, "Grimp'EPFC", CompetitionType.Swiftness, "08-14");
                var compet6 = CreateCompetition(new DateTime(2020, 04, 19, 10, 00, 00), 10, "Grimp'EPFC", CompetitionType.Difficulty, "18-99");
                var compet7 = CreateCompetition(new DateTime(2020, 05, 30, 10, 00, 00), 15, "Grimp'EPFC", CompetitionType.Block, "18-99");
                var compet8 = CreateCompetition(new DateTime(2020, 05, 31, 10, 00, 00), 15, "Grimp'EPFC", CompetitionType.Block, "08-14");
                var compet9 = CreateCompetition(new DateTime(2020, 06, 21, 10, 00, 00), 10, "Grimp'EPFC", CompetitionType.Difficulty, "14-18");
                Console.WriteLine("ok");
                SaveChanges();

                Console.Write("Seeding courses... ");
                // Cours pour les 10-12 ans
                CreateCourse(ben, 1, new DateTime(2020, 09, 02, 12, 00, 00), 15, "Grimp'EPFC", "10-12");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 03, 12, 00, 00), 15, "Grimp'EPFC", "10-12");
                CreateCourse(ben, 1, new DateTime(2020, 09, 04, 12, 00, 00), 15, "Grimp'EPFC", "10-12");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 05, 12, 00, 00), 15, "Grimp'EPFC", "10-12");
                CreateCourse(ben, 1, new DateTime(2020, 09, 06, 12, 00, 00), 15, "Grimp'EPFC", "10-12");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 07, 12, 00, 00), 15, "Grimp'EPFC", "10-12");
                // Cours pour les 12-14 ans
                CreateCourse(ben, 1, new DateTime(2020, 09, 02, 13, 00, 00), 15, "Grimp'EPFC", "12-14");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 03, 13, 00, 00), 15, "Grimp'EPFC", "12-14");
                CreateCourse(ben, 1, new DateTime(2020, 09, 04, 13, 00, 00), 15, "Grimp'EPFC", "12-14");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 05, 13, 00, 00), 15, "Grimp'EPFC", "12-14");
                CreateCourse(ben, 1, new DateTime(2020, 09, 06, 13, 00, 00), 15, "Grimp'EPFC", "12-14");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 07, 13, 00, 00), 15, "Grimp'EPFC", "12-14");
                // Cours pour les 14-16 ans
                CreateCourse(ben, 1, new DateTime(2020, 09, 02, 14, 00, 00), 15, "Grimp'EPFC", "14-16");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 03, 14, 00, 00), 15, "Grimp'EPFC", "14-16");
                CreateCourse(ben, 1, new DateTime(2020, 09, 04, 14, 00, 00), 15, "Grimp'EPFC", "14-16");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 05, 14, 00, 00), 15, "Grimp'EPFC", "14-16");
                CreateCourse(ben, 1, new DateTime(2020, 09, 06, 14, 00, 00), 15, "Grimp'EPFC", "14-16");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 07, 14, 00, 00), 15, "Grimp'EPFC", "14-16");
                // Cours pour les 16-18 ans
                CreateCourse(ben, 1, new DateTime(2020, 09, 02, 15, 00, 00), 15, "Grimp'EPFC", "16-18");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 03, 15, 00, 00), 15, "Grimp'EPFC", "16-18");
                CreateCourse(ben, 1, new DateTime(2020, 09, 04, 15, 00, 00), 15, "Grimp'EPFC", "16-18");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 05, 15, 00, 00), 15, "Grimp'EPFC", "16-18");
                CreateCourse(ben, 1, new DateTime(2020, 09, 06, 15, 00, 00), 15, "Grimp'EPFC", "16-18");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 07, 15, 00, 00), 15, "Grimp'EPFC", "16-18");
                // Cours pour les 18-20 ans
                CreateCourse(ben, 1, new DateTime(2020, 09, 02, 16, 00, 00), 15, "Grimp'EPFC", "18-20");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 03, 16, 00, 00), 15, "Grimp'EPFC", "18-20");
                CreateCourse(ben, 1, new DateTime(2020, 09, 04, 16, 00, 00), 15, "Grimp'EPFC", "18-20");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 05, 16, 00, 00), 15, "Grimp'EPFC", "18-20");
                CreateCourse(ben, 1, new DateTime(2020, 09, 06, 16, 00, 00), 15, "Grimp'EPFC", "18-20");
                CreateCourse(bruno, 1, new DateTime(2020, 09, 07, 16, 00, 00), 15, "Grimp'EPFC", "18-20");
                // Cours pour les adultes
                var course1 = CreateCourse(ben, 1, new DateTime(2020, 09, 02, 17, 00, 00), 15, "Grimp'EPFC", "20-99");
                var course2 = CreateCourse(bruno, 1, new DateTime(2020, 09, 03, 17, 00, 00), 15, "Grimp'EPFC", "20-99");
                var course3 = CreateCourse(ben, 1, new DateTime(2020, 09, 04, 17, 00, 00), 15, "Grimp'EPFC", "20-99");
                var course4 = CreateCourse(bruno, 1, new DateTime(2020, 09, 05, 17, 00, 00), 15, "Grimp'EPFC", "20-99");
                var course5 = CreateCourse(ben, 1, new DateTime(2020, 09, 06, 17, 00, 00), 15, "Grimp'EPFC", "20-99");
                var course6 = CreateCourse(bruno, 1, new DateTime(2020, 09, 07, 17, 00, 00), 15, "Grimp'EPFC", "20-99");
                Console.WriteLine("ok");
                SaveChanges();

                // Subscriptions pour des cours
                CreateSubscriptionToCourse(guillaume, new DateTime(2020, 05, 22), SubscriptionType.YearlyPass);
                CreateSubscriptionToCourse(gautier, new DateTime(2020, 05, 22), SubscriptionType.YearlyPass);
                CreateSubscriptionToCourse(quentin, new DateTime(2020, 05, 22), SubscriptionType.YearlyPass);
                SaveChanges();

                guillaume.SubToCourse(course1);
                guillaume.SubToCourse(course2);
                gautier.SubToCourse(course3);
                gautier.SubToCourse(course4);
                quentin.SubToCourse(course5);
                quentin.SubToCourse(course6);
                quentin.SubToCourse(course1);

                // Subscriptions pour des competitions
                CreateSubscriptionToCompetition(guillaume, new DateTime(2020, 05, 22), SubscriptionType.MonthlyPass);
                CreateSubscriptionToCompetition(ben, new DateTime(2020, 05, 22), SubscriptionType.MonthlyPass);
                CreateSubscriptionToCompetition(bruno, new DateTime(2020, 05, 22), SubscriptionType.MonthlyPass);
                CreateSubscriptionToCompetition(gautier, new DateTime(2020, 05, 22), SubscriptionType.MonthlyPass);
                CreateSubscriptionToCompetition(quentin, new DateTime(2020, 05, 22), SubscriptionType.MonthlyPass);
                SaveChanges();

                guillaume.SubToCompetition(compet1);
                guillaume.SubToCompetition(compet2);
                quentin.SubToCompetition(compet3);
                quentin.SubToCompetition(compet8);
                gautier.SubToCompetition(compet3);
                bruno.SubToCompetition(compet1);
                ben.SubToCompetition(compet1);

                // Subscriptions pour des pass
                CreateSubscriptionToPass(guillaume, new DateTime(2020, 05, 22), SubscriptionType.MonthlyPass);
                CreateSubscriptionToPass(quentin, new DateTime(2020, 05, 22), SubscriptionType.WeeklyPass);
                CreateSubscriptionToPass(gautier, new DateTime(2020, 05, 22), SubscriptionType.QuarterlyPass);
                CreateSubscriptionToPass(ben, new DateTime(2020, 05, 22), SubscriptionType.YearlyPass);
                SaveChanges();

                Console.Write("Seeding threads & posts... ");
                var thread1 = CreateThread(guillaume, "Hello everyone, I'm looking forward to buy some new material buy I don't really know what brands are the best. Could you help me ?",
                                           "Do you know where I could buy some material ?");
                CreatePost(ben, thread1, "Actually, Decathlon has strong material and not that expensive");
                CreatePost(quentin, thread1, "I've bought my whole material at Decathlon, and I'm not disappointed at all");
                CreatePost(gautier, thread1, "Here's a list of brands for professionnals : Beal, Black Diamond, Camp, Climbing Technology, Dreamtime, Mammut, Petzl, Wild Country.");
                CreatePost(guillaume, thread1, "Thanks everyone for your answers!");

                var thread2 = CreateThread(admin, "You can directly sub in the competition section", "Grimp'EPFC is organizing the climb rock competition of the year");
                CreatePost(gautier, thread2, "I'm already subbed hehe");
                CreatePost(guillaume, thread2, "I'M IN !!!");
                CreatePost(quentin, thread2, "Well, one more competition to win");

                var thread3 = CreateThread(ben, "Due to the new season, all subscriptions will be deleted, you can sub to the course by clicking on it directly in the courses section",
                                           "Reminder : members of the annual courses must re-sub");
                CreatePost(admin, thread3, "And a reminder : Prices have changed !!!");
                CreatePost(guillaume, thread3, "Well, prices have changed but ok...");
                CreatePost(quentin, thread3, "Wow... that's so expensive");
                CreatePost(gautier, thread3, "Come on guys, it's still affordable");

                var thread4 = CreateThread(admin, "The prices have changed, check the prices section !", "New annual pass price rating");
                CreatePost(guillaume, thread4, "WTF???????");
                CreatePost(gautier, thread4, "Ok, I'm leaving");
                CreatePost(quentin, thread4, "How can you do that?");
                CreatePost(admin, thread4, "Due to your reaction, we'll stick to the past season's rate. Sorry for that!");

                var thread5 = CreateThread(bruno, "I'm sorry, I'm sick and I have to rest a bit", "Friday's course is canceled");
                CreatePost(guillaume, thread5, "Get well soon");
                CreatePost(gautier, thread5, "It's ok, I didn't want to come");
                CreatePost(quentin, thread5, "gngng krkrkr");
                CreatePost(admin, thread5, "Get well soon Bruno!2");
                SaveChanges();
                Console.WriteLine("ok");
            }
        }
 public int PageCount()
 {
     return(Convert.ToInt32(Math.Ceiling(Posts.Count() / (double)PostsPerPage)));
 }
Exemplo n.º 11
0
        public static void Main(string[] args)
        {
            logger.Info("Program started");
            string userChoice = "";

            try
            {
                do
                {
                    Console.WriteLine("1) Display your list of Blogs");
                    Console.WriteLine("2) Make a Blog");
                    Console.WriteLine("3) Make a Post");
                    Console.WriteLine("4) Display your Posts");
                    Console.WriteLine("Press any key to quit");

                    userChoice = Console.ReadLine();
                    logger.Info("User choice: ", userChoice);


                    if (userChoice == "1")
                    {
                        // Display all Blogs from the database
                        var database = new BloggingContext();
                        var sqlQuery = database.Blogs.OrderBy(b => b.Name);

                        Console.WriteLine($"{sqlQuery.Count()} Blogs");
                        foreach (var item in sqlQuery)
                        {
                            Console.WriteLine(item.Name);
                        }
                    }

                    else if (userChoice == "2")
                    {
                        // Create and save a new Blog
                        Console.Write("Enter a name for a new Blog: ");
                        var name = Console.ReadLine();
                        if (name.Length == 0)
                        {
                            logger.Error("Please enter a name for your Blog, it can't be blank.");
                        }
                        else
                        {
                            var blog = new Blog {
                                Name = name
                            };

                            var database = new BloggingContext();
                            database.AddBlog(blog);
                            logger.Info("Blog added - {name}", name);
                        }
                    }


                    else if (userChoice == "3")
                    {
                        var database = new BloggingContext();
                        var sqlQuery = database.Blogs.OrderBy(b => b.BlogId);

                        Console.WriteLine("Which blog do you want to post to? : ");
                        foreach (var item in sqlQuery)
                        {
                            Console.WriteLine($"{item.BlogId}) {item.Name}");
                        }

                        if (int.TryParse(Console.ReadLine(), out int BlogID))
                        {
                            if (database.Blogs.Any(b => b.BlogId == BlogID))
                            {
                                Post post = new Post();
                                post.BlogId = BlogID;
                                Console.WriteLine("Name the title of your Post:");
                                post.Title = Console.ReadLine();
                                logger.Info("Post added - {postTitle}", post.Title);
                                if (post.Title.Length == 0)
                                {
                                    logger.Info("Sorry partner, your title can't be blank");
                                }
                                else
                                {
                                    Console.WriteLine("Wanna add some content to your post?");
                                    post.Content = Console.ReadLine();
                                    database.AddPost(post);
                                    logger.Info("Content added - {Content}", post.Content);
                                }
                            }
                            else
                            {
                                logger.Error("Hmmm, seems there aren't any blogs with that ID Number");
                            }
                        }
                        else
                        {
                            logger.Error("Invalid Blog ID Number");
                        }
                    }

                    else if (userChoice == "4")
                    {
                        var database = new BloggingContext();
                        var sqlQuery = database.Blogs.OrderBy(b => b.BlogId);
                        Console.WriteLine("Which Blog do you want to see posts from?");

                        foreach (var item in sqlQuery)
                        {
                            Console.WriteLine($"{item.BlogId}) {item.Name}");
                        }
                        if (int.TryParse(Console.ReadLine(), out int BlogId))
                        {
                            IEnumerable <Post> Posts;
                            if (BlogId != 0 && database.Blogs.Count(b => b.BlogId == BlogId) == 0)
                            {
                                logger.Error("Hmmm, there aren't any blogs saved with that ID Number");
                            }
                            else
                            {
                                Posts = database.Posts.OrderBy(p => p.Title);
                                if (BlogId == 0)
                                {
                                    Posts = database.Posts.OrderBy(p => p.Title);
                                }
                                else
                                {
                                    Posts = database.Posts.Where(p => p.BlogId == BlogId).OrderBy(p => p.Title);
                                }
                                Console.WriteLine($"{Posts.Count()} post/s returned");
                                foreach (var item in Posts)
                                {
                                    Console.WriteLine($"Blog: {item.Blog.Name}\nTitle: {item.Title}\nContent: {item.Content}\n");
                                }
                            }
                        }
                        else
                        {
                            logger.Error("Error! Blog ID Number nonexistent!");
                        }
                    }
                } while (userChoice == "1" || userChoice == "2" || userChoice == "3" || userChoice == "4");
                logger.Info("Program has ended");
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }
Exemplo n.º 12
0
 public bool AllowFollowUp()
 {
     return(Posts.Count(p => p.CreatedBy == CreatedBy) == 0);
 }
Exemplo n.º 13
0
        public static void Main(string[] args)
        {
            logger.Info("Program started");
            try
            {
                int choice = 0;
                do
                {
                    Console.WriteLine("1) Display all Blogs");
                    Console.WriteLine("2) Add Blog");
                    Console.WriteLine("3) Create post");

                    if (choice == 2)
                    {
                        // Create and save a new Blog
                        Console.Write("Enter a name for a new Blog: ");
                        var name = Console.ReadLine();

                        var blog = new Blog {
                            Name = name
                        };

                        var db = new BloggingContext();
                        db.AddBlog(blog);
                        logger.Info("Blog added - {name}", name);
                    }

                    else if (choice == 1)
                    {
                        var db = new BloggingContext();
                        // Display all Blogs from the database
                        var query = db.Blogs.OrderBy(b => b.Name);

                        Console.WriteLine("All blogs in the database:");
                        foreach (var item in query)
                        {
                            Console.WriteLine(item.Name);
                        }
                    }

                    else if (choice == 3)
                    {
                        var db = new BloggingContext();

                        Console.WriteLine("Create post\n");

                        var query = db.Blogs.OrderBy(b => b.Name);

                        Console.WriteLine("All blogs in the database:");
                        foreach (var item in query)
                        {
                            Console.WriteLine($"{item.BlogId} + {item.Name}");
                        }

                        if (int.TryParse(Console.ReadLine(), out int BlogId))
                        {
                            if (db.Blogs.Any(b => b.BlogId == BlogId))
                            {
                                Post post = new Post();
                                post.BlogId = BlogId;
                                Console.WriteLine("Enter the Title");
                                post.Title = Console.ReadLine();
                                if (post.Title.Length == 0)
                                {
                                    logger.Error("Titles cant be blank");
                                }
                                else
                                {
                                    Console.WriteLine("Enter post info");
                                    post.Content = Console.ReadLine();
                                    db.AddPost(post);
                                    logger.Info("{title} added.", post.Title);
                                }
                            }
                            else
                            {
                                logger.Error("There are no Blogs with that id");
                            }
                        }
                        else
                        {
                            logger.Error("No Blog with that ID");
                        }
                    }
                    else if (choice == 4)
                    {
                        // Display Posts
                        var db    = new BloggingContext();
                        var query = db.Blogs.OrderBy(b => b.BlogId);
                        Console.WriteLine("Select the blog's posts to display:");
                        Console.WriteLine("0) Posts from all blogs");
                        foreach (var item in query)
                        {
                            Console.WriteLine($"{item.BlogId}) Posts from {item.Name}");
                        }
                        if (int.TryParse(Console.ReadLine(), out int BlogId))
                        {
                            IEnumerable <Post> Posts;
                            if (BlogId != 0 && db.Blogs.Count(b => b.BlogId == BlogId) == 0)
                            {
                                logger.Error("There are no Blogs saved with that Id");
                            }
                            else
                            {
                                // display posts from all blogs
                                Posts = db.Posts.OrderBy(p => p.Title);
                                if (BlogId == 0)
                                {
                                    // display all posts from all blogs
                                    Posts = db.Posts.OrderBy(p => p.Title);
                                }
                                else
                                {
                                    // display post from selected blog
                                    Posts = db.Posts.Where(p => p.BlogId == BlogId).OrderBy(p => p.Title);
                                }
                                Console.WriteLine($"{Posts.Count()} post(s) returned");
                                foreach (var item in Posts)
                                {
                                    Console.WriteLine($"Blog: {item.Blog.Name}\nTitle: {item.Title}\nContent: {item.Content}\n");
                                }
                            }
                        }
                        else
                        {
                            logger.Error("Invalid Blog Id");
                        }
                    }
                    Console.WriteLine();
                } while (choice == 5);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
            logger.Info("Program ended");
        }