Пример #1
0
        public static Guid SubmitNewTweet(Guid AuthorKey, Guid wallOwnerReferenceKey, string text)
        {
            using (var db = new FHNWPrototypeDB())
            {
                Guid newGuid = Guid.NewGuid();
                var wall = db.ContentStreams
                    .Include("Owner")
                    .FirstOrDefault(x => x.Owner.ReferenceKey == wallOwnerReferenceKey);
                var author = db.BasicProfiles.FirstOrDefault(x => x.ReferenceKey == AuthorKey);

                Tweet newTweet = new Tweet();
                newTweet.Author = author;
                newTweet.Key = newGuid;
                newTweet.PublishDateTime = DateTime.Now;
                newTweet.Text = text;
                newTweet.Wall = wall;

                db.Tweets.Add(newTweet);

                var hashtag = text.Substring(0,text.IndexOf(" "));
                var tag = db.Tags.FirstOrDefault(x=>x.Name==hashtag);
                var suscriptions = db.Suscriptions.Where(x=>x.ReferencePoint==tag.Key).ToList();

                //suscribe the author to receive notifications from this post, from now on
                //Suscription thisSuscription = new Suscription { Key = Guid.NewGuid(), Type = SuscriptionType.TweetOnTagIBelong, Suscriber = author, ReferencePoint = newGuid };

                //db.Suscriptions.Add(thisSuscription);

                //register the event of liking the post
                if (AuthorKey != wallOwnerReferenceKey)
                {
                    Event thisEvent = new Event { Key = Guid.NewGuid(), PostOrComment = newGuid, Type = EventType.LikedMyPost, TriggeredBy = author, TriggeredOn = DateTime.Now };

                    db.Events.Add(thisEvent);

                    Notification notification = new Notification { Key = Guid.NewGuid(), Event = thisEvent, NotifiedTo = wall.Owner };

                    db.Notifications.Add(notification);
                }

                db.SaveChanges();
                return newGuid;
            }
        }
Пример #2
0
        public static Guid SubmitNewComment(Guid AuthorKey, Guid postKey, string text)
        {
            using (var db = new FHNWPrototypeDB())
            {
                Guid  newGuid = Guid.NewGuid();
                var post = db.Posts
                    .Include("Author")
                    .Include("Wall.Owner")
                    .FirstOrDefault(x => x.Key == postKey);
                // var author = db.UserAccounts.Single(x => x.Key == AuthorKey);
                var author = db.BasicProfiles.FirstOrDefault(x => x.ReferenceKey == AuthorKey);

                Comment newComment = new Comment();
                newComment.Author = author;
                newComment.Key = newGuid;
                newComment.PublishDateTime = DateTime.Now;
                newComment.Text = text;
                newComment.Post = post;

                db.Comments.Add(newComment);

                Suscription thisSuscription = null;
                Suscription thisSuscription2 = null;
                Event thisEvent = null;
                Event thisEvent2 = null;
                Notification notification = null;

                //suscribe the author to receive notifications from this post, from now on
                if (AuthorKey != post.Wall.Owner.ReferenceKey)
                {
                    thisSuscription = new Suscription { Key = Guid.NewGuid(), Type = SuscriptionType.MyComment , Suscriber = author, ReferencePoint = newGuid };
                    thisSuscription2 = new Suscription { Key = Guid.NewGuid(), Type = SuscriptionType.CommentOnPostOnMyWall, Suscriber = post.Wall.Owner, ReferencePoint = newGuid };

                    db.Suscriptions.Add(thisSuscription);
                    db.Suscriptions.Add(thisSuscription2);

                    //register the event of liking the post

                    thisEvent = new Event { Key = Guid.NewGuid(), PostOrComment = newGuid, Type = EventType.NewCommentOnPostOnMyWall , TriggeredBy = author, TriggeredOn = DateTime.Now };
                    thisEvent2 = new Event { Key = Guid.NewGuid(), PostOrComment = newGuid, Type = EventType.NewCommentOnPostILiked,  TriggeredBy = author, TriggeredOn = DateTime.Now };

                    db.Events.Add(thisEvent);
                    db.Events.Add(thisEvent2);

                    //dont notify if its yourself

                    notification = new Notification { Key = Guid.NewGuid(), Event = thisEvent, NotifiedTo = post.Wall.Owner };
                    db.Notifications.Add(notification);

                    var suscriptions = db.Suscriptions.Where(x => x.ReferencePoint == post.Key && x.Type == SuscriptionType.PostILiked).ToList();

                    foreach (Suscription suscription in suscriptions)
                    {
                        db.Notifications.Add(new Notification { Key=Guid.NewGuid(), Event=thisEvent2 , NotifiedTo = suscription.Suscriber   });
                    }

                }

                db.SaveChanges();
                return newGuid;
            }
        }
Пример #3
0
        public static Guid SubmitNewPost(Guid AuthorKey, Guid wallOwnerReferenceKey, string text)
        {
            using (var db = new FHNWPrototypeDB())
            {
                Guid newGuid = Guid.NewGuid();
                var wall = db.ContentStreams
                    .Include("Owner")
                    .FirstOrDefault(x => x.Owner.ReferenceKey == wallOwnerReferenceKey);
                var author = db.BasicProfiles.FirstOrDefault(x => x.ReferenceKey == AuthorKey);

                Post newPost = new Post();
                newPost.Author = author;
                newPost.Key = newGuid;
                newPost.PublishDateTime = DateTime.Now;
                newPost.Text = text;
                newPost.Wall = wall;

                db.Posts.Add(newPost);

                Suscription thisSuscription = null;
                Suscription thisSuscription2 = null;
                Event thisEvent = null;
                Notification notification = null;

                //suscribe the author to receive notifications from this post, from now on
                if (AuthorKey != wallOwnerReferenceKey)
                {
                    thisSuscription = new Suscription { Key = Guid.NewGuid(), Type = SuscriptionType.MyPost  , Suscriber = author, ReferencePoint = newGuid };
                    thisSuscription2 = new Suscription { Key = Guid.NewGuid(), Type = SuscriptionType.PostOnMyWall , Suscriber = wall.Owner, ReferencePoint = newGuid };

                    db.Suscriptions.Add(thisSuscription);
                    db.Suscriptions.Add(thisSuscription2);

                    //register the event of liking the post

                    thisEvent = new Event { Key = Guid.NewGuid(), PostOrComment = newGuid, Type = EventType.NewPostOnMyWall , TriggeredBy = author, TriggeredOn = DateTime.Now };

                    db.Events.Add(thisEvent);

                    //dont notify if its yourself

                    notification = new Notification { Key = Guid.NewGuid(), Event = thisEvent, NotifiedTo = wall.Owner };

                    db.Notifications.Add(notification);
                }

                db.SaveChanges();
                return newGuid;
            }
        }
Пример #4
0
        public static int LikePost(Guid AuthorKey, Guid postKey)
        {
            using (var db = new FHNWPrototypeDB())
            {
                var thisPost = db.Posts
                    .Include("PostLikes")
                    .Include("Author")
                    .Single(x => x.Key == postKey);
                var author = db.BasicProfiles.FirstOrDefault(x => x.ReferenceKey == AuthorKey);
                PostLike newLike = new PostLike();
                Guid newGuid = Guid.NewGuid();
                newLike.Key = newGuid;
                newLike.Author = author;
                newLike.DateTime = DateTime.Now;
                newLike.Value = LikeValue.Positive;
                newLike.Post = thisPost;
                db.PostLikes.Add(newLike);

                Suscription thisSuscription = null;
                Event thisEvent = null;
                Notification notification = null;

                //suscribe the author to receive notifications from this post, from now on
                if (AuthorKey != author.ReferenceKey)
                {
                     thisSuscription = new Suscription { Key = Guid.NewGuid(), Type = SuscriptionType.PostILiked, Suscriber = author, ReferencePoint = newGuid };

                    db.Suscriptions.Add(thisSuscription);

                //register the event of liking the post

                     thisEvent = new Event { Key = Guid.NewGuid(), PostOrComment = newGuid, Type = EventType.LikedMyPost, TriggeredBy = author, TriggeredOn = DateTime.Now };

                    db.Events.Add(thisEvent);

                //dont notify if its yourself

                    notification = new Notification { Key = Guid.NewGuid(), Event = thisEvent, NotifiedTo = thisPost.Author };

                    db.Notifications.Add(notification);
                }

                db.SaveChanges();
                return thisPost.PostLikes.Count;
            }
        }