public static void InsertCommentDummyData(IMongoDatabase database, TextPost tp, DataPost dp)
        {
            var comments = database.GetCollection <Comment>("Comments");

            var comment1  = new Comment(tp.PostId, tp.AuthorId, tp.AuthorName, commentstring: "Hvor er du?", new DateTime(year: 2019, month: 11, day: 29, hour: 19, minute: 3, second: 43));
            var comment2  = new Comment(dp.PostId, dp.AuthorId, dp.AuthorName, commentstring: "HVOR ER DU?", new DateTime(year: 2019, month: 11, day: 29, hour: 19, minute: 3, second: 43));
            var comment3  = new Comment(tp.PostId, tp.AuthorId, tp.AuthorName, commentstring: "WebAPI load", new DateTime(year: 2019, month: 11, day: 29, hour: 11, minute: 23, second: 23));
            var comment4  = new Comment(dp.PostId, dp.AuthorId, dp.AuthorName, commentstring: "MongoDb virker ikke", new DateTime(year: 2019, month: 11, day: 29, hour: 11, minute: 23, second: 28));
            var comment5  = new Comment(tp.PostId, tp.AuthorId, tp.AuthorName, commentstring: "Nu virker det!", new DateTime(year: 2019, month: 11, day: 29, hour: 11, minute: 53, second: 16));
            var comment6  = new Comment(dp.PostId, dp.AuthorId, dp.AuthorName, commentstring: "Giver det mening??", new DateTime(year: 2019, month: 11, day: 29, hour: 7, minute: 23, second: 23));
            var comment7  = new Comment(tp.PostId, tp.AuthorId, tp.AuthorName, commentstring: "Nu er jeg vaagen", new DateTime(year: 2019, month: 11, day: 29, hour: 10, minute: 23, second: 23));
            var comment8  = new Comment(dp.PostId, dp.AuthorId, dp.AuthorName, commentstring: "Du kan bare komme forbi kontoret", new DateTime(year: 2019, month: 11, day: 30, hour: 8, minute: 23, second: 23));
            var comment9  = new Comment(tp.PostId, tp.AuthorId, tp.AuthorName, commentstring: "Jeg tager papir med", new DateTime(year: 2019, month: 11, day: 18, hour: 4, minute: 40, second: 33));
            var comment10 = new Comment(dp.PostId, dp.AuthorId, dp.AuthorName, commentstring: "Kravsspec og review", new DateTime(year: 2019, month: 11, day: 29, hour: 10, minute: 20, second: 0));

            comments.InsertOne(comment1);
            comments.InsertOne(comment2);
            comments.InsertOne(comment3);
            comments.InsertOne(comment4);
            comments.InsertOne(comment5);
            comments.InsertOne(comment6);
            comments.InsertOne(comment7);
            comments.InsertOne(comment8);
            comments.InsertOne(comment9);
            comments.InsertOne(comment10);
        }
Пример #2
0
        public ActionResult PostToMyFeed(FeedPostModel postModel)
        {
            var loggedInUserId = User.Identity.GetUserId <int>();
            var loggedInUser   = Context.Users.FirstOrDefault(x => x.Id == loggedInUserId);

            if (postModel.ImagePost)
            {
                var post = new ImagePost
                {
                    Subject  = postModel.Subject,
                    Url      = postModel.Url,
                    Sender   = loggedInUser,
                    Receiver = loggedInUser
                };

                Context.ImagePosts.Add(post);
                Context.SaveChanges();
            }
            else
            {
                var post = new TextPost
                {
                    Subject  = postModel.Subject,
                    Content  = postModel.Content,
                    Sender   = loggedInUser,
                    Receiver = loggedInUser
                };

                Context.TextPosts.Add(post);
                Context.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public async Task <TextPost> Create(TextPost textPost)
        {
            await _textPosts.AddAsync(textPost);

            await _context.SaveChangesAsync();

            return(textPost);
        }
Пример #4
0
        static void Main(string[] args)
        {
            TextPost textPost = new TextPost
            {
                BlogName = "NewTumblrSharp",

                Id = 1,

                Trails = new List <Trail>
                {
                    new Trail()
                    {
                        Content = "test content",

                        Blog = new TrailBlog()
                        {
                            Active = true,
                            Name   = "TestBlog",
                            Theme  = new TrailTheme()
                            {
                                AvatarShape = AvatarShape.AvatarCircle,
                                ShowTitle   = true
                            }
                        }
                    },

                    new Trail()
                    {
                        Content = "test 2 content"
                    }
                },

                Notes = new List <BaseNote>
                {
                    new BaseNote()
                    {
                        PostId    = "1",
                        ReplyText = "This a note",
                        Type      = NoteType.Reblog
                    },

                    new PostAttributionNote()
                    {
                        PostId = "2",
                        Post_attribution_type = "test",
                        Type = NoteType.Post_attribution
                    }
                },

                NotesCount = 2
            };

            string json = JsonConvert.SerializeObject(textPost, Formatting.Indented);

            Console.WriteLine(json);

            Console.ReadLine();
        }
Пример #5
0
        static void Main(string[] args)
        {
            using (var context = new BlogContext())
            {
                var videoPost = new VideoPost
                {
                    Blog = new Blog
                    {
                        Name   = "Blog1",
                        Author = new Author
                        {
                            Name = "Jan Kowalski"
                        }
                    },
                    Title    = "test",
                    VideoUrl = "http://fake/adres"
                };

                context.Add(videoPost);

                var podcastPost = new PodcastPost
                {
                    Blog = new Blog
                    {
                        Name   = "Blog2",
                        Author = new Author
                        {
                            Name = "Jan Kowalski"
                        }
                    },
                    Title      = "test",
                    PodcastUrl = "http://fake/adres"
                };

                context.Add(podcastPost);

                var textPost = new TextPost
                {
                    Blog = new Blog
                    {
                        Name   = "Blog3",
                        Author = new Author
                        {
                            Name = "Jan Kowalski"
                        }
                    },
                    Title       = "test",
                    PostContent = "test"
                };

                context.Add(textPost);

                context.SaveChanges();
            }
        }
        public async Task <TextPost> Update(TextPost updatedTextPost)
        {
            var existingTextPost = _textPosts.FirstOrDefault(c => c.Id == updatedTextPost.Id);

            _textPosts.Update(existingTextPost);
            MapUpdatedValues(existingTextPost, updatedTextPost);

            await _context.SaveChangesAsync();

            return(existingTextPost);
        }
Пример #7
0
        private static async Task PostImageToSlack(string channel, string[] thumbnailUrls)
        {
            using (var client = new HttpClient()) {
                object payload;

                if (thumbnailUrls != null)
                {
                    payload = new ImagePost()
                    {
                        token       = getToken(),
                        channel     = channel,
                        text        = "",
                        attachments = thumbnailUrls.Select(x => {
                            return(new ImagePostAttachment()
                            {
                                fallback = x,
                                image_url = x
                            });
                        }).ToList()
                    };
                }
                else
                {
                    payload = new TextPost()
                    {
                        token   = getToken(),
                        channel = channel,
                        text    = "そんな画像はありません"
                    };
                }

                var msg = new HttpRequestMessage {
                    RequestUri = new Uri("https://slack.com/api/chat.postMessage"),
                    Method     = HttpMethod.Post,
                    Headers    =
                    {
                        { HttpRequestHeader.Authorization.ToString(), $"Bearer {getToken()}" },
                        { HttpRequestHeader.ContentType.ToString(),   "application/json"     },
                    },
                    Content = new StringContent(
                        JsonConvert.SerializeObject(payload),
                        Encoding.UTF8,
                        "application/json"
                        )
                };

                var reslut = await client.SendAsync(msg);

                await reslut.Content.ReadAsStringAsync();
            }
        }
Пример #8
0
        public T Post <U, T>(string url, U request)
        {
            TextPost post = new TextPost(url);

            logger.Info("Post request url" + url);
            post.SetAccept(contentType);
            post.SetContentType(contentType);
            string body = serializer.Serialize(request);

            post.Body = body;
            logger.Info("Post request body: " + body);
            ConstructRequestHeader(post, HttpConstans.METHOD_POST, url, body);
            return(Execute <T>(post));
        }
Пример #9
0
        private TextPost ParseTextPost(JObject jObject, HashSet <string> checkedProperties)
        {
            TextPost newPost = new TextPost();
            JToken   current;

            if (CheckProperty(jObject, "title", checkedProperties, out current))
            {
                newPost.Title = (string)current;
            }
            if (CheckProperty(jObject, "body", checkedProperties, out current))
            {
                newPost.Body = (string)current;
            }
            return(newPost);
        }
Пример #10
0
        public async Task <IActionResult> Post([FromBody] TextPost value)
        {
            var applicationUser = await _userManager.GetUserAsync(HttpContext.User);

            if (applicationUser == null)
            {
                return(Unauthorized());
            }
            var user = _userService.GetUserById(applicationUser.Id);

            value.PostAuthor   = user;
            value.CreationTime = DateTime.Now;
            var postText = await _service.Create(value);

            return(Ok(postText));
        }
Пример #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="post"></param>
        /// <param name="jPost"></param>
        public static void GenerateTextPost(ref TumblrPost post, dynamic jPost)
        {
            if (post == null)
            {
                throw new ArgumentNullException(nameof(post));
            }
            if (jPost == null)
            {
                throw new ArgumentNullException(nameof(jPost));
            }

            post = new TextPost
            {
                Title = !string.IsNullOrEmpty((string)jPost.title) ? jPost.title : null,
                Body  = !string.IsNullOrEmpty((string)jPost.body) ? jPost.body : null
            };
            IncludeCommonPostFields(ref post, jPost);
        }
Пример #12
0
        public void TestPosts2()
        {
            using (var context = new GeneralContext())
            {
                var user1 = context.Users.FirstOrDefault(x => x.Id == 1);
                var user2 = context.Users.FirstOrDefault(x => x.Id == 2);

                var p = new TextPost()
                {
                    Name     = "Name 1",
                    Receiver = user1,
                    Sender   = user2,
                    Subject  = "Saying Hi 1",
                    Content  = "Content 1"
                };

                context.TextPosts.Add(p);
                context.SaveChanges();
            }
        }
Пример #13
0
        public void NoteConverter_Theorie()
        {
            const string resultStr = "{\r\n  \"title\": null,\r\n  \"body\": \"testbody\",\r\n  \"type\": \"All\",\r\n  \"blog_name\": \"TestBlog\"," +
                                     "\r\n  \"id\": 12456789,\r\n  \"post_url\": null,\r\n  \"slug\": null,\r\n  \"timestamp\": -62135596800.0,\r\n  \"state\": \"published\"," +
                                     "\r\n  \"format\": \"Html\",\r\n  \"reblog_key\": null,\r\n  \"tags\": null,\r\n  \"short_url\": null,\r\n  \"summary\": null," +
                                     "\r\n  \"note_count\": 0,\r\n  \"notes\": [\r\n    {\r\n      \"type\": \"Like\",\r\n      \"timestamp\": -62135596800.0," +
                                     "\r\n      \"blog_name\": \"OtherBlock\",\r\n      \"blog_uuid\": null,\r\n      \"blog_url\": null,\r\n      \"followed\": false," +
                                     "\r\n      \"avatar_shape\": \"circle\",\r\n      \"reply_text\": null,\r\n      \"post_id\": null,\r\n      \"reblog_parent_blog_name\": null\r\n    }\r\n  ]," +
                                     "\r\n  \"source_url\": null,\r\n  \"source_title\": null,\r\n  \"total_posts\": 0,\r\n  \"liked\": null,\r\n  \"mobile\": null," +
                                     "\r\n  \"bookmarklet\": null,\r\n  \"reblog\": null,\r\n  \"reblogged_from_id\": 0,\r\n  \"reblogged_from_url\": null," +
                                     "\r\n  \"reblogged_from_name\": null,\r\n  \"reblogged_from_title\": null,\r\n  \"reblogged_root_id\": 0,\r\n  \"reblogged_root_url\": null," +
                                     "\r\n  \"reblogged_root_name\": null,\r\n  \"reblogged_root_title\": null,\r\n  \"trail\": []\r\n}";

            TextPost basicTextPost = new TextPost
            {
                BlogName = "TestBlog",
                Body     = "testbody",
                Id       = 12456789,
                Format   = PostFormat.Html,
                Trails   = new List <Trail>()
            };

            basicTextPost.Notes = new List <BaseNote>
            {
                new BaseNote()
                {
                    BlogName    = "OtherBlock",
                    Type        = NoteType.Like,
                    AvatarShape = AvatarShape.Circle
                }
            };

            // convert post
            string json = JsonConvert.SerializeObject(basicTextPost, Formatting.Indented);

            Assert.AreEqual(resultStr, json);

            TextPost tp = JsonConvert.DeserializeObject <TextPost>(json);

            Assert.AreEqual(basicTextPost.Notes[0].BlogName, tp.Notes[0].BlogName);
        }
Пример #14
0
        public async Task <IActionResult> LikeTextPost([FromBody] TextPost textPost)
        {
            var applicationUser = await _userManager.GetUserAsync(HttpContext.User);

            if (applicationUser == null)
            {
                return(Unauthorized());
            }
            var user         = _userService.GetUserById(applicationUser.Id);
            var textPostLike = new TextPostLike
            {
                LikeOwner = user
            };

            textPost.Likes.Add(textPostLike);
            await _service.Like(textPostLike);

            var likedTextPost = await _service.Update(textPost);

            return(Ok(likedTextPost));
        }
Пример #15
0
        public virtual PartialViewResult Index(IndexViewModel model)
        {
            if (!string.IsNullOrWhiteSpace(model.NewTextPost))
            {
                TextPost newTextPost = new TextPost();
                newTextPost.Owner       = CurrentUser;
                newTextPost.SubjectUser = Target;
                newTextPost.Text        = model.NewTextPost;
                if (model.NewTextPostParent != -1)
                {
                    newTextPost.IsReplyTo = db.FeedItems.Find(model.NewTextPostParent);
                    if (!CurrentUser.IsAllowedTo(Permission.Reply, newTextPost.IsReplyTo))
                    {
                        throw new ArgumentException("Posted to different family");
                    }
                }
                db.FeedItems.Add(newTextPost);
                db.SaveChanges();
            }

            return(Index());
        }
            public void PopulatesPropertiesFromBasePost()
            {
                // Arrange
                var postDateTime = DateTime.Now;
                var basePost     = new TextPost()
                {
                    Id        = 12345,
                    Timestamp = postDateTime,
                    BlogName  = "blackjackkent",
                    Url       = "http://www.test.com",
                    Title     = "My Awesome Title"
                };

                // Act
                var adapter = new PostAdapter(basePost);

                // Assert
                adapter.Id.Should().Be(basePost.Id.ToString(CultureInfo.InvariantCulture));
                adapter.Timestamp.Should().Be(basePost.Timestamp);
                adapter.BlogName.Should().Be(basePost.BlogName);
                adapter.Url.Should().Be(basePost.Url);
                adapter.Title.Should().Be(basePost.Title);
            }
Пример #17
0
        public void GetWall(string userid, string guestId)
        {
            var user  = _users.Find(findUser => findUser.Id == userid).FirstOrDefault();
            var guest = _users.Find(findGuest => findGuest.Id == guestId).FirstOrDefault();

            if (user == null || guest == null)
            {
                Console.WriteLine("User or guest doesn't exist");
                return;
            }

            if (user.BlockId != null)
            {
                if (user.BlockId.Contains(guestId))
                {
                    Console.WriteLine("Guest is blocked by user!");
                    return;
                }
            }

            var wall = _posts.Find(postsOnWall =>
                                   postsOnWall.AuthorId == user.Id)
                       .SortBy(post => post.DateTime).Limit(5).ToList();

            if (wall.Count == 0 || wall == null)
            {
                Console.WriteLine("There's no posts on the wall!");
                return;
            }

            foreach (var wp in wall)
            {
                if (!wp.IsPublic && !wp.BlockedAllowedUserId.Contains(guestId))
                {
                    continue;
                }

                if (wp is DataPost)
                {
                    DataPost dp = (DataPost)wp;
                    Console.WriteLine($"Wall: {dp.UrlToData}");
                }
                else if (wp is TextPost)
                {
                    TextPost tp = (TextPost)wp;
                    Console.WriteLine($"Wall: {tp.Text}");
                }

                var comments = _comments.Find(comment =>
                                              comment.PostId == wp.PostId)
                               .SortByDescending(comment => comment.PostId).Limit(5).ToList();


                if (comments == null)
                {
                    Console.WriteLine("There's no comment to the post on the wall");
                    return;
                }

                foreach (var c in comments)
                {
                    Console.WriteLine($"Comment: {c.CommentString} at {c.DateTime}");
                }
            }
        }
Пример #18
0
        static void Main(string[] args)
        {
            // connects to a local database
            Services.Services._client   = new MongoClient("mongodb://127.0.0.1:27017/");
            Services.Services._database = Services.Services._client.GetDatabase("SocialNetworkDb");

            services.CreateCollections();    //comment this out after first run of the programme
            services.retrieveCollections();

            SetUp  setUp = new SetUp(services);
            string input = "0";

            // insert dummydata
            Console.WriteLine("Want to insert dummydata? press D (Press any button if don't wish to add dummy data)");
            Console.WriteLine("NOTE: if this is the first time running the program, its an good idea to insert dummyData");
            input = Console.ReadLine();
            switch (input)
            {
            case "D":
                setUp.seedData();
                Console.WriteLine("DummyData inserted!");
                input = "0";
                break;

            default:
                Console.WriteLine("DummyData not inserted!");
                input = "0";
                break;
            }
            //SetUp.SeedingData();           //comment this out after first run of the programme

            User Currentuser = new User();
            Wall wall        = new Wall(services);
            Feed feed        = new Feed(services);

            Console.WriteLine("WELCOME TO THE SOCIAL NETWORK");
            Currentuser = setUp.UserLogin();



            //string input = "0";

            while (true)
            {
                switch (input)
                {
                case "0":
                    InitMessage();
                    input = Console.ReadLine();
                    break;

                case "1":
                    CreatePostPrintout();
                    string postType = Console.ReadLine();
                    string postContent;
                    if (postType == "T")
                    {
                        Console.WriteLine("Please enter content for your post");
                        postContent = Console.ReadLine();
                        TextPost textPost = new TextPost()
                        {
                            CreationTime = DateTime.Now,
                            TextContent  = postContent,
                            Author       = Currentuser.UserName
                        };
                        setUp.PostOptions(Currentuser, textPost);
                    }
                    else if (postType == "V")
                    {
                        Console.WriteLine("Please enter Video title: ");
                        var       videoContent = Console.ReadLine();
                        string    videoInput   = "";
                        VideoPost videoPost    = new VideoPost()
                        {
                            CreationTime = DateTime.Now,
                            VideoContent = videoContent,
                            Options      = new Dictionary <string, int>(),
                            Author       = Currentuser.UserName
                        };

                        do
                        {
                            Console.WriteLine("--------------------------------------");
                            Console.WriteLine("|| 0  || Where to post               ||");
                            Console.WriteLine("|| 1  || Create Video                ||");
                            videoInput = Console.ReadLine();
                            if (videoInput == "1")
                            {
                                Console.WriteLine("------------------------------------------------------------------------------------------");
                                Console.WriteLine("||                       PLEASE ENTER VIDEO CONTENT                                       ||");
                                Console.WriteLine("------------------------------------------------------------------------------------------");
                                var content = Console.ReadLine();
                                videoPost.Options.Add(content, 0);
                            }
                        } while (videoInput != "0");
                        setUp.PostOptions(Currentuser, videoPost);
                        Console.WriteLine("-------------------------------------------------------------------------------------------");
                        Console.WriteLine("||                       THE VIDEO HAS BEEN POSTED SUCCESSFULLY!                         ||");
                        Console.WriteLine("-------------------------------------------------------------------------------------------");
                    }
                    input = "0";
                    break;

                case "2":
                    Console.WriteLine("Please enter a user to visit their wall:");
                    var userInput = Console.ReadLine();
                    var findUser  = services.GetUser().FirstOrDefault(u => userInput == u.UserName);
                    if (findUser == null)
                    {
                        Console.WriteLine("------------------------------------------------------------------------------------------");
                        Console.WriteLine("||                       WARNING: USER DOES NOT EXIST - PRESS ENTER TO CONTINUE         ||");
                        Console.WriteLine("------------------------------------------------------------------------------------------");
                        Console.ReadLine();
                        input = "0";
                        break;
                    }
                    var wallOfUser       = wall.GetWall(findUser.UserId, Currentuser.UserId);
                    int PostnumberOnWall = 1;
                    foreach (var post in wallOfUser)
                    {
                        Console.WriteLine($"------------------ PostNumber: {PostnumberOnWall++} ------------------------");
                        post.print();
                    }

                    Console.WriteLine("|| 0  || Enter to add a comment      ||");
                    if (wallOfUser.OfType <VideoPost>().Any())
                    {
                        Console.WriteLine("|| 1  || Enter to vote on meme   ||");
                    }
                    Console.WriteLine("|| Enter  || To continue             ||");
                    var commentWallChoice = Console.ReadLine();
                    if (commentWallChoice == "0")
                    {
                        var wallCommentNumber = 0;
                        do
                        {
                            Console.WriteLine("Please enter the number of the post you wish to comment on:");
                            wallCommentNumber = int.Parse(Console.ReadLine());
                            if (wallCommentNumber <= 5 && wallCommentNumber >= 1)
                            {
                                break;
                            }
                            warningMessageNumber_NotValid();
                        } while (true);

                        Console.WriteLine(wallOfUser[wallCommentNumber - 1].Author);
                        setUp.NewComment(wallOfUser[wallCommentNumber - 1]);
                    }
                    else if (commentWallChoice == "1")
                    {
                        var wallMemeNumber = 0;
                        do
                        {
                            Console.WriteLine("Please enter the number of the post you wish to vote on:");
                            wallMemeNumber = int.Parse(Console.ReadLine());
                            if (wallMemeNumber <= 5 && wallMemeNumber >= 1)
                            {
                                break;
                            }
                            if ((wallOfUser[wallMemeNumber - 1] is VideoPost))
                            {
                                break;
                            }
                            warningMessageNumber_NotValid();
                        } while (true);

                        Console.WriteLine("Choose the option to vote for: (Name of the option. Case sensitive)");
                        var WallMemeChoice = Console.ReadLine();
                        var post           = wallOfUser[wallMemeNumber - 1] as VideoPost;
                        post.Options[WallMemeChoice]++;
                        setUp.UpdatePosts(post);
                    }
                    input = "0";
                    break;

                case "3":
                    Console.WriteLine("------------------------------------------------------------------------------------------");
                    Console.WriteLine("||                       THIS IS YOUR FEED                                              ||");
                    Console.WriteLine("------------------------------------------------------------------------------------------");
                    var yourFeed         = feed.ShowFeed(Currentuser.UserId);
                    int postNumberInFeed = 1;
                    foreach (var post in yourFeed)
                    {
                        Console.WriteLine($"------------------ PostNumber: {postNumberInFeed++} ------------------------");
                        post.print();
                    }

                    Console.WriteLine("|| 0  || Enter to add a comment for one of the posts      ||");
                    if (yourFeed.OfType <VideoPost>().Any())
                    {
                        Console.WriteLine("|| 1  || Enter to vote on meme   ||");
                    }
                    Console.WriteLine("|| Enter  || To continue             ||");
                    var choosingComment = Console.ReadLine();
                    if (choosingComment == "0")
                    {
                        var numberCommentsOfFeed = 0;
                        do
                        {
                            Console.WriteLine("Please enter the number of post you wish to comment on: ");
                            numberCommentsOfFeed = int.Parse(Console.ReadLine());
                            if (numberCommentsOfFeed <= 5 && numberCommentsOfFeed >= 1)
                            {
                                break;
                            }

                            warningMessageNumber_NotValid();
                        } while (true);

                        setUp.NewComment(yourFeed[numberCommentsOfFeed - 1]);
                    }
                    else if (choosingComment == "1")
                    {
                        var feedMemeNumber = 0;
                        do
                        {
                            Console.WriteLine("Please enter the number of the post you wish to vote on: ");
                            feedMemeNumber = int.Parse(Console.ReadLine());
                            if (feedMemeNumber <= 5 && feedMemeNumber >= 1)
                            {
                                break;
                            }
                            if ((yourFeed[feedMemeNumber - 1] is VideoPost))
                            {
                                break;
                            }
                            warningMessageNumber_NotValid();
                        } while (true);

                        Console.WriteLine("Choose the option to vote for: (Name of the option. Case sensitive)");
                        var feedMemeChoice = Console.ReadLine();
                        var post           = yourFeed[feedMemeNumber - 1] as VideoPost;
                        post.Options[feedMemeChoice]++;
                        setUp.UpdatePosts(post);
                    }
                    input = "0";
                    break;

                case "4":
                    Console.WriteLine("Please enter a username you wish to add to your blocked list:");
                    var BlockedUser     = Console.ReadLine();
                    var findUserToBlock = services.GetUser().FirstOrDefault(u => BlockedUser == u.UserName);
                    if (findUserToBlock == null)
                    {
                        Console.WriteLine("------------------------------------------------------------------------------------------");
                        Console.WriteLine("||                           WARNING: USER DOES NOT EXIST!                              ||");
                        Console.WriteLine("------------------------------------------------------------------------------------------");
                        input = "0";
                        break;
                    }

                    if (Currentuser.BlockedList.Contains(findUserToBlock.UserId))
                    {
                        Currentuser.BlockedList.Add(findUserToBlock.UserId);
                        Console.WriteLine("------------------------------------------------------------------------------------------");
                        Console.WriteLine("||                        A USER HAS BEEN BLOCKED SUCCESSFULLY!                         ||");
                        Console.WriteLine("------------------------------------------------------------------------------------------");
                    }
                    else
                    {
                        Currentuser.BlockedList.Remove(findUserToBlock.UserId);
                        Console.WriteLine("------------------------------------------------------------------------------------------");
                        Console.WriteLine("||                        A USER HAS BEEN UNBLOCKED SUCCESSFULLY!                       ||");
                        Console.WriteLine("------------------------------------------------------------------------------------------");
                    }
                    services.UpdateUser(Currentuser.UserId, Currentuser);

                    input = "0";
                    break;

                case "5":
                    Console.WriteLine("Please enter the username you want to follow/unfollow: ");
                    var UserToFollow     = Console.ReadLine();
                    var findUserToFollow = services.GetUser().FirstOrDefault(u => UserToFollow == u.UserName);
                    if (findUserToFollow == null)
                    {
                        Console.WriteLine("\nUser does not exist");
                        input = "0";
                        break;
                    }

                    if (Currentuser.FriendList.Contains(findUserToFollow.UserId)) // hvis user findes i db vil den gå ind i if noget med circle
                    {
                        if (Currentuser.Circles == findUserToFollow.Circles)      // hvis der findes et circlename i currentusers circles, som også findes i findUsertoFollows circles
                        {
                            Currentuser.FriendList.Add(findUserToFollow.UserId);
                            Console.WriteLine("------------------------------------------------------------------------------------------");
                            Console.WriteLine("||                    A USER HAS BEEN ADDED TO YOUR FRIENDLIST SUCCESSFULLY!            ||");
                            Console.WriteLine("------------------------------------------------------------------------------------------");
                            break;
                        }
                        Currentuser.FriendList.Add(findUserToFollow.UserId);
                        Console.WriteLine("------------------------------------------------------------------------------------------");
                        Console.WriteLine("||                    A USER HAS BEEN ADDED TO YOUR FRIENDLIST SUCCESSFULLY!            ||");
                        Console.WriteLine("------------------------------------------------------------------------------------------");
                    }
                    else
                    {
                        Currentuser.FriendList.Remove(findUserToFollow.UserId);
                        Console.WriteLine("------------------------------------------------------------------------------------------");
                        Console.WriteLine("||                    A USER HAS BEEN REMOVED FROM YOUR FRIENDLIST SUCCESSFULLY!          ||");
                        Console.WriteLine("------------------------------------------------------------------------------------------");
                    }
                    //Currentuser.FriendList.Add(findUserToFollow.UserId);
                    services.UpdateUser(Currentuser.UserId, Currentuser);

                    input = "0";
                    break;

                case "6":
                    setUp.newUser();
                    break;

                case "7":
                    setUp.AddCircle(Currentuser);
                    input = "0";
                    break;

                case "8":
                    Currentuser = setUp.UserLogin();
                    input       = "0";
                    break;

                case "9":
                    return;

                default:
                    Console.WriteLine("------------------------------------------------------------------------------------------");
                    Console.WriteLine("||                         WARNING: WRONG COMMAND - PLEASE TRY AGAIN                    ||");
                    Console.WriteLine("------------------------------------------------------------------------------------------");
                    input = "0";
                    break;
                }
            }
        }
Пример #19
0
        static void Main(string[] args)
        {
            int score = 0;

            Console.Write("TEST1: Ist die Post Klasse abstrakt? ");
            score += AssertTrue(() => typeof(Post).IsAbstract);

            Console.Write("TEST2: Kann ein TextPost angelegt werden? ");
            DateTime time = DateTime.Now.AddMinutes(-10);
            TextPost tp1  = new TextPost("Mein Titel");
            TextPost tp2  = new TextPost("Mein 2. Titel", time);

            score += AssertTrue(() => tp1.Title == "Mein Titel" && tp2.Created == time);

            Console.Write("TEST3: Kann ein ImagePost angelegt werden? ");
            ImagePost ip1 = new ImagePost("Mein Titel");
            ImagePost ip2 = new ImagePost("Mein Titel", time);

            score += AssertTrue(() => ip1.Title == "Mein Titel" && ip2.Created == time);

            Console.Write("TEST4: Stimmt die Länge des Postings? ");
            TextPost tp3 = new TextPost("Mein Titel", time);
            TextPost tp4 = new TextPost("Mein Titel", time)
            {
                Content = "Content"
            };

            score += AssertTrue(() => tp3.Length == 0 && tp4.Length == 7);

            Console.Write("TEST5: Stimmt das HTML Property von TextPost? ");
            Post tp5 = new TextPost("Mein Titel", time)
            {
                Content = "Content"
            };

            score += AssertTrue(() => tp5.Html == "<p>Content</p>");

            Console.Write("TEST6: Stimmt das HTML Property von ImagePost? ");
            Post ip3 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png"
            };

            score += AssertTrue(() => ip3.Html == "<img src=\"http://image.png\">");

            Console.Write("TEST7: Stimmt die ToString Repräsentation von Post? ");
            object ip4 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png"
            };

            score += AssertTrue(() => ip4.ToString() == "<img src=\"http://image.png\">");

            Console.Write("TEST8: Ist das Length Property von TextPost readonly? ");
            PropertyInfo info = typeof(TextPost).GetMember("Length")[0] as PropertyInfo;

            score += AssertTrue(() => info.CanWrite == false);

            Console.Write("TEST9: Ist das Title Property von Post readonly? ");
            PropertyInfo info2 = typeof(Post).GetMember("Title")[0] as PropertyInfo;

            score += AssertTrue(() => info2.CanWrite == false);

            Console.Write("TEST10: Funktioniert die PostCollection? ");
            TextPost tp6 = new TextPost("Mein Titel", time)
            {
                Content = "Content"
            };
            ImagePost ip5 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png"
            };
            PostCollection pc1 = new PostCollection();

            pc1.Add(tp6);
            pc1.Add(ip5);
            score += AssertTrue(() => pc1.Count == 2);

            Console.Write("TEST11: Funktioniert CalcRating mit Lambdas? ");
            TextPost tp7 = new TextPost("Mein Titel", time)
            {
                Content = "Content", Rating = 10
            };
            ImagePost ip6 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png", Rating = -1
            };
            PostCollection pc2 = new PostCollection();

            pc2.Add(tp7);
            pc2.Add(ip6);
            score += AssertTrue(() => pc2.CalcRating(p => p.Rating > 0 ? p.Rating : 0) == 10);

            Console.Write("TEST12: Funktioniert ProcessPosts mit Lambdas? ");
            TextPost tp8 = new TextPost("Mein Titel", time)
            {
                Content = "Content", Rating = 10
            };
            ImagePost ip7 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png", Rating = -1
            };
            PostCollection pc3 = new PostCollection();

            pc3.Add(tp8);
            pc3.Add(ip7);
            int ratingSum = 0;

            pc3.ProcessPosts(p => ratingSum += p.Rating);
            score += AssertTrue(() => ratingSum == 9);

            double percent = score / 12.0;
            int    note    = percent > 0.875 ? 1 : percent > 0.75 ? 2 : percent > 0.625 ? 3 : percent > 0.5 ? 4 : 5;

            Console.WriteLine($"{score} von 12 Punkten erreicht. Note: {note}.");
            Console.ReadLine();
        }
Пример #20
0
        //Get feed from er specific user
        public void GetFeed(string userid)
        {
            var user = _users.Find(findUser => findUser.Id == userid).FirstOrDefault();

            //Find user from whom, you want to see feed
            if (user == null)
            {
                Console.WriteLine("User doesn't exist");
                return;
            }


            var userFeed = _posts.Find(post =>
                                       //Checking if post is private or public, if the use is blocked
                                       //or not - and if the user follows the author of post
                                       (post.IsPublic == false &&
                                        post.BlockedAllowedUserId.Contains(userid) &&
                                        user.FollowId.Contains(post.AuthorId)) ||

                                       //If the post is public - we're checking if the user
                                       //is in the "blockedAllowedUserId list (if the user is, post wont show in feed)
                                       (post.IsPublic &&
                                        !post.BlockedAllowedUserId.Contains(userid) &&
                                        user.FollowId.Contains(post.AuthorId)
                                       ))
                           .SortByDescending(post => post.PostId).Limit(5).ToList();

            if (userFeed.Count == 0)
            {
                Console.WriteLine("User has no feed to see");
                return;
            }
            foreach (var f in userFeed)
            {
                if (f is DataPost)
                {
                    DataPost dp = (DataPost)f;
                    Console.WriteLine($"Feed: {dp.UrlToData}");
                }
                else if (f is TextPost)
                {
                    TextPost tp = (TextPost)f;
                    Console.WriteLine($"Feed: {tp.Text}");
                }

                //Console.WriteLine($"Feed: {f}");

                var comments = _comments.Find(comment =>
                                              comment.PostId == f.PostId)
                               .SortByDescending(comment => comment.PostId).Limit(5).ToList();

                if (comments == null)
                {
                    Console.WriteLine("There's no comment to the post on the feed");
                    return;
                }
                foreach (var c in comments)
                {
                    Console.WriteLine($"Comment: {c.CommentString} at {c.DateTime}");
                }
            }
            ////////////////////////////////////////////////////////////////////////////////////////
        }
Пример #21
0
        protected override void Seed(KidStepsContext context)
        {
            //throw new Exception();

            // install/initialize asp.net membership services
            SqlServices.Install(
                "KidSteps",
                SqlFeatures.Membership | SqlFeatures.RoleManager | SqlFeatures.Profile,
                WebConfigurationManager.ConnectionStrings["KidStepsContext"].ConnectionString);
            //foreach (Models.Role role in Enum.GetValues(typeof(Models.Role)))
            //    Roles.CreateRole(role.ToString());

            // todo: unique constraint for email

            // create admin users
            UserRepository         userRepos = new UserRepository();
            MembershipCreateStatus _;
            User pinchas = userRepos.CreateFamilyMember(context, new PersonName("Pinchas", "Friedman"), "*****@*****.**", "admin", out _);

            pinchas.RoleFlags |= Role.SuperUser;
            User moshe = userRepos.CreateFamilyMember(context, new PersonName("Moshe", "Starkman"), "*****@*****.**", "moshe", out _);

            moshe.RoleFlags |= Role.SuperUser;

            // create add admin users' relationships to kids
            FamilyRepository familyRepos = new FamilyRepository();
            User             shalom      = familyRepos.AddFamilyMember(context, pinchas.Family, new PersonName("Shalom", "Friedman"), null, true);

            familyRepos.UpdateRelationship(context, new Relationship()
            {
                SourceUser = pinchas, RelatedUser = shalom, RelatedUserIsSourceUsers = RelationshipType.Child
            });

            User yael = familyRepos.AddFamilyMember(context, pinchas.Family, new PersonName("Yael", "Friedman"), null, false);

            familyRepos.UpdateRelationship(context, new Relationship()
            {
                SourceUser = yael, RelatedUser = shalom, RelatedUserIsSourceUsers = RelationshipType.Child
            });
            familyRepos.UpdateRelationship(context, new Relationship()
            {
                SourceUser = pinchas, RelatedUser = yael, RelatedUserIsSourceUsers = RelationshipType.Spouse
            });

            // add some comments
            FeedItem t1 = new TextPost()
            {
                Owner       = pinchas,
                SubjectUser = pinchas,
                Text        = "Foo"
            };
            FeedItem t2 = new TextPost()
            {
                Owner       = pinchas,
                SubjectUser = pinchas,
                Text        = "Foo2",
                IsReplyTo   = t1
            };
            FeedItem t3 = new TextPost()
            {
                Owner       = pinchas,
                SubjectUser = pinchas,
                Text        = " New Foo"
            };

            context.FeedItems.Add(t1);
            context.FeedItems.Add(t2);
            context.FeedItems.Add(t3);

            context.SaveChanges();
        }
Пример #22
0
 public ActionResult <TextPost> UpdatePost([FromBody] TextPost post)
 {
     _context.TextPost.Update(post);
     _context.SaveChanges();
     return(Created("", post));
 }
        public void InsertDummyData(IMongoDatabase database, string connection)
        {
            var users       = database.GetCollection <User>("Users");
            var posts       = database.GetCollection <Post>("Posts");
            var comments    = database.GetCollection <Comment>("Comments");
            var circles     = database.GetCollection <Circle>("Circles");
            var userService = new UserServices(connection);

            var rand      = new Random(DateTime.Now.Millisecond);
            var usersList = new List <User>();

            #region Users

            for (int i = 0; i < 20; i++)
            {
                var r      = rand.Next(2);
                var gender = r == 1 ? "M" : "F";
                var user   = new User("Name_" + i.ToString(), i + 10, gender);
                usersList.Add(user);
            }
            users.InsertMany(usersList);

            usersList = users.Find(u => true).ToList();

            foreach (var u in usersList)
            {
                foreach (var un in usersList.Where(un => un != u))
                {
                    var uUpdate = users.Find <User>(us => us.Id == u.Id).FirstOrDefault();
                    if (rand.Next(3) == 2)
                    {
                        userService.BlockUser(u.Id, un.Id);
                    }
                    else
                    {
                        userService.Follow(u.Id, un.Id);
                    }
                }
            }

            #endregion

            #region Circle

            foreach (var u in usersList)
            {
                var c1 = new Circle(u.Name + "_C1", u.Id);
                var c2 = new Circle(u.Name + "_C2", u.Id);
                var c3 = new Circle(u.Name + "_C3", u.Id);
                foreach (var un in usersList.Where(un => un != u))
                {
                    var random = rand.Next(3);
                    if (random == 0)
                    {
                        c1.UserIds.Add(un.Id);
                    }
                    else if (random == 1)
                    {
                        c2.UserIds.Add(un.Id);
                    }
                    else if (random == 2)
                    {
                        c3.UserIds.Add(un.Id);
                    }
                }
                circles.InsertOne(c1);
                circles.InsertOne(c2);
                circles.InsertOne(c3);

                var c1d = circles.Find <Circle>(c => c.Name == u.Name + "_C1").FirstOrDefault();
                var c2d = circles.Find <Circle>(c => c.Name == u.Name + "_C2").FirstOrDefault();
                var c3d = circles.Find <Circle>(c => c.Name == u.Name + "_C3").FirstOrDefault();

                var updateCircle1Id = Builders <User> .Update.AddToSet(u => u.CircleId, c1d.CircleId);

                var updateCircle2Id = Builders <User> .Update.AddToSet(u => u.CircleId, c2d.CircleId);

                var updateCircle3Id = Builders <User> .Update.AddToSet(u => u.CircleId, c3d.CircleId);

                users.FindOneAndUpdate(us => us.Id == u.Id, updateCircle1Id);
                users.FindOneAndUpdate(us => us.Id == u.Id, updateCircle2Id);
                users.FindOneAndUpdate(us => us.Id == u.Id, updateCircle3Id);
            }
            usersList = users.Find(u => true).ToList();
            #endregion


            #region Post
            int timeToAdd = 0;
            //Dummy Posts
            foreach (var user in usersList)
            {
                TextPost textPost = new TextPost();
                DataPost dataPost = new DataPost();

                textPost.AuthorId = user.Id;
                dataPost.AuthorId = user.Id;

                textPost.AuthorName = user.Name;
                dataPost.AuthorName = user.Name;

                bool randPublicPost = rand.Next(2) == 1 ? true : false;

                textPost.IsPublic = randPublicPost;
                dataPost.IsPublic = randPublicPost;

                string publicPost = randPublicPost == true ? "public" : "private";

                textPost.Text      = $"My name is {textPost.AuthorName} and my ID is {textPost.AuthorId}. This is a {publicPost} TEXTPOST.";
                dataPost.UrlToData = $"Audio: 'My name is {dataPost.AuthorName} and my ID is {dataPost.AuthorId}. This is a {publicPost} DATAPOST.'";

                //Overwrite DateTime
                textPost.DateTime.AddHours(timeToAdd);
                dataPost.DateTime.AddHours(timeToAdd);
                timeToAdd++;

                posts.InsertOne(textPost);
                posts.InsertOne(dataPost);

                if (randPublicPost == true)
                {
                    foreach (var id in user.BlockId)
                    {
                        var updateBlockedAllowedUserId = Builders <Post> .Update.AddToSet(post => post.BlockedAllowedUserId, id);

                        posts.FindOneAndUpdate(post => post.AuthorId == user.Id, updateBlockedAllowedUserId);
                    }
                }
                else
                {
                    for (int i = 0; i < user.CircleId.Count; i++)
                    {
                        var c = circles.Find <Circle>(c => c.CircleId == user.CircleId[i]).FirstOrDefault();

                        var updateBlockedAllowedUserId = Builders <Post> .Update.AddToSet(post => post.BlockedAllowedUserId, c.CircleId);

                        posts.FindOneAndUpdate(post => post.AuthorId == user.Id, updateBlockedAllowedUserId);
                    }
                }

                try
                {
                    var updateUserPostId = Builders <User> .Update.AddToSet(user => user.UserPostsId, textPost.PostId);

                    users.FindOneAndUpdate(user => user.Id == textPost.AuthorId, updateUserPostId);
                }
                catch (Exception)
                {
                    Console.WriteLine("User doesn't exist");
                    return;
                }

                try
                {
                    var updateUserPostId = Builders <User> .Update.AddToSet(user => user.UserPostsId, dataPost.PostId);

                    users.FindOneAndUpdate(user => user.Id == dataPost.AuthorId, updateUserPostId);
                }
                catch (Exception)
                {
                    Console.WriteLine("User doesn't exist");
                    return;
                }



                //Insert comments to post
                InsertCommentDummyData(database, textPost, dataPost);
            }

            #endregion
        }
        public void CreateTextPost(User user)
        {
            TextPost post = new TextPost();

            post.AuthorId   = user.Id;
            post.AuthorName = user.Name;

            Console.WriteLine($"\nHello {post.AuthorName}! You are making a textpost.");

            Console.WriteLine("Do you want your post to be public or not?\n");
            ConsoleKeyInfo key;

            do
            {
                Console.WriteLine("PRESS 'Y' for YES or 'N' for NO");
                key = Console.ReadKey(true);
                if (key.Key == ConsoleKey.Y)
                {
                    post.IsPublic = true;
                    Console.WriteLine("Post status: Public\n");
                }
                else if (key.Key == ConsoleKey.N)
                {
                    post.IsPublic = false;
                    Console.WriteLine("Post status: Private\n");
                }
            }while (key.Key != ConsoleKey.Y && key.Key != ConsoleKey.N);

            //Write text to post//
            Console.WriteLine("Write post, exit with 'Enter': ");
            post.Text = Console.ReadLine();
            Console.WriteLine();
            // ===================== //

            if (post.IsPublic == true)
            {
                foreach (var id in user.BlockId)
                {
                    post.BlockedAllowedUserId.Add(id);
                }

                Console.WriteLine("Public post added");
            }
            else
            {
                Console.WriteLine("Which circle(s) do you want to post to?\nHere is your list of circles: ");
                foreach (var id in user.CircleId)
                {
                    var c = _circles.Find <Circle>(c => c.CircleId == id).FirstOrDefault();
                    Console.WriteLine($"Circle id: {c.CircleId}, Cicle name: {c.Name}");
                }

                Console.WriteLine("\nWrite the id of the circles, you want to include, one at a time.");

                do
                {
                    Console.Write("Write id: ");
                    string circleIdToInclude = Console.ReadLine();

                    if (user.CircleId.Contains(circleIdToInclude))
                    {
                        var c = _circles.Find <Circle>(c => c.CircleId == circleIdToInclude).FirstOrDefault();
                        post.BlockedAllowedUserId = c.UserIds;
                    }
                    else
                    {
                        Console.WriteLine("Id does not exist");
                    }

                    do
                    {
                        Console.WriteLine("Pess 'A' to add another circle");
                        Console.WriteLine("Pess 'C' to Continue");

                        key = Console.ReadKey(true);
                    } while (key.Key != ConsoleKey.A && key.Key != ConsoleKey.C);
                } while (key.Key == ConsoleKey.A);

                Console.WriteLine("Private post added to circles");
            }

            user.UserPostsId.Add(post.PostId);
            _posts.InsertOne(post);
        }
Пример #25
0
        public async Task <IActionResult> Update([FromBody] TextPost textPost)
        {
            var updatedTextPost = await _service.Update(textPost);

            return(Ok(updatedTextPost));
        }
        public async Task <TextPost> Update(TextPost textPost)
        {
            var updatedTextPost = await _repository.Update(textPost);

            return(updatedTextPost);
        }
 private static void MapUpdatedValues(TextPost existingTextPost, TextPost updatedTextPost)
 {
     existingTextPost.Subject     = updatedTextPost.Subject;
     existingTextPost.Description = updatedTextPost.Description;
 }
        public async Task <TextPost> Create(TextPost textPost)
        {
            var newTextPost = await _repository.Create(textPost);

            return(newTextPost);
        }
Пример #29
0
        static void Main(string[] args)
        {
            var  service   = new SvendService();
            var  userList  = service.Get();
            bool isInThere = false;


            Console.WriteLine("Wellcome to the SvendDB console interface");
            Console.WriteLine("Your choice of commands are:" +
                              "\n\"1\" : Create user" +
                              "\n\"2\" : Have a user create a post" +
                              "\n\"3\" : Have a user create a comment to a post" +
                              "\n\"4\" : Have a user get another users wall" +
                              "\n\"5\" : Have a user get its feed");
            do
            {
                try
                {
                    Console.Write(" ");
                    var command = Console.ReadLine();
                    switch (command)
                    {
                    case "1":
                        Console.WriteLine("What is the users name?");
                        string name = Console.ReadLine();
                        Console.WriteLine("What is the users gender? Male, Female or Other?(M/F/O)");
                        char gender = Convert.ToChar(Console.ReadLine());
                        Console.WriteLine("What is the users age?");
                        int age = Convert.ToInt32(Console.ReadLine());

                        var userInTheMaking = new User()
                        {
                            Name   = name,
                            Gender = gender,
                            Age    = age
                        };

                        Console.WriteLine("how many follows this user?");
                        int forLoop = Convert.ToInt32(Console.ReadLine());

                        for (int i = 0; i < forLoop; i++)
                        {
                            Console.WriteLine("What is the name of a follower?");
                            var ToBeFollower = Console.ReadLine();
                            userList = service.Get();
                            userInTheMaking.Followers.Add(userList.Where(u => u.Name == ToBeFollower).FirstOrDefault().Id);
                            Console.WriteLine("Added!");
                        }

                        Console.WriteLine("how many have this user blocked?");
                        forLoop = Convert.ToInt32(Console.ReadLine());

                        for (int i = 0; i < forLoop; i++)
                        {
                            Console.WriteLine("What is the name of a blocked user?");
                            var ToBeFollower = Console.ReadLine();
                            userList = service.Get();
                            userInTheMaking.BlockedUsers.Add(userList.Where(u => u.Name == ToBeFollower).FirstOrDefault().Id);
                            Console.WriteLine("Added!");
                        }

                        Console.WriteLine("how many are in this users cirkles?");
                        forLoop = Convert.ToInt32(Console.ReadLine());

                        for (int i = 0; i < forLoop; i++)
                        {
                            Console.WriteLine("What is the name of a follower?");
                            var ToBeFollower = Console.ReadLine();
                            userList = service.Get();
                            userInTheMaking.UserCircle.Add(userList.Where(u => u.Name == ToBeFollower).FirstOrDefault().Id);
                            Console.WriteLine("Added!");
                        }

                        service.Create(userInTheMaking);
                        Console.WriteLine("Done!");
                        break;

                    case "2":
                        Console.WriteLine("What is the name of the user that is going to create a post?");
                        string postAuthor = Console.ReadLine();

                        User ToBePostAuthor = new User();
                        isInThere = false;
                        foreach (var user in service.Get())
                        {
                            if (user.Name == postAuthor)
                            {
                                ToBePostAuthor = user;
                                isInThere      = true;
                                break;
                            }
                        }

                        if (!isInThere)
                        {
                            Console.WriteLine("User does not exist!");
                            break;
                        }
                        isInThere = false;


                        bool notdone   = true;
                        bool isPrivate = false;
                        while (notdone)
                        {
                            Console.WriteLine("Is the post going to be public or private?");
                            string input = Console.ReadLine();
                            if (input == "public")
                            {
                                isPrivate = false;
                                notdone   = false;
                            }
                            else if (input == "private")
                            {
                                isPrivate = true;
                                notdone   = false;
                            }
                            else
                            {
                                Console.WriteLine("Try again");
                            }
                        }

                        notdone = true;
                        while (notdone)
                        {
                            Console.WriteLine("Is the post type text or picture?");
                            string input = Console.ReadLine();
                            if (input == "text")
                            {
                                Console.WriteLine("What is the text in the post?");
                                input = Console.ReadLine();

                                TextPost thePost = new TextPost()
                                {
                                    UserId       = ToBePostAuthor.Id,
                                    Author       = postAuthor,
                                    IsPublic     = !isPrivate,
                                    CreationDate = DateTime.Now,
                                    Text         = input
                                };
                                service.Create(ToBePostAuthor.Id, thePost);

                                notdone = false;
                            }
                            else if (input == "picture")
                            {
                                Console.WriteLine("What is the text in the post?");
                                string textInput = Console.ReadLine();
                                Console.WriteLine("What is the URL for the picture in the post?");
                                string      picInput = Console.ReadLine();
                                PicturePost thePost  = new PicturePost()
                                {
                                    UserId       = ToBePostAuthor.Id,
                                    Author       = postAuthor,
                                    IsPublic     = !isPrivate,
                                    CreationDate = DateTime.Now,
                                    Text         = input,
                                    ImageUrl     = picInput
                                };
                                service.Create(ToBePostAuthor.Id, thePost);
                                notdone = false;
                            }
                            else
                            {
                                Console.WriteLine("Try again");
                            }
                        }
                        Console.WriteLine("Done!");
                        break;

                    case "3":

                        Console.WriteLine("What is the name of the user that is going to create a comment?");
                        string commentAuthor = Console.ReadLine();

                        User ToBeCommentAuthor = new User();
                        isInThere = false;
                        foreach (var user in service.Get())
                        {
                            if (user.Name == commentAuthor)
                            {
                                ToBeCommentAuthor = user;
                                isInThere         = true;
                                break;
                            }
                        }

                        if (!isInThere)
                        {
                            Console.WriteLine("User does not exist!");
                            break;
                        }
                        isInThere = false;

                        Console.WriteLine("What is the author of the post that is going to have a comment?");
                        string postauthor = Console.ReadLine();

                        User ToBePostAuthorer = new User();
                        isInThere = false;
                        foreach (var user in service.Get())
                        {
                            if (user.Name == postauthor)
                            {
                                ToBePostAuthorer = user;
                                isInThere        = true;
                                break;
                            }
                        }

                        if (!isInThere)
                        {
                            Console.WriteLine("User does not exist!");
                            break;
                        }
                        isInThere = false;

                        Console.WriteLine("Is the post text or picture?");
                        string type = Console.ReadLine();

                        if (type == "text")
                        {
                            TextPost ourpost = new TextPost();
                            isInThere = false;
                            foreach (var post in service.GetPost())
                            {
                                if (post.Author == postauthor)
                                {
                                    ourpost   = (TextPost)post;
                                    isInThere = true;
                                    break;
                                }
                            }
                            if (!isInThere)
                            {
                                Console.WriteLine("Post does not exist!");
                                break;
                            }
                            isInThere = false;

                            Console.WriteLine("What is the comment text?");
                            string content = Console.ReadLine();

                            Comment ourComment = new Comment()
                            {
                                Text   = content,
                                PostId = ourpost.Id,
                                UserId = ToBePostAuthorer.Id
                            };

                            service.Create(ourpost.Id, ourComment);
                        }
                        else if (type == "picture")
                        {
                            PicturePost ourpost = new PicturePost();
                            isInThere = false;
                            foreach (var post in service.GetPost())
                            {
                                if (post.Author == postauthor)
                                {
                                    ourpost   = (PicturePost)post;
                                    isInThere = true;
                                    break;
                                }
                            }
                            if (!isInThere)
                            {
                                Console.WriteLine("Post does not exist!");
                                break;
                            }
                            isInThere = false;

                            Console.WriteLine("What is the comment text?");
                            string content = Console.ReadLine();

                            Comment ourComment = new Comment()
                            {
                                Text   = content,
                                PostId = ourpost.Id,
                                UserId = ToBePostAuthorer.Id
                            };

                            service.Create(ourpost.Id, ourComment);
                        }
                        Console.WriteLine("Done!");
                        break;

                    case "4":

                        Console.WriteLine("What is the user that is getting another users wall?");
                        string wallWanter = Console.ReadLine();

                        User ToBewallWanter = new User();
                        isInThere = false;
                        foreach (var user in service.Get())
                        {
                            if (user.Name == wallWanter)
                            {
                                ToBewallWanter = user;
                                isInThere      = true;
                                break;
                            }
                        }

                        if (!isInThere)
                        {
                            Console.WriteLine("User does not exist!");
                            break;
                        }
                        isInThere = false;

                        Console.WriteLine("What is the user whose wall we are going to get?");
                        string wallOwner = Console.ReadLine();

                        User ToBewallOwner = new User();
                        isInThere = false;
                        foreach (var user in service.Get())
                        {
                            if (user.Name == wallOwner)
                            {
                                ToBewallOwner = user;
                                isInThere     = true;
                                break;
                            }
                        }

                        if (!isInThere)
                        {
                            Console.WriteLine("User does not exist!");
                            break;
                        }
                        isInThere = false;

                        IEnumerable <Tuple <Post, IEnumerable <Comment> > > wall = service.GetWall(ToBewallOwner.Id, ToBewallWanter.Id);
                        foreach (var instance in wall)
                        {
                            Console.WriteLine("Post created at " + instance.Item1.CreationDate + " by " + instance.Item1.Author + " can be seen");
                            Console.WriteLine("With the comment(s):");
                            foreach (var comment in instance.Item2)
                            {
                                Console.WriteLine(comment.Text);
                            }
                        }

                        break;

                    case "5":

                        Console.WriteLine("What is the user whose feed we are going to see?");
                        string FeedOwner = Console.ReadLine();

                        User ToBeFeedOwner = new User();
                        isInThere = false;
                        foreach (var user in service.Get())
                        {
                            if (user.Name == FeedOwner)
                            {
                                ToBeFeedOwner = user;
                                isInThere     = true;
                                break;
                            }
                        }

                        if (!isInThere)
                        {
                            Console.WriteLine("User does not exist!");
                            break;
                        }
                        isInThere = false;

                        foreach (var post in ToBeFeedOwner.Feed)
                        {
                            Console.WriteLine("Post created at " + post.CreationDate + " by " + post.Author + " can be seen");
                        }

                        break;

                    default:
                        Console.WriteLine("Unknown command");
                        break;
                    }
                }

                catch (Exception e)
                {
                    Console.WriteLine("Invalid database request" +
                                      "\nWant to review exeption?" +
                                      "\ny/N");
                    string answer = Console.ReadLine();
                    if (answer == "y" || answer == "Y")
                    {
                        Console.WriteLine(e);
                    }
                    else if (answer == "n" || answer == "N" || answer == "")
                    {
                    }
                    else
                    {
                        Console.WriteLine("Invalid command, try again");
                    }
                }
            } while (true);
        }