final
This commit is contained in:
@@ -11,11 +11,13 @@ namespace LittleShop.Areas.Admin.Controllers;
|
||||
public class MessagesController : Controller
|
||||
{
|
||||
private readonly ICustomerMessageService _messageService;
|
||||
private readonly ICustomerService _customerService;
|
||||
private readonly ILogger<MessagesController> _logger;
|
||||
|
||||
public MessagesController(ICustomerMessageService messageService, ILogger<MessagesController> logger)
|
||||
public MessagesController(ICustomerMessageService messageService, ICustomerService customerService, ILogger<MessagesController> logger)
|
||||
{
|
||||
_messageService = messageService;
|
||||
_customerService = customerService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -28,9 +30,42 @@ public class MessagesController : Controller
|
||||
public async Task<IActionResult> Customer(Guid id)
|
||||
{
|
||||
var conversation = await _messageService.GetMessageThreadAsync(id);
|
||||
|
||||
// If no conversation exists yet, create an empty one for this customer
|
||||
if (conversation == null)
|
||||
{
|
||||
return NotFound();
|
||||
// Check if customer exists
|
||||
var customerExists = await _messageService.ValidateCustomerExistsAsync(id);
|
||||
if (!customerExists)
|
||||
{
|
||||
TempData["Error"] = "Customer not found.";
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
// Get customer information
|
||||
var customer = await _customerService.GetCustomerByIdAsync(id);
|
||||
if (customer == null)
|
||||
{
|
||||
TempData["Error"] = "Customer information not available.";
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
// Create empty conversation structure for new conversation
|
||||
conversation = new MessageThreadDto
|
||||
{
|
||||
ThreadId = id,
|
||||
Subject = customer.DisplayName,
|
||||
CustomerId = id,
|
||||
CustomerName = customer.DisplayName,
|
||||
OrderId = null,
|
||||
OrderReference = null,
|
||||
StartedAt = DateTime.UtcNow,
|
||||
LastMessageAt = DateTime.UtcNow,
|
||||
MessageCount = 0,
|
||||
HasUnreadMessages = false,
|
||||
RequiresResponse = false,
|
||||
Messages = new List<CustomerMessageDto>()
|
||||
};
|
||||
}
|
||||
|
||||
return View(conversation);
|
||||
|
||||
Reference in New Issue
Block a user