Пример #1
0
        public static void DeleteComment(Guid commentKey)
        {
            using (var db = new FHNWPrototypeDB())
            {
                db.Configuration.LazyLoadingEnabled = false;
                var comment = db.Comments
                    .Include("CommentLikes")
                    .SingleOrDefault(x => x.Key == commentKey);

                List<CommentLike> commentLikesToDelete = new List<CommentLike>();

                foreach (CommentLike like in comment.CommentLikes)
                {
                    commentLikesToDelete.Add(like);
                }

                foreach (var item in commentLikesToDelete)
                {
                    db.CommentLikes.Remove(item);
                }

                db.Comments.Remove(comment);
                db.SaveChanges();
            }
        }
Пример #2
0
 public static void Remove(User entity)
 {
     using (var db = new FHNWPrototypeDB())
     {
         db.Users.Remove(entity);
         db.SaveChanges();
     }
 }
        public static OrganizationAccount FindBy(Guid key)
        {
            OrganizationAccount organizationAccountFound = new OrganizationAccount();
              //  ContentStream contentStreamFound = null;
            using (var db = new FHNWPrototypeDB())
            {
               var result = (from organizationAccount in db.OrganizationAccounts
                                                 .Include("Organization")
                                                 //.Include("PartnershipsRequested.Sender.Organization")
                                                 //.Include("PartnershipsRequested.Receiver.Organization")
                                                 //.Include("PartnershipsReceived.Sender.Organization")
                                                 //.Include("PartnershipsReceived.Receiver.Organization")
                                                 //.Include("AllianceMemberships.AllianceRequested")
                                                 //.Include("Employees.OrganizationAccount.Organization")
                                                 //.Include("Employees.User")
                                                 //.Include("Location")
                                                 //.Include("Wall.Posts.Author")
                                                 //.Include("Wall.Posts.Comments.Author")
                                            where organizationAccount.Key == key
                                            select organizationAccount).FirstOrDefault();

                //contentStreamFound = (from cs in db.ContentStreams
                //                               .Include("Posts.Author")
                //                                .Include("Posts.Comments.Author")
                //                      where cs.Owner.ReferenceKey == organizationAccountFound.Key
                //                      select cs).FirstOrDefault();

                //if (organizationAccountFound != null)
                //{
                //    if (contentStreamFound != null)
                //    {
                //        organizationAccountFound.Wall = contentStreamFound;
                //    }
                //    else
                //    {
                //        ContentStream emptyWall = new ContentStream();
                //        emptyWall.Posts = new List<Post>();
                //        organizationAccountFound.Wall = emptyWall;
                //    }
                //}
                //else
                //{
                //    return null;
                //}
                organizationAccountFound.Key = result.Key;
                organizationAccountFound.Name = result.Name;
                organizationAccountFound.Organization = result.Organization;
                organizationAccountFound.Description = result.Description;
                organizationAccountFound.Location = result.Location;
                organizationAccountFound.PartnershipsReceived = new List<PartnershipStateInfo>();
                organizationAccountFound.PartnershipsRequested = new List<PartnershipStateInfo>();
                organizationAccountFound.AllianceMemberships = new List<AllianceMembershipStateInfo>();
                organizationAccountFound.Wall = new ContentStream();
                organizationAccountFound.Wall.Posts = new List<Post>();
                return organizationAccountFound;
            }
        }
Пример #4
0
 public static Byte[] GetProfilePictureByUserKey(Guid key)
 {
     Byte[] foundPicture = null;
     using (var db = new FHNWPrototypeDB())
     {
         foundPicture = db.Users.FirstOrDefault(x => x.Key == key).ProfilePicture;
         return foundPicture;
     }
 }
Пример #5
0
 public static User FindBy(Guid key)
 {
     User foundUser = null;
     using (var db = new FHNWPrototypeDB())
     {
         foundUser = db.Users.Single(x => x.Key == key);
         return foundUser;
     }
 }
Пример #6
0
        public static byte[] GetHeaderPictureByOrganizationKey(Guid key)
        {
            byte[] result = null;
            using (var db = new FHNWPrototypeDB())
            {
                result = db.Organizations.SingleOrDefault(x => x.Key == key).HeaderPicture;

                return result;
            }
        }
Пример #7
0
 public static IEnumerable<User> FindAll()
 {
     IEnumerable<User> result = null;
     using (var db = new FHNWPrototypeDB())
     {
         result = from user in db.Users
                      select user;
         return result;
     }
 }
Пример #8
0
        public static IEnumerable<Organization> FindAll()
        {
            IEnumerable<Organization> result = null;
            using (var db = new FHNWPrototypeDB())
            {
                result = from organizations in db.Organizations
                         select organizations;

                return result;
            }
        }
Пример #9
0
 public static IEnumerable<UserAccount> GetAllAccountsByUserKey(Guid key)
 {
     IEnumerable<UserAccount> results = null;
     using (var db = new FHNWPrototypeDB())
     {
         results = from userAccounts in db.UserAccounts
                   where userAccounts.User.Key == key
                   select userAccounts;
         return results;
     }
 }
Пример #10
0
 public static IEnumerable<Alliance> FindAll()
 {
     IEnumerable<Alliance> results = null;
     using (var db = new FHNWPrototypeDB())
     {
         results = from alliances in db.Alliances
                                     .Include("AllianceMemberships.AllianceRequested")
                                     .Include("AllianceMemberships.OrganizationRequestor")
                       select alliances;
         return results;
     }
 }
        //public static Boolean isPotentiallyRelatedWithThisViewerAsOrganization(string userAccountEmail)
        //{
        //    return true;
        //}
        public static IEnumerable<OrganizationAccount> FindAll()
        {
            IEnumerable<OrganizationAccount> result = null;

            using (var db = new FHNWPrototypeDB())
            {
                result = from organizationAccount in db.OrganizationAccounts
                         select organizationAccount;

                return result.ToList();
            }
        }
Пример #12
0
 public static IEnumerable<Group> FindAll()
 {
     IEnumerable<Group> results = null;
     using (var db = new FHNWPrototypeDB())
     {
         results = from g in db.Groups
                                 .Include("GroupMemberships.RequestedGroup")
                                 .Include("GroupMemberships.RequestorAccount.User")
                       select g;
         return results;
     }
 }
Пример #13
0
        public static Organization FindBy(Guid key)
        {
            Organization result = null;
            using (var db = new FHNWPrototypeDB())
            {
                result = (from organization in db.Organizations
                                                    .Include("Location")
                          where organization.Key == key
                          select organization).FirstOrDefault();

                return result;
            }
        }
Пример #14
0
        public static Alliance FindBy(Guid key)
        {
            Alliance allianceFound = new Alliance();
               // ContentStream contentStreamFound = null;
            using (var db = new FHNWPrototypeDB())
            {
                                            //                .Include("Wall.Posts.Author.User")
                                            //.Include("Wall.Posts.Comments.Author.User")
                var result = (from alliance in db.Alliances
                                            //.Include("AllianceMemberships.AllianceRequested")
                                            .Include("AllianceMemberships.OrganizationRequestor")
                                            //.Include("Wall.Posts.Author")
                                            //.Include("Wall.Posts.Comments.Author")
                                     where alliance.Key == key
                                     select alliance).FirstOrDefault();

                //contentStreamFound = (from cs in db.ContentStreams
                //                                                .Include("Posts.Author")
                //                                                .Include("Posts.PostLikes")
                //                                                .Include("Posts.Comments.Author")
                //                                                .Include("Posts.Comments.CommentLikes")
                //                                                where cs.Owner.ReferenceKey == allianceFound.Key
                //                                                select cs).FirstOrDefault();

                //if (contentStreamFound != null)
                //{
                //    var newPostList = contentStreamFound.Posts.OrderByDescending(x => x.PublishDateTime).ToList();
                //    foreach (var post in newPostList)
                //    {
                //        var newCommentList = post.Comments.OrderBy(x => x.PublishDateTime).ToList();
                //        post.Comments = newCommentList;
                //    }
                //    contentStreamFound.Posts = newPostList;
                //}
                //else
                //{
                //    contentStreamFound = new ContentStream();
                //    contentStreamFound.Posts = new List<Post>();
                //}

               // allianceFound.Wall = contentStreamFound;

                allianceFound.Key = result.Key;
                allianceFound.Name = result.Name;
                allianceFound.Description = result.Description;

                allianceFound.AllianceMemberships = result.AllianceMemberships;

                return allianceFound;
            }
        }
Пример #15
0
        public static void DeletePost(Guid  postKey)
        {
            using (var db = new FHNWPrototypeDB())
            {
              //  db.Configuration.LazyLoadingEnabled = false;
                var post = db.Posts
                    .Include("Author")
                    .Include("PostLikes.Author")
                    .Include("Comments.CommentLikes")
                    .Include("Wall")
                    .SingleOrDefault(x => x.Key == postKey);

                List<CommentLike> commentLikesToDelete = new List<CommentLike>();
                List<Comment> commentsToDelete = new List<Comment>();
                List<PostLike> postLikesToDelete = new List<PostLike>();

                foreach (Comment comment in post.Comments)
                {
                    foreach (CommentLike like in comment.CommentLikes)
                    {
                        commentLikesToDelete.Add(like);
                    }
                    commentsToDelete.Add(comment);
                }
                foreach (PostLike like in post.PostLikes)
                {
                    postLikesToDelete.Add(like);
                }

                foreach (var item in commentLikesToDelete)
                {
                    db.CommentLikes.Remove(item);
                }

                foreach (var item in commentsToDelete)
                {
                    db.Comments.Remove(item);
                }

                foreach (var item in postLikesToDelete)
                {
                    db.PostLikes.Remove(item);
                }

                db.Posts.Remove(post);

                db.SaveChanges();
            }
        }
Пример #16
0
        public static Group FindBy(Guid key)
        {
            Group groupFound = new Group() ;
            //ContentStream contentStreamFound = new ContentStream();
            //contentStreamFound.Posts = new List<Post>();

            using (var db = new FHNWPrototypeDB())
            {
                var result = (from g in db.Groups
                                        //.Include("GroupMemberships.RequestedGroup")
                                        .Include("GroupMemberships.RequestorAccount.User")
                                        //.Include("Wall.Posts.Author")
                                        //.Include("Wall.Posts.Comments.Author")
                              where g.Key == key
                              select g).FirstOrDefault();
                //contentStreamFound = (from cs in db.ContentStreams
                //                                    .Include("Posts.Author")
                //                                    .Include("Posts.PostLikes")
                //                                    .Include("Posts.Comments.Author")
                //                                    .Include("Posts.Comments.CommentLikes")
                //                      where cs.Owner.ReferenceKey  == groupFound.Key
                //                      select cs).FirstOrDefault();

                //if (contentStreamFound != null)
                //{
                //    var newPostList = contentStreamFound.Posts.OrderByDescending(x => x.PublishDateTime).ToList();
                //    foreach (var post in newPostList)
                //    {
                //        var newCommentList = post.Comments.OrderBy(x => x.PublishDateTime).ToList();
                //        post.Comments = newCommentList;
                //    }
                //    contentStreamFound.Posts = newPostList;
                //}
                //else
                //{
                //    contentStreamFound = new ContentStream();
                //    contentStreamFound.Posts = new List<Post>();
                //}
                //groupFound.Wall = contentStreamFound;
                groupFound.Key = result.Key;
                groupFound.Name = result.Name;
                groupFound.Description = result.Description;
                groupFound.GroupMemberships = result.GroupMemberships;
                return groupFound;
            }
        }
Пример #17
0
        public static SystemAuthenticationToken AttemptAuthentication(string email, string password)
        {
            if (UserAlreadyExists(email))
            {
                SystemAccount result = null;
                using (var db = new FHNWPrototypeDB())
                {
                    result = db.SystemAccounts
                                            .Include("Holder")
                                            .Single(x => x.Email == email);

                    if (result.Password == password)
                    {

                        SystemAuthenticationToken token = new SystemAuthenticationToken();
                        token.IsAuthenticated = true;
                        CompleteProfile completeProfile = new CompleteProfile();
                        completeProfile.BasicProfile = result.Holder;

                        switch(result.Holder.ReferenceType)
                        {
                            case AccountType.UserAccount :
                                  var ua = db.UserAccounts
                                                        .Include("User")
                                                        .Include("OrganizationAccount.Organization")
                                                        .SingleOrDefault(x => x.Key == result.Holder.ReferenceKey);
                                  completeProfile.FullName = ua.User.FirstName + " " + ua.User.LastName;
                                  completeProfile.Description1 = ua.OrganizationAccount.Name;
                                  completeProfile.Description2 = ua.OrganizationAccount.Organization.Name;
                                break;
                            case AccountType.OrganizationAccount:
                                var oa = db.OrganizationAccounts
                                               .Include("Organization")
                                               .SingleOrDefault(x => x.Key == result.Holder.ReferenceKey);
                                completeProfile.FullName = oa.Name;
                                completeProfile.Description1 = oa.Description;
                                  completeProfile.Description2 = oa.Organization.Name;
                                break;

                        }

                        token.MyProfile = completeProfile;
                        token.Email = email;
                        token.LastSuccesfulLogin = DateTime.Now;
                        //register the new check
                        //result.LastCheck = DateTime.Now;
                        //db.SaveChanges();
                        return token;
                    }
                    else
                    {
                        SystemAuthenticationToken token = new SystemAuthenticationToken() { Email = email, IsAuthenticated = false };
                        return token;
                    }

                }
            }
            else
            {
                SystemAuthenticationToken token = new SystemAuthenticationToken() { Email = email, IsAuthenticated = false };
                return token;
            }
        }
Пример #18
0
        //private FHNWPrototypeDB db = null;
        //public SecurityRepository()
        //{
        //    //db = new FHNWPrototypeDB();
        //}
        public static CompleteProfile GetCompleteProfileFromUserEmail(string userEmail)
        {
            CompleteProfile result = new CompleteProfile();
            result.BasicProfile = new BasicProfile();

            using (var db = new FHNWPrototypeDB())
            {
                BasicProfile  profile = db.SystemAccounts.Include("Holder").FirstOrDefault(x => x.Email == userEmail).Holder;

                if (profile.ReferenceType == AccountType.UserAccount)
                {
                    var ua = db.UserAccounts
                                            .Include("User")
                                            .Include("OrganizationAccount.Organization")
                                            .FirstOrDefault(x => x.Key == profile.ReferenceKey);
                    result.BasicProfile.ReferenceKey = ua.Key;
                    result.BasicProfile.ReferenceType = AccountType.UserAccount;
                    result.FullName = ua.User.FirstName + " " + ua.User.LastName;
                    result.Description1 = ua.OrganizationAccount.Name;
                    result.Description2 = ua.OrganizationAccount.Organization.Name;
                }
                if (profile.ReferenceType == AccountType.OrganizationAccount)
                {
                    var oa = db.OrganizationAccounts
                                                    .Include("Organization")
                                                    .FirstOrDefault(x => x.Key == profile.ReferenceKey);
                    result.BasicProfile.ReferenceKey = oa.Key;
                    result.BasicProfile.ReferenceType = AccountType.OrganizationAccount;
                    result.FullName = oa.Name;
                    result.Description1 = oa.Description;
                    result.Description2 = oa.Organization.Name;
                }

                return result;

            }
        }
Пример #19
0
 public static void RegisterLastCheck(BasicProfile profile)
 {
     using (var db = new FHNWPrototypeDB())
     {
         var account = db.SystemAccounts.FirstOrDefault(x => x.Holder.ReferenceKey == profile.ReferenceKey);
         account.LastCheck = DateTime.Now;
         db.SaveChanges();
     }
 }
Пример #20
0
 public static IEnumerable<AllianceMembershipStateInfo> GetAllAllianceMembershipsByAllianceKey(Guid key)
 {
     IEnumerable<AllianceMembershipStateInfo> results = null;
     using (var db = new FHNWPrototypeDB())
     {
         results = from membership in db.AllianceMemberships
                                         .Include("AllianceRequested")
                                         .Include("OrganizationRequestor")
                       where membership.AllianceRequested.Key == key
                       select membership;
         return results;
     }
 }
Пример #21
0
 public static byte[] GetProfilePictureByAllianceKey(Guid key)
 {
     byte[] results = null;
     using (var db = new FHNWPrototypeDB())
     {
         results = db.Alliances.FirstOrDefault(x => x.Key == key).ProfilePicture;
         return results;
     }
 }
Пример #22
0
 public static void DeleteRetweet(Guid  retweetKey)
 {
     using (var db = new FHNWPrototypeDB())
     {
         db.Configuration.LazyLoadingEnabled = false;
         var retweet = db.Retweets
             .SingleOrDefault(x => x.Key == retweetKey );
         retweet.Tweet = null;
         db.Retweets.Remove(retweet);
         db.SaveChanges();
     }
 }
Пример #23
0
        public static int UnLikePost(Guid AuthorUserAccountKey, Guid postKey)
        {
            using (var db = new FHNWPrototypeDB())
            {
                var thisPost = db.Posts.FirstOrDefault(x => x.Key == postKey);
                var author = db.UserAccounts.FirstOrDefault(x => x.Key == AuthorUserAccountKey);
                var unlike = db.PostLikes.FirstOrDefault(x => x.Post.Key == postKey && x.Author.ReferenceKey == AuthorUserAccountKey);
                db.PostLikes.Remove(unlike);

                db.SaveChanges();

                return thisPost.PostLikes.Count;
            }
        }
Пример #24
0
        public static int UnLikeComment(Guid AuthorKey, Guid commentKey)
        {
            using (var db = new FHNWPrototypeDB())
            {
                var thisComment = db.Comments.FirstOrDefault(x => x.Key == commentKey);
                //var author = db.BasicProfiles.SingleOrDefault(x => x.ReferenceKey  == AuthorKey);
                var unlike = db.CommentLikes.FirstOrDefault(x => x.Comment.Key == commentKey && x.Author.ReferenceKey == AuthorKey);
                db.CommentLikes.Remove(unlike);
                db.SaveChanges();

                return thisComment.CommentLikes.Count;
            }
        }
Пример #25
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;
            }
        }
Пример #26
0
 public static bool UserAlreadyExists(string email)
 {
     Boolean result=false ;
     using (var db = new FHNWPrototypeDB())
     {
         if (db.SystemAccounts.Count(x => x.Email == email) > 0)
         {
             result = true;
         }
         return result;
     }
 }
Пример #27
0
        public static void RegisterNewSystemAccount(string email, string password, bool isCorporateAccount)
        {
            if (!UserAlreadyExists(email))
            {
                SystemAccount newAccount = new SystemAccount();
                newAccount.Email = email;
                newAccount.Password = password;
                //newAccount.Key = Guid.NewGuid();
               // newAccount.IsConfirmed = true;
                Guid newRecordGuid = Guid.NewGuid();
                if (isCorporateAccount)
                {
                    BasicProfile basicProfile = new BasicProfile() { ReferenceKey = newRecordGuid, ReferenceType = AccountType.OrganizationAccount };
                  //  CompleteProfile completeProfile = new CompleteProfile { BasicProfile=basicProfile  };
                    OrganizationAccount newOrganizationAccount = new OrganizationAccount() { Key=newRecordGuid, Name="OrganizationAccount" };
                    newAccount.Holder = basicProfile ;
                    using (var db = new FHNWPrototypeDB())
                    {
                        db.BasicProfiles.Add(basicProfile);
                        db.SystemAccounts.Add(newAccount);
                        db.OrganizationAccounts.Add(newOrganizationAccount);

                        db.SaveChanges();
                    }
                }
                else
                {
                    BasicProfile basicProfile = new BasicProfile() { ReferenceKey = newRecordGuid, ReferenceType = AccountType.UserAccount  };
                   // CompleteProfile completeProfile = new CompleteProfile { BasicProfile=basicProfile  };
                    UserAccount newUserAccount = new UserAccount() { Key=newRecordGuid };
                    newAccount.Holder = basicProfile ;
                    using (var db = new FHNWPrototypeDB())
                    {
                        db.BasicProfiles.Add(basicProfile);
                        db.SystemAccounts.Add(newAccount);
                        db.UserAccounts.Add(newUserAccount);

                        db.SaveChanges();
                    }
                }
               // newAccount.IsCorporateAccount = isCorporateAccount;
               // newAccount.CreationDateTime = DateTime.Now;

            }
        }
Пример #28
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;
            }
        }
Пример #29
0
        public static CompleteProfile GetCompleteProfile(BasicProfile profile)
        {
            CompleteProfile  result = new CompleteProfile();
            BasicProfile basicProfile = new BasicProfile();
            result.BasicProfile=basicProfile;
            using (var db = new FHNWPrototypeDB())
            {
                if (profile.ReferenceType == AccountType.UserAccount)
                {
                    var ua = db.UserAccounts
                                            .Include("User")
                                            .Include("OrganizationAccount.Organization")
                                            .FirstOrDefault(x => x.Key == profile.ReferenceKey);
                    result.BasicProfile.ReferenceKey = ua.Key;
                    result.BasicProfile.ReferenceType = AccountType.UserAccount;
                    result.FullName = ua.User.FirstName + " " + ua.User.LastName;
                    result.Description1 = ua.OrganizationAccount.Name;
                    result.Description2 = ua.OrganizationAccount.Organization.Name;
                }
                if (profile.ReferenceType == AccountType.OrganizationAccount)
                {
                    var oa = db.OrganizationAccounts
                                                    .Include("Organization")
                                                    .FirstOrDefault(x => x.Key == profile.ReferenceKey);
                    result.BasicProfile.ReferenceKey = oa.Key;
                    result.BasicProfile.ReferenceType = AccountType.OrganizationAccount;
                    result.FullName = oa.Name;
                    result.Description1 = oa.Description;
                    result.Description2 = oa.Organization.Name;
                }
                if (profile.ReferenceType == AccountType.Group )
                {
                    var g = db.Groups.FirstOrDefault(x => x.Key == profile.ReferenceKey);
                    result.BasicProfile.ReferenceKey = g.Key;
                    result.BasicProfile.ReferenceType = AccountType.Group;
                    result.FullName = g.Name;
                    result.Description1 = g.Description;
                    result.Description2 = g.Description;
                }
                if (profile.ReferenceType == AccountType.Alliance )
                {
                    var al = db.Groups.FirstOrDefault(x => x.Key == profile.ReferenceKey);
                    result.BasicProfile.ReferenceKey = al.Key;
                    result.BasicProfile.ReferenceType = AccountType.Alliance;
                    result.FullName = al.Name;
                    result.Description1 = al.Description;
                    result.Description2 = al.Description;
                }

            }
            return result;
        }
Пример #30
0
        public static Guid SubmitNewRetweet(Guid AuthorKey, Guid tweetKey)
        {
            using (var db = new FHNWPrototypeDB())
            {
                Guid newGuid = Guid.NewGuid();

                var wall = db.ContentStreams.FirstOrDefault(x => x.Owner.ReferenceKey == AuthorKey);

                var tweet = db.Tweets.FirstOrDefault(x => x.Key == tweetKey);
                // var author = db.UserAccounts.Single(x => x.Key == AuthorKey);
                var author = db.BasicProfiles.FirstOrDefault(x => x.ReferenceKey == AuthorKey);

                Retweet newRetweet = new Retweet();
                newRetweet.Author = author;
                newRetweet.Key = newGuid;
                newRetweet.PublishDateTime = DateTime.Now;
                newRetweet.Tweet = tweet;
                newRetweet.Wall = wall;

                db.Retweets.Add(newRetweet);
                db.SaveChanges();
                return newGuid;
            }
        }