public async Task AddFriend(string authenticationToken, string friendId) { try { FriendService friendService = new FriendService(); var response = await friendService.AddFriend(authenticationToken, friendId); if (!response.IsSuccessStatusCode) { if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { throw new Exception("Unauthorized"); } else { throw new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Show(User user) { Console.Write("Введите почтовый адрес пользователя: "); string email = Console.ReadLine(); User friend; try { friend = userService.FindByEmail(email); } catch (UserNotFoundException) { AlertMessage.Show("Пользователь не найден!"); return; } if (friendService.FriendExists(user.Id, friend.Id)) { AlertMessage.Show("Пользователь уже добавлен в друзья"); return; } friendService.AddFriend(user, friend); Console.WriteLine("Пользователь добавлен в друзья"); }
public async void AddFriend_ForProperGuids_ShouldAddNewFriendShips() { var service = new FriendService(_dataContext); var currentUserGuid = Guid.Parse("852cd5f9-083e-464e-86e1-f2631eb88573"); var newFriendId = Guid.Parse("475d30dc-6e0f-4369-bf15-37f4f8873215"); await service.AddFriend(currentUserGuid, newFriendId); _dataContext.Friendships.FirstOrDefault(x => x.CurrentUserId == currentUserGuid && x.FriendId == newFriendId).Should().NotBeNull(); _dataContext.Friendships.FirstOrDefault(x => x.CurrentUserId == newFriendId && x.FriendId == currentUserGuid).Should().NotBeNull(); }
public ActionResult AjouterAmi(string id, string username) { if (!id.IsNullOrWhiteSpace() && !username.IsNullOrWhiteSpace()) { var user = User as PrincessPrincipal; if (user != null) { var fs = new FriendService(user.Token); fs.AddFriend(id, username); } } return(RedirectToAction("Index", "Home")); }
public async Task SendMessageToServer(System.ServiceModel.Channels.Message msg) { if (msg.IsEmpty) { Console.WriteLine("received empty message"); return; } byte[] body = msg.GetBody <byte[]>(); string clientMessage = Encoding.UTF8.GetString(body); JObject jsonMessage = JObject.Parse(clientMessage); string type = jsonMessage["type"].ToString(); JToken data = jsonMessage["data"]; switch (type) { case Message: await chatService.SendMessage(data); break; case FriendshipRequest: await friendService.AddFriend(data); break; case FriendshipAccept: await friendService.ReplyToFriendRequest(data); break; case Login: IWebsocketCallback webCallback = OperationContext.Current.GetCallbackChannel <IWebsocketCallback>(); await loginService.Subscribe(data, webCallback); break; default: Console.WriteLine(String.Format("{0} type is not supported", type)); break; } }