public static async Task <OperationsResponse> AddFriend(int senderId, int recipientId, string message) { return(await Task.Run(async() => { try { using (DataEntity db = new DataEntity()) { bool checkIsExist = db.Friends.Count() != 0 && db.Friends.Any(f => f.SenderAccountId == recipientId && f.RecipientAccountId == senderId); if (!checkIsExist) { Friend newFriendRequest = new Friend { MessageText = message, RecipientAccountId = senderId, SenderAccountId = recipientId, Status = FriendRequestStatus.Ok }; db.Friends.Add(newFriendRequest); await db.SaveChangesAsync(); return OperationsResponse.Ok; } else { await SetNewStatus(recipientId, senderId, FriendRequestStatus.Ok); return OperationsResponse.Ok; } } } catch (Exception) { return OperationsResponse.ServerError; } })); }