public async Task <IActionResult> EditChat([FromBody] ChatEditDetails details, CancellationToken ct = default) { if (!ModelState.IsValid) { return(BadRequest("Invalid chat details")); } if (!AuthenticationUtilities.IsAllowedChat(User)) { return(BadRequest("User has been banned from Chat")); } return(Ok(await _chatService.EditChatAsync(details, ct))); }
public async Task <Chat> EditChatAsync(ChatEditDetails newChat, CancellationToken ct = default) { Chat chat = await _context.Chats.AsNoTracking().FirstOrDefaultAsync(c => c.ChatUUID == newChat.ChatUUID, cancellationToken: ct); if (chat == null) { return(null); } chat.ChatName = newChat.ChatName; chat.ChatIsProtected = newChat.ChatIsProtected; chat.ChatIsDeleted = newChat.ChatIsDeleted; chat.ChatIsPublic = newChat.ChatIsPublic; _context.Update(chat); await _context.SaveChangesAsync(ct); return(await GetChatByIdAsync(newChat.ChatUUID, ct)); }