/// <summary> /// Accept a specific friend request /// </summary> /// <param name="id">The specific friend Id</param> public async Task <User> AcceptAddFriendRequestAsync(string requestId) { var request = await RemoveFriendRequestByIdAsync(requestId); var user = request?.ToUserId == CurrentUser.Id ? request.FromUser:null; if (user == null) { return(null); } var chat = new Chat() { CreatedByUser = CurrentUser, ChatType = ChatType.Personal }; var uc = new List <UsersChats>() { new UsersChats { Chat = chat, User = CurrentUser, Rools = UserChatRools.Admin }, new UsersChats { Chat = chat, User = user, Rools = UserChatRools.Admin } }; chat.UsersChats = uc; (await Chats.AddAsync(chat)).State = EntityState.Added; await UsersChats.AddRangeAsync(uc); var friends = new Friends() { FromUser = user, ToUser = CurrentUser, Chat = chat }; (await Friends.AddAsync(friends)).State = EntityState.Added; await Db.SaveChangesAsync(); return(user); }