Fixed ui bugs. Implemented ticket deletion when a user is going to be deleted
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using Moonlight.App.Database.Entities;
|
using Moonlight.App.Database.Entities;
|
||||||
using Moonlight.App.Database.Entities.Community;
|
using Moonlight.App.Database.Entities.Community;
|
||||||
using Moonlight.App.Database.Entities.Store;
|
using Moonlight.App.Database.Entities.Store;
|
||||||
|
using Moonlight.App.Database.Entities.Tickets;
|
||||||
using Moonlight.App.Repositories;
|
using Moonlight.App.Repositories;
|
||||||
using Moonlight.App.Services.Community;
|
using Moonlight.App.Services.Community;
|
||||||
using Moonlight.App.Services.ServiceManage;
|
using Moonlight.App.Services.ServiceManage;
|
||||||
@@ -16,6 +17,8 @@ public class UserDeleteService
|
|||||||
private readonly Repository<Transaction> TransactionRepository;
|
private readonly Repository<Transaction> TransactionRepository;
|
||||||
private readonly Repository<CouponUse> CouponUseRepository;
|
private readonly Repository<CouponUse> CouponUseRepository;
|
||||||
private readonly Repository<GiftCodeUse> GiftCodeUseRepository;
|
private readonly Repository<GiftCodeUse> GiftCodeUseRepository;
|
||||||
|
private readonly Repository<Ticket> TicketRepository;
|
||||||
|
private readonly Repository<TicketMessage> TicketMessageRepository;
|
||||||
private readonly ServiceService ServiceService;
|
private readonly ServiceService ServiceService;
|
||||||
private readonly PostService PostService;
|
private readonly PostService PostService;
|
||||||
|
|
||||||
@@ -27,7 +30,9 @@ public class UserDeleteService
|
|||||||
Repository<User> userRepository,
|
Repository<User> userRepository,
|
||||||
Repository<GiftCodeUse> giftCodeUseRepository,
|
Repository<GiftCodeUse> giftCodeUseRepository,
|
||||||
Repository<CouponUse> couponUseRepository,
|
Repository<CouponUse> couponUseRepository,
|
||||||
Repository<Transaction> transactionRepository)
|
Repository<Transaction> transactionRepository,
|
||||||
|
Repository<Ticket> ticketRepository,
|
||||||
|
Repository<TicketMessage> ticketMessageRepository)
|
||||||
{
|
{
|
||||||
ServiceRepository = serviceRepository;
|
ServiceRepository = serviceRepository;
|
||||||
ServiceService = serviceService;
|
ServiceService = serviceService;
|
||||||
@@ -37,6 +42,8 @@ public class UserDeleteService
|
|||||||
GiftCodeUseRepository = giftCodeUseRepository;
|
GiftCodeUseRepository = giftCodeUseRepository;
|
||||||
CouponUseRepository = couponUseRepository;
|
CouponUseRepository = couponUseRepository;
|
||||||
TransactionRepository = transactionRepository;
|
TransactionRepository = transactionRepository;
|
||||||
|
TicketRepository = ticketRepository;
|
||||||
|
TicketMessageRepository = ticketMessageRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Perform(User user)
|
public async Task Perform(User user)
|
||||||
@@ -103,6 +110,42 @@ public class UserDeleteService
|
|||||||
foreach (var transaction in transactions)
|
foreach (var transaction in transactions)
|
||||||
TransactionRepository.Delete(transaction);
|
TransactionRepository.Delete(transaction);
|
||||||
|
|
||||||
|
// Tickets and ticket messages
|
||||||
|
|
||||||
|
// First we need to fetch every message this user has sent and delete it as admin accounts can have messages
|
||||||
|
// in tickets they dont own
|
||||||
|
var messagesFromUser = TicketMessageRepository
|
||||||
|
.Get()
|
||||||
|
.Where(x => x.Sender.Id == user.Id)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
foreach (var message in messagesFromUser)
|
||||||
|
{
|
||||||
|
TicketMessageRepository.Delete(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we can only delete the tickets the user actually owns
|
||||||
|
var tickets = TicketRepository
|
||||||
|
.Get()
|
||||||
|
.Include(x => x.Messages)
|
||||||
|
.Where(x => x.Creator.Id == user.Id)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
foreach (var ticket in tickets)
|
||||||
|
{
|
||||||
|
var messages = ticket.Messages.ToArray(); // Cache message models
|
||||||
|
|
||||||
|
ticket.Messages.Clear();
|
||||||
|
TicketRepository.Update(ticket);
|
||||||
|
|
||||||
|
foreach (var ticketMessage in messages)
|
||||||
|
{
|
||||||
|
TicketMessageRepository.Delete(ticketMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
TicketRepository.Delete(ticket);
|
||||||
|
}
|
||||||
|
|
||||||
// User
|
// User
|
||||||
|
|
||||||
// We need to use this in order to entity framework not crashing because of the previous deleted data
|
// We need to use this in order to entity framework not crashing because of the previous deleted data
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<div class="separator separator-content">@(message.Content)</div>
|
<div class="separator separator-content my-15">@(message.Content)</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -100,7 +100,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
<th>
|
||||||
<span>Status</span>
|
<span>Open</span>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
|
|||||||
Reference in New Issue
Block a user