static void AddOrNot(ref Admin.Admin a) { Console.Write("Do you wanna add post (1 for yes): "); bool isInt = int.TryParse(Console.ReadLine(), out int res); if (isInt) { if (res == 1) { Console.Clear(); Console.Write("Enter content: "); a.addPost(new Post.Post() { Content = Console.ReadLine(), CreatingDate = DateTime.Now, LikeCount = 0, ViewCount = 0 }); } } else { throw new Exception("Invalid type!"); } }
public void Start() { Admin.Admin admin = new Admin.Admin() { Username = "******", Email = "*****@*****.**", Password = "******", }; User.User u1 = new User.User() { Name = "User", Surname = "Number 1", Email = "*****@*****.**", Password = "******" }; User.User u2 = new User.User() { Name = "Sun", Surname = "Glasses", Email = "*****@*****.**", Password = "******" }; User.User u3 = new User.User() { Name = "Moon", Surname = "Shine", Email = "*****@*****.**", Password = "******" }; Post.Post p1 = new Post.Post() { Content = "Forest Holiday", CreatingDate = new DateTime(2017, 2, 25), LikeCount = 100, ViewCount = 160 }; Post.Post p2 = new Post.Post() { Content = "Snowing woww!", CreatingDate = new DateTime(2015, 12, 13), LikeCount = 20, ViewCount = 22 }; Post.Post p3 = new Post.Post() { Content = "Happy Easter everyone!", CreatingDate = new DateTime(2021, 3, 17), LikeCount = 2, ViewCount = 14 }; admin.addPost(p1); admin.addPost(p2); admin.addPost(p3); User.User[] users = new User.User[3] { u1, u2, u3 }; dynamic a; while (true) { Console.WriteLine("1)Admin"); Console.WriteLine("2)User"); try { a = Choosing(Console.ReadLine(), ref admin, ref users); Console.Clear(); if (a == 'u') { while (true) { try { LookingAround(ref users[indexofuser], ref admin); break; } catch (Exception ex) { Console.WriteLine(ex.Message); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }