Repository navigation
Expand file tree
/
Copy pathCustomerNoteController.cs
More file actions
66 lines (58 loc) · 2.68 KB
/
Copy pathCustomerNoteController.cs
File metadata and controls
66 lines (58 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using Grand.Business.Core.Interfaces.Customers;
using Grand.Domain.Customers;
using Grand.Domain.Permissions;
using Grand.Web.Admin.Extensions;
using Grand.Web.AdminShared.Controllers;
using Grand.Web.AdminShared.Interfaces;
using Grand.Web.Common.DataSource;
using Grand.Web.Common.Filters;
using Grand.Web.Common.Localization;
using Grand.Web.Common.Security.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Grand.Web.Admin.Controllers;
/// <summary>The customer's notes tab; the store panel has no notes tab, so this controller is Admin-only.</summary>
[AuthorizeAdmin]
[Area(Constants.AreaAdmin)]
[AuthorizeMenu]
public class CustomerNoteController(
ICustomerService customerService,
ICustomerNoteViewModelService customerNoteViewModelService,
IRequestTranslationService translationService,
IAdminDataScope<Customer> scope)
: BaseCustomerScopedController(customerService, scope)
{
[PermissionAuthorizeAction(PermissionActionName.Preview)]
[HttpPost]
public async Task<IActionResult> CustomerNotesSelect(string customerId, DataSourceRequest command)
{
var (_, denied) = await LoadAuthorizedCustomer(customerId);
if (denied != null) throw new ArgumentException("No customer found with the specified id");
var customerNoteModels = await customerNoteViewModelService.PrepareCustomerNoteList(customerId);
var gridModel = new DataSourceResult { Data = customerNoteModels, Total = customerNoteModels.Count };
return Json(gridModel);
}
[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
public async Task<IActionResult> CustomerNoteAdd(string customerId, string downloadId, bool displayToCustomer,
string title, string message)
{
var (_, denied) = await LoadAuthorizedCustomer(customerId);
if (denied != null) return Json(new { Result = false });
if (!await customerNoteViewModelService.InsertCustomerNote(customerId, downloadId, displayToCustomer, title,
message))
return Json(new {
Result = false,
Message = translationService.GetResource("Admin.Customers.Customers.CustomerNotes.DownloadNotOfCustomer")
});
return Json(new { Result = true });
}
[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
public async Task<IActionResult> CustomerNoteDelete(string id, string customerId)
{
var (_, denied) = await LoadAuthorizedCustomer(customerId);
if (denied != null) throw new ArgumentException("No customer found with the specified id");
await customerNoteViewModelService.DeleteCustomerNote(id, customerId);
return new JsonResult("");
}
}