Exemplo n.º 1
0
 public static void PrintContent()
 {
     using (var model = new FamilyBoardModel())
     {
         foreach (var photo in model.Photos)
         {
             Console.WriteLine("Photo Title: {0}", photo.Title);
             Console.WriteLine("------------------------------");
             var comments = model.PhotoComments.Where(p => p.PhotoId == photo.Id);
             //linq
             foreach (var comment in comments)
             {
                 Console.WriteLine("Comment: {0}", comment.Content);
             }
             Console.WriteLine();
         }
         foreach (var video in model.Videos)
         {
             Console.WriteLine("Video Title: {0}", video.Title);
             Console.WriteLine("------------------------------");
             var comments = model.VideoComments.Where(p => p.VideoId == video.Id);
             foreach (var comment in comments)
             {
                 Console.WriteLine("Comment: {0}", comment.Content);
             }
             Console.WriteLine();
         }
     }
 }
Exemplo n.º 2
0
 public static void addPhoto(Photo Photo)
 {
     using (var model = new FamilyBoardModel()) {
         model.Photos.Add(Photo);
         model.SaveChanges();
     }
 }
Exemplo n.º 3
0
 public static void addVideocomment(VideoComment VideoComment)
 {
     using (var model = new FamilyBoardModel())
     {
         model.VideoComments.Add(VideoComment);
         model.SaveChanges();
     }
 }
Exemplo n.º 4
0
 public static void addPhotocomment(PhotoComment PhotoComment)
 {
     using (var model = new FamilyBoardModel())
     {
         model.PhotoComments.Add(PhotoComment);
         model.SaveChanges();
     }
 }
Exemplo n.º 5
0
 public static void addTodoList(TodoList TodoList)
 {
     using (var model = new FamilyBoardModel())
     {
         model.TodoLists.Add(TodoList);
         model.SaveChanges();
     }
 }
Exemplo n.º 6
0
 public static void addUser(User User)
 {
     using (var model = new FamilyBoardModel())
     {
         model.Users.Add(User);
         model.SaveChanges();
     }
 }
Exemplo n.º 7
0
 public static void addVideo(Video Video)
 {
     using (var model = new FamilyBoardModel())
     {
         model.Videos.Add(Video);
         model.SaveChanges();
     }
 }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            User nicole = new User("nicolepi");

            Board.addUser(nicole);
            Console.WriteLine("Welcome to Family Board!\n");
            int  choice        = -1;
            bool invalidChoice = false;
            var  input         = Console.ReadLine();
            int  UserId        = -1;

            while (choice != 0 || invalidChoice)
            {
                Console.WriteLine("1. Log in, or\n");
                Console.WriteLine("2. Create new user.\n");
                using (var model = new FamilyBoardModel())
                {
                    model.SaveChanges();
                    input = Console.ReadLine();
                    if (!int.TryParse(input, out choice))
                    {
                        invalidChoice = true;
                        Console.WriteLine("Invalid choice, try again...");
                        continue;
                    }

                    invalidChoice = false;
                    choice        = int.Parse(input);
                    break;
                }
            }
            if (choice == 1)
            {
                while (choice != 0 || invalidChoice)
                {
                    Console.WriteLine("Select a user\n");
                    using (var model = new FamilyBoardModel())
                    {
                        int i = 1;
                        foreach (var user in model.Users)
                        {
                            Console.WriteLine("{0}. {1}", i, user.UserName);
                            i++;
                        }
                        input = Console.ReadLine();
                        if (!int.TryParse(input, out choice))
                        {
                            invalidChoice = true;
                            Console.WriteLine("Invalid choice, try again...");
                            continue;
                        }

                        invalidChoice = false;


                        UserId = int.Parse(input);
                        break;
                    }
                }
            }
            else if (choice == 2)
            {
            }



            choice        = -1;
            invalidChoice = false;
            while (choice != 0 || invalidChoice)
            {
                Console.WriteLine("What do you want to do?\n");
                Console.WriteLine("1. Upload a picture.");
                Console.WriteLine("2. Upload a video.");
                Console.WriteLine("3. Leave a photo comment.");
                Console.WriteLine("4. Leave a video comment.");
                Console.WriteLine("0. Exit.\n");
                Console.Write("Please choose an option from above: ");
                input = Console.ReadLine();

                if (!int.TryParse(input, out choice))
                {
                    invalidChoice = true;
                    Console.WriteLine("Invalid choice, try again...");
                    continue;
                }
                invalidChoice = false;
                switch (choice)
                {
                case 1:
                {
                    Console.Write("Enter Photo Title: ");
                    var title = Console.ReadLine();
                    var photo = new Photo(UserId);
                    photo.Title       = title;
                    photo.DateCreated = DateTime.Now.ToString();
                    Board.addPhoto(photo);
                    break;
                }

                case 2:
                {
                    Console.Write("Enter Video Title: ");
                    var title = Console.ReadLine();
                    var video = new Video();
                    video.Title       = title;
                    video.DateCreated = DateTime.Now.ToString();
                    Board.addVideo(video);
                    break;
                }

                case 3:
                {
                    Console.WriteLine("Select a photo that you want to make a comment:\n");
                    using (var model = new FamilyBoardModel())
                    {
                        int i = 1;
                        foreach (var photo in model.Photos)
                        {
                            Console.WriteLine("{0}. {1}", i, photo.Title);
                            i++;
                        }
                        input = Console.ReadLine();
                        if (!int.TryParse(input, out choice))
                        {
                            invalidChoice = true;
                            Console.WriteLine("Invalid choice, try again...");
                            continue;
                        }

                        invalidChoice = false;

                        IEnumerable <Photo> photoQuery =
                            from photo in model.Photos
                            where photo.Id == choice
                            select photo;

                        foreach (Photo photo in photoQuery)
                        {
                            Console.WriteLine("What do you think about {0}?", photo.Title);
                        }


                        input = Console.ReadLine();
                        PhotoComment comment = new PhotoComment(UserId, choice);
                        comment.Content = input;

                        Board.addPhotocomment(comment);

                        break;
                    }
                }

                case 4:
                {
                    Console.WriteLine("Select a video that you want to make a comment:\n");
                    using (var model = new FamilyBoardModel())
                    {
                        int i = 1;
                        foreach (var video in model.Videos)
                        {
                            Console.WriteLine("{0}. {1}", i, video.Title);
                            i++;
                        }
                        input = Console.ReadLine();
                        if (!int.TryParse(input, out choice))
                        {
                            invalidChoice = true;
                            Console.WriteLine("Invalid choice, try again...");
                            continue;
                        }

                        invalidChoice = false;

                        IEnumerable <Video> videoQuery =
                            from video in model.Videos
                            where video.Id == choice
                            select video;
                        foreach (Video video in videoQuery)
                        {
                            Console.WriteLine("What do you think about {0}?", video.Title);
                        }
                        input = Console.ReadLine();
                        VideoComment comment = new VideoComment();
                        comment.Content = input;
                        comment.VideoId = choice;
                        comment.UserId  = 1;
                        Board.addVideocomment(comment);
                        break;
                    }
                }

                default:
                    break;
                }



                //Console.ReadLine(); //prevent command line from closing
            }
            Board.PrintContent();
            Console.ReadLine(); //prevent command line from closing
        }