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); }
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(); }
public async Task Create(WallPost post) { db.WallPosts.Add(post); await db.SaveChangesAsync(); }
public async Task Create(VcksUserProfile profile) { db.UserProfiles.Add(profile); await db.SaveChangesAsync(); }
public async Task Create(File file) { db.Files.Add(file); await db.SaveChangesAsync(); }