public void AddPrivateMessage([FromBody] PrivateMessage privateMessage, [FromUri] int chatId) { var chat = chatRepository.GetById(chatId); var messagesInChat = chat.Messages; privateMessageRepository.Add(privateMessage); privateMessageRepository.SaveChanges(privateMessage); messagesInChat.Add(privateMessage); dataContext.SaveChanges(); }