public void Delete(int profileId, int friendId) { if (_profileService.AreFriends(profileId, friendId)) { var result = _profileService.RemoveFriend(profileId, friendId); if (result) { Response.StatusCode = 500; return; } Response.StatusCode = 200; return; } Response.StatusCode = 204; }
public bool SendMessage(int friendId, MessageDTO msg) { if (msg == null) { throw new ArgumentException("Message is null"); } if (string.IsNullOrWhiteSpace(msg.Message)) { throw new ArgumentException("Message is empty"); } var conv = _convRepository.GetConversationBetween(msg.ProfileId, friendId); if (conv == null) { if (!_profileService.ProfileExists(friendId) || !_profileService.AreFriends(msg.ProfileId, friendId)) { throw new ArgumentException("Cannot send message to this person"); } conv = new Conversation { Member1Id = msg.ProfileId, Member2Id = friendId, Messages = new List <Message>() }; conv = _convRepository.AddConversaion(conv); if (conv == null) { return(false); } } Message message = new Message { ProfileId = msg.ProfileId, Body = msg.Message, Date = DateTime.UtcNow, ConversationId = conv.Id, }; var dbMessage = _convRepository.AddMessage(message); _notificationService.SendMessageNotification(friendId, dbMessage.Id); return(true); }