✨ Delete chat room will delete others related resources as well
This commit is contained in:
@@ -428,8 +428,29 @@ public class ChatRoomController(
|
|||||||
ResourceId = chatRoomResourceId
|
ResourceId = chatRoomResourceId
|
||||||
});
|
});
|
||||||
|
|
||||||
db.ChatRooms.Remove(chatRoom);
|
await using var transaction = await db.Database.BeginTransactionAsync();
|
||||||
await db.SaveChangesAsync();
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var now = SystemClock.Instance.GetCurrentInstant();
|
||||||
|
await db.ChatMessages
|
||||||
|
.Where(m => m.ChatRoomId == id)
|
||||||
|
.ExecuteUpdateAsync(s => s.SetProperty(s => s.DeletedAt, now));
|
||||||
|
await db.ChatMembers
|
||||||
|
.Where(m => m.ChatRoomId == id)
|
||||||
|
.ExecuteUpdateAsync(s => s.SetProperty(s => s.DeletedAt, now));
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
db.ChatRooms.Remove(chatRoom);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
await transaction.CommitAsync();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
await transaction.RollbackAsync();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
_ = als.CreateActionLogAsync(new CreateActionLogRequest
|
_ = als.CreateActionLogAsync(new CreateActionLogRequest
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user