public async Task Create_WithImagePostWithNewAndExistingTags_DoesNotDuplicateExistingTag()
        {
            int expectedExistingTagCount      = 1;
            IEnumerable <string> newTags      = new [] { "Fun", _existingTagContent };
            ImagePost            newImagePost = new ImagePost()
            {
                Tags = newTags.Select((t) => new ImagePostTag()
                {
                    Tag = new Tag()
                    {
                        Content = t
                    }
                }).ToList()
            };

            ImagePost createdImagePost = await _imagePostService.Create(newImagePost);

            int actualExistingTagCount = GetDbContext().Tags.Count(t => t.Content == _existingTagContent);

            Assert.AreEqual(expectedExistingTagCount, actualExistingTagCount);
        }
예제 #2
0
        public async Task <ImagePost> Create(ImagePost imagePost)
        {
            using (ShowNTellDbContext context = _contextFactory.CreateDbContext())
            {
                ICollection <ImagePostTag> mergedTags = null;

                if (imagePost.Tags != null && imagePost.Tags.Count > 0)
                {
                    mergedTags = await GetMergedNewAndExistingTagsFromContext(imagePost.Tags, context);

                    imagePost.Tags = ConvertImagePostTagsForSave(mergedTags);
                }

                context.ImagePosts.Add(imagePost);
                await context.SaveChangesAsync();

                imagePost.Tags = mergedTags;

                return(imagePost);
            }
        }
예제 #3
0
        private async void UploadButton_ClickedAsync(object sender, EventArgs e)
        {
            if (ChangeProfilePic && PhotoImage.Source != null)
            {
                AccountGiven.ProfilePicPath = selectedImagePath;
                await App.accountDatabase.SaveAccountAsync(AccountGiven);
                await DisplayAlert("Profile Picture Uploaded", "Your Profile Picture Has Been Uploaded.", "OK");
                await Navigation.PopAsync();
            }
            else if (PhotoImage.Source != null && TitleField.Text != "" && TitleField.Text != null)
            {
                var result = await this.DisplayAlert("Upload Image?", "Are You Sure You Want To Upload This Image?", "Confirm", "Cancel");
                if (result)
                {
                    var OurAccountDetails = AccountGiven;
                    ImagePost post = new ImagePost
                    {
                        AuthorId = OurAccountDetails.Id,
                        AuthorName = OurAccountDetails.Username,
                        AuthorProfilePicPath = OurAccountDetails.ProfilePicPath,
                        DateCreated = DateTime.Now.ToString(),
                        Title = TitleField.Text,
                        LikeCount = 0,
                        Path = selectedImagePath,
                    };
                    await App.ImageDatabase.SaveImagePostAsync(post);
                    await DisplayAlert("Post Created.", "Your Newly Createad Post Has Been Uploaded.", "OK");
                    await Navigation.PopAsync();

                }
                else
                {
                    return;
                }
            }
            else
            {
                await DisplayAlert("Can't Create Post.", "Make sure the post has a title and an image.", "OK");
            }
        }
        public async Task <string> CreateAsync(PostCreateInputModel input, string userId, string imagePath)
        {
            var post = new Post
            {
                Content = input.Content,
                UserId  = userId,
            };

            Directory.CreateDirectory($"{imagePath}/posts/");
            if (input.Images != null)
            {
                foreach (var image in input.Images)
                {
                    var extension = Path.GetExtension(image.FileName).TrimStart('.');
                    if (!this.allowedExtensions.Any(x => extension.EndsWith(x)))
                    {
                        throw new ArgumentException($"Invalid image extension {extension}");
                    }

                    var dbImage = new ImagePost
                    {
                        UserId    = userId,
                        Post      = post,
                        Extension = extension,
                    };
                    post.ImagePosts.Add(dbImage);
                    var physicalPath = $"{imagePath}/posts/{dbImage.Id}.{extension}";
                    using Stream fileStream = new FileStream(physicalPath, FileMode.Create);
                    await image.CopyToAsync(fileStream);
                }
            }

            await this.postsRepository.AddAsync(post);

            await this.postsRepository.SaveChangesAsync();

            return(post.Id);
        }
        public async Task Create_WithImagePostWithNewTags_SavesTagsInDatabase()
        {
            IEnumerable <string> expectedTags = new [] { "Fun", "Cool" };
            ImagePost            newImagePost = new ImagePost()
            {
                Tags = expectedTags.Select((t) => new ImagePostTag()
                {
                    Tag = new Tag()
                    {
                        Content = t
                    }
                }).ToList()
            };

            ImagePost createdImagePost = await _imagePostService.Create(newImagePost);

            IEnumerable <string> actualTags = GetDbContext().Tags.Select(t => t.Content);

            foreach (string expectedTag in expectedTags)
            {
                Assert.Contains(expectedTag, actualTags.ToList());
            }
        }
예제 #6
0
        public ActionResult Search(string searching)
        {
            List <PostDetail> ls = new List <PostDetail>();
            var list             = client.Search(searching);

            foreach (var item in list)
            {
                var postedUser             = client.GetTrallerById(item.UserId);
                List <ImagePost> listImage = new List <ImagePost>();
                var listImg = client.SearchImage(item.id);
                foreach (var img in listImg)
                {
                    var image = new ImagePost()
                    {
                        Id   = img.Id,
                        Name = img.Name,
                        Path = img.Path
                    };
                    listImage.Add(image);
                }
                var UserImage  = client.GetImageByUserId(item.UserId);
                var postDetail = new PostDetail()
                {
                    Content   = item.Content,
                    CreatedAt = item.CreatedAt,
                    id        = item.id,
                    Title     = item.Title,
                    firstName = postedUser.firstName,
                    lastName  = postedUser.LastName,
                    ImagePath = UserImage.Path,
                    ImageP    = listImage[0].Path
                };
                ls.Add(postDetail);
            }

            return(View(client.Search(searching)));
        }
예제 #7
0
 public OwnImagePostLikeException(ImagePost likedImagePost, string likerEmail)
 {
     LikedImagePost = likedImagePost;
     LikerEmail     = likerEmail;
 }
예제 #8
0
        private void LoadData()
        {
            var from = (IDictionary<string, object>)posts["from"];

            InlineUIContainer uiContainer = new InlineUIContainer();
            uiContainer.Child = new UserLinks((String)from["name"], -4);
            Story.Inlines.Add(uiContainer);

            string profilePictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", (String)from["id"], "square", _fb.AccessToken);
            UserPic.Source = new BitmapImage(new Uri(profilePictureUrl));
            
            String storytxt = "";
            String story_tag = "";
            dynamic selected_tagDic = null;
            String message = "";
            int message_tagsCount = 0;
            try
            {
                storytxt = (String)posts["story"];
            }
            catch (Exception e) { }

            try
            {
                if (((String)posts["type"]).Equals("link"))
                {
                    var application = (IDictionary<string, object>)posts["application"];
                    if (((String)application["namespace"]).Equals("likes"))
                    {
                        storytxt = " likes a link.";
                    }
                }
            }
            catch (Exception e) { }
            IDictionary<string, object> message_tagsDic = null;
            try
            {
                message_tagsDic = (IDictionary<string, object>)posts["message_tags"];
            }
            catch (Exception e) { }

            try
            {
                var story_tagsDic = (IDictionary<string, object>)posts["story_tags"];
                var story_tagsSecondEl = (IEnumerable<object>)story_tagsDic.ElementAt(1).Value;
                var selected_tag = story_tagsSecondEl.ElementAt(0);
                selected_tagDic = (IDictionary<string, object>)selected_tag;

                story_tag = (String)selected_tagDic["name"]; ;
            }
            catch (Exception e) { }

            try { message = (String)posts["message"]; }
            catch (Exception e) { }

            try
            {
                var message_tagsDicForCount = (IDictionary<string, object>)posts["message_tags"];
                message_tagsCount = message_tagsDicForCount.Count;
            }
            catch (Exception e) { }

            Run pText = new Run();
            //pText.Foreground = new SolidColorBrush(Color.FromArgb(255, 129,129,129));
            pText.Text = storytxt.Replace((String)from["name"], "");
            Story.Inlines.Add(pText);

            if (!story_tag.Equals(""))
            {
                String[] storyTextSplit = new String[] { storytxt.Substring(0, (int)selected_tagDic["offset"]), storytxt.Substring((int)selected_tagDic["offset"] + story_tag.Length) };
                
                pText.Text = storyTextSplit[0].Replace((String)from["name"], "");
                uiContainer = new InlineUIContainer();
                uiContainer.Child = new UserLinks(story_tag, false, -4);
                Story.Inlines.Add(uiContainer);
                pText = new Run();
                pText.Text = storyTextSplit.Last();
                Story.Inlines.Add(pText);
            }

            if (message_tagsDic == null)
            {
                Run r = new Run();
                r.Text = message;
                Message.Inlines.Add(r);
            }
            else
            {
                String[] modMessage = new String[]{message};
                Run r;
                int offset = 0;
                for (int i = 0; i < message_tagsDic.Count; i++)
                {
                    var message_tagEl = (IEnumerable<object>)message_tagsDic.ElementAt(i).Value;
                    dynamic message_selTag = message_tagEl.ElementAt(0);
                    message_selTag = (IDictionary<string, object>)message_selTag;
                    String message_tagName = (String)message_selTag["name"];

                    modMessage = new String[] { modMessage[0].Substring(0, (int)message_selTag["offset"]-offset), modMessage[0].Substring((int)message_selTag["offset"] - offset + message_tagName.Length) };
                    offset = message_tagName.Length + (int)message_selTag["offset"];

                    r = new Run();
                    r.Text = modMessage[0];
                    Message.Inlines.Add(r);

                    uiContainer = new InlineUIContainer();
                    uiContainer.Child = new UserLinks(message_tagName, false, -3);
                    Message.Inlines.Add(uiContainer);

                    modMessage = new String[] { modMessage[1] };
                }
                r = new Run();
                r.Text = modMessage[0];
                Message.Inlines.Add(r);
            }

            if (((String)posts["type"]).Equals("photo"))
            {
                ImagePost image = new ImagePost();

                string photoFormat = string.Format("https://graph.facebook.com/{0}/picture?access_token={1}", posts["object_id"], _fb.AccessToken);

                BitmapImage photo = new BitmapImage(new Uri(photoFormat));

                image.postImage.Source = photo;
                StatusArea.Children.Insert(StatusArea.Children.Count()-1, image);
            }

            statusControls = new StatusControls(posts, _fbSession);
            StatusControlSection.Children.Add(statusControls);
        }
예제 #9
0
        public async Task GetRandom_WithNoExistingImagePosts_ReturnsNull()
        {
            ImagePost actual = await _randomImagePostService.GetRandom();

            Assert.IsNull(actual);
        }
예제 #10
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();
        }
예제 #11
0
 public DuplicateLikeException(string message, ImagePost likedImagePost, string likerEmail) : base(message)
 {
     LikedImagePost = likedImagePost;
     LikerEmail     = likerEmail;
 }
예제 #12
0
        public ActionResult PostDetail(int id)
        {
            Session["PostId"] = id;
            IList <ImagePost> ls = new List <ImagePost>();
            var list             = client.SearchImage(id);

            foreach (var item in list)
            {
                var image = new ImagePost()
                {
                    Id   = item.Id,
                    Name = item.Name,
                    Path = item.Path
                };
                ls.Add(image);
            }
            ViewData["ImageList"] = ls;

            var posted = client.PostDetail(id);

            var postedUser = client.GetTrallerById(posted.UserId);

            var UserImage = client.GetImageByUserId(posted.UserId);

            var detailPosted = new PostDetail()
            {
                Content   = posted.Content,
                CreatedAt = posted.CreatedAt,
                id        = posted.id,
                Title     = posted.Title,
                firstName = postedUser.firstName,
                lastName  = postedUser.LastName,
                ImagePath = UserImage.Path
            };



            IList <CommentDetail> listCommentClient = new List <CommentDetail>();
            var listComment = client.GetCommentsbyPostId(id);

            foreach (var item in listComment)
            {
                int?UserId    = item.UserId;
                var User      = client.GetTrallerById(UserId);
                var ImageUser = client.GetImageByUserId(UserId);
                List <SubComment> subsList = new List <SubComment>();
                var subCommentlist         = client.GetSubCommentsbyCommentId(item.Id);
                foreach (var subComment in subCommentlist)
                {
                    var sub_Comment = new SubComment()
                    {
                        Id         = subComment.Id,
                        Subcomment = subComment.Subcomment,


                        CommentId = subComment.CommentId,
                        CreateAt  = subComment.CreateAt
                    };
                    subsList.Add(sub_Comment);
                }
                var comment = new CommentDetail()

                {
                    comment1    = item.comment1,
                    Mark        = item.Vote,
                    CreatAt     = item.CreatAt,
                    firstName   = User.firstName,
                    lastName    = User.LastName,
                    ImagePath   = ImageUser.Path,
                    SubComments = subsList
                };
                listCommentClient.Add(comment);
            }
            ViewBag.UserId          = posted.UserId;
            @ViewBag.postId         = posted.id;
            ViewData["CommentList"] = listCommentClient;
            return(View(detailPosted));
        }
        public List <IPost> GetPostWithId(int idPost)
        {
            var result = new List <IPost>();

            try
            {
                if (_client.Open())
                {
                    var command = new SqlCommand
                    {
                        Connection  = _client.GetConnection(),
                        CommandText = "getpostwithid",
                        CommandType = CommandType.StoredProcedure
                    };

                    var par1 = new SqlParameter("@idPost", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Input,
                        Value     = idPost
                    };

                    var par2 = new SqlParameter("@haserror", SqlDbType.Bit)
                    {
                        Direction = ParameterDirection.Output
                    };

                    command.Parameters.Add(par1);
                    command.Parameters.Add(par2);

                    var dataReader = command.ExecuteReader();
                    while (dataReader.Read())
                    {
                        var   pic = dataReader["imagen"].ToString();
                        IPost post;
                        if (pic == "")
                        {
                            post = new MessagePost
                            {
                                idPost    = Convert.ToInt32(dataReader["idPost"].ToString()),
                                idPersona = Convert.ToInt32(dataReader["idPersona"].ToString()),
                                mensaje   = dataReader["mensaje"].ToString(),
                                imagen    = pic,
                                likes     = Convert.ToInt32(dataReader["likes"].ToString()),
                            };
                        }
                        else
                        {
                            post = new ImagePost()
                            {
                                idPost    = Convert.ToInt32(dataReader["idPost"].ToString()),
                                idPersona = Convert.ToInt32(dataReader["idPersona"].ToString()),
                                mensaje   = dataReader["mensaje"].ToString(),
                                imagen    = pic,
                                likes     = Convert.ToInt32(dataReader["likes"].ToString()),
                            };
                        }
                        result.Add(post);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                //do something
            }
            finally
            {
                _client.Close();
            }
            return(result);
        }
예제 #14
0
 public PostDetails(ImagePost _ImagePostGiven, Account _AccountGiven)
 {
     InitializeComponent();
     AccountGiven   = _AccountGiven;
     ImagePostGiven = _ImagePostGiven;
 }
예제 #15
0
 public OwnImagePostLikeException(string message, Exception innerException, ImagePost likedImagePost, string likerEmail) : base(message, innerException)
 {
     LikedImagePost = likedImagePost;
     LikerEmail     = likerEmail;
 }
예제 #16
0
 public Task <int> DeleteImagePostAsync(ImagePost ImagePost)
 {
     return(_database.DeleteAsync(ImagePost));
 }
예제 #17
0
 public DuplicateLikeException(ImagePost likedImagePost, string likerEmail)
 {
     LikedImagePost = likedImagePost;
     LikerEmail     = likerEmail;
 }
예제 #18
0
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            var context = app.ApplicationServices.GetRequiredService <WhiteBoardContext>();

            context.Database.Migrate();

            if (DbIsEmpty(context))
            {
                var user1 = new User()
                {
                    FirstName = "Samwise",
                    LastName  = "Gamgee",
                    Alias     = "Sam",
                    Email     = "*****@*****.**",
                    Password  = "******",
                };

                var user2 = new User()
                {
                    FirstName = "Bertha",
                    LastName  = "Baggins",
                    Alias     = "Bertha",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                var quotePost1 = new QuotePost()
                {
                    UserId = 1,
                    //CreatedBy = user1,
                    Text  = "We have a business strategy around here -  it's called getting shit done",
                    Likes = 5,
                };

                var quotePost2 = new QuotePost()
                {
                    UserId = 2,
                    //CreatedBy = user2,
                    Text  = "If you can think it, you can build it",
                    Likes = 2
                };

                user1.QuotePosts.Add(quotePost1);
                user2.QuotePosts.Add(quotePost2);


                var imagePost = new ImagePost()
                {
                    UserId = 1,
                    Url    = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Everest_North_Face_toward_Base_Camp_Tibet_Luca_Galuzzi_2006.jpg/560px-Everest_North_Face_toward_Base_Camp_Tibet_Luca_Galuzzi_2006.jpg"
                };

                var videoPost = new VideoPost()
                {
                    UserId = 2,
                    Url    = "https://youtu.be/fFRVFHP4GLE"
                };

                user1.ImagePosts.Add(imagePost);

                user2.VideoPosts.Add(videoPost);

                var comment1 = new Comment()
                {
                    UserId = 1,
                    User   = user1,
                    PostId = 1,
                    Body   = "You are so right!"
                };

                imagePost.Comments.Add(comment1);

                var comment2 = new Comment()
                {
                    UserId = 2,
                    User   = user2,
                    PostId = 2,
                    Body   = "Lovely Video! So motivating :) "
                };

                videoPost.Comments.Add(comment2);

                Console.WriteLine("DB is being updated");

                var comment3 = new Comment()
                {
                    UserId = 2,
                    User   = user2,
                    PostId = 2,
                    Body   = "What a strategy!"
                };

                quotePost1.Comments.Add(comment3);

                context.Users.AddRange(
                    user1, user2
                    );
                context.Posts.AddRange(videoPost, imagePost, quotePost1, quotePost2);

                context.SaveChanges();
            }
        }
        public async Task GetById_WithNonExistingId_ReturnsNull()
        {
            ImagePost imagePost = await _imagePostService.GetById(_nonExistingId);

            Assert.IsNull(imagePost);
        }