コード例 #1
0
        public async Task <Dialog> GetDialogBetweenUsers(int[] users)
        {
            int dipper = users[0], mabel = users[1];

            VcksUser user1 = db.Users.Find(dipper);
            VcksUser user2 = db.Users.Find(mabel);

            if (user1 != null && user2 != null)
            {
                Dialog dialog = db.Dialogs.Include(x => x.Participants).Include(x => x.Messages).FirstOrDefault(d => d.Participants.Any(p => p.ProfileId == user1.Id) && d.Participants.Any(p => p.ProfileId == user2.Id));
                if (dialog == null)
                {
                    dialog = new Dialog()
                    {
                        Participants = new List <Participant>()
                        {
                            new Participant()
                            {
                                ProfileId = user1.Id
                            }, new Participant()
                            {
                                ProfileId = user2.Id
                            }
                        }
                    };
                    db.Dialogs.Add(dialog);
                    await db.SaveChangesAsync();
                }
                return(dialog);
            }
            return(null);
        }
コード例 #2
0
        public async Task Follow(int callerId, int userId)
        {
            var caller = db.Users.Include(x => x.Followers).Include(x => x.Friends).FirstOrDefault(u => u.Id == callerId);
            var user   = db.Users.Include(x => x.Followers).Include(x => x.Friends).FirstOrDefault(u => u.Id == userId);

            if (caller == null || user == null)
            {
                return;
            }

            if (caller.Friends.Any(f => f.ProfileId.Equals(user.Id)) || user.Friends.Any(f => f.ProfileId.Equals(caller.Id))) // They're already friends
            {
                return;
            }

            var r = caller.Followers.FirstOrDefault(f => f.ProfileId.Equals(user.Id));

            if (r != null) // MakeEmFriends
            {
                caller.Followers.Remove(r);
                caller.Friends.Add(new Friend()
                {
                    ProfileId = user.Id
                });
                user.Friends.Add(new Friend()
                {
                    ProfileId = caller.Id
                });
            }
            else // Subscribe
            {
                user.Followers.Add(new Follower()
                {
                    ProfileId = caller.Id
                });
            }

            await db.SaveChangesAsync();
        }
コード例 #3
0
ファイル: WallManager.cs プロジェクト: vcks/VcksCore
 public async Task Create(WallPost post)
 {
     db.WallPosts.Add(post);
     await db.SaveChangesAsync();
 }
コード例 #4
0
ファイル: ProfileManager.cs プロジェクト: vcks/VcksCore
 public async Task Create(VcksUserProfile profile)
 {
     db.UserProfiles.Add(profile);
     await db.SaveChangesAsync();
 }
コード例 #5
0
 public async Task Create(File file)
 {
     db.Files.Add(file);
     await db.SaveChangesAsync();
 }