Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Admin panel - fix and improvements in document features

KrzysztofPajak39baf253739c
diff --git a/src/Business/Grand.Business.Marketing/Interfaces/Documents/IDocumentService.cs b/src/Business/Grand.Business.Marketing/Interfaces/Documents/IDocumentService.cs
index 6ee0dd156..145503599 100644
--- a/src/Business/Grand.Business.Marketing/Interfaces/Documents/IDocumentService.cs
+++ b/src/Business/Grand.Business.Marketing/Interfaces/Documents/IDocumentService.cs
@@ -18,7 +18,7 @@ namespace Grand.Business.Marketing.Interfaces.Documents
/// Gets all documents
/// </summary>
/// <returns>Documents</returns>
- Task<IPagedList<Document>> GetAll(string customerId = "", string name = "", string number = "", string email = "", string username = "",
+ Task<IPagedList<Document>> GetAll(string name = "", string number = "", string email = "", string username = "",
Reference reference = Reference.None, string objectId = "", string seId = "", int status = -1, int pageIndex = 0, int pageSize = int.MaxValue);
/// <summary>
diff --git a/src/Business/Grand.Business.Marketing/Services/Documents/DocumentService.cs b/src/Business/Grand.Business.Marketing/Services/Documents/DocumentService.cs
index 23428aec7..6ed779b29 100644
--- a/src/Business/Grand.Business.Marketing/Services/Documents/DocumentService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Documents/DocumentService.cs
@@ -33,15 +33,12 @@ namespace Grand.Business.Marketing.Services.Documents
await _mediator.EntityDeleted(document);
}
- public virtual async Task<IPagedList<Document>> GetAll(string customerId = "", string name = "", string number = "", string email = "", string username = "",
+ public virtual async Task<IPagedList<Document>> GetAll(string name = "", string number = "", string email = "", string username = "",
Reference reference = Reference.None, string objectId = "", string seId = "", int status = -1, int pageIndex = 0, int pageSize = int.MaxValue)
{
var query = from d in _documentRepository.Table
select d;
- if (!string.IsNullOrEmpty(customerId))
- query = query.Where(d => d.CustomerId == customerId);
-
if (!string.IsNullOrWhiteSpace(name))
query = query.Where(m => m.Name != null && m.Name.ToLower().Contains(name.ToLower()));
@@ -49,7 +46,7 @@ namespace Grand.Business.Marketing.Services.Documents
query = query.Where(m => m.Number != null && m.Number.ToLower().Contains(number.ToLower()));
if (!string.IsNullOrWhiteSpace(email))
- query = query.Where(m => m.CustomerEmail != null && m.CustomerEmail.ToLower().Contains(email.ToLower()));
+ query = query.Where(m => m.CustomerEmail == email.ToLower());
if (!string.IsNullOrWhiteSpace(username))
query = query.Where(m => m.Username == username);
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Brand/_CreateOrUpdate.TabDocuments.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Brand/_CreateOrUpdate.TabDocuments.cshtml
index 5eabfeb13..c4e7f2c16 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Brand/_CreateOrUpdate.TabDocuments.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Brand/_CreateOrUpdate.TabDocuments.cshtml
@@ -20,7 +20,7 @@
dataSource: {
transport: {
read: {
- url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Brand, ObjectId = Model.Id, area = Constants.AreaAdmin }))",
+ url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Brand, ObjectId = Model.Id, StatusId = -1, area = Constants.AreaAdmin }))",
type: "POST",
dataType: "json",
data: addAntiForgeryToken
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Category/_CreateOrUpdate.TabDocuments.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Category/_CreateOrUpdate.TabDocuments.cshtml
index 8fc9e622c..1128667d6 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Category/_CreateOrUpdate.TabDocuments.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Category/_CreateOrUpdate.TabDocuments.cshtml
@@ -20,7 +20,7 @@
dataSource: {
transport: {
read: {
- url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Category, ObjectId = Model.Id, area = Constants.AreaAdmin }))",
+ url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Category, ObjectId = Model.Id, StatusId = -1, area = Constants.AreaAdmin }))",
type: "POST",
dataType: "json",
data: addAntiForgeryToken
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Collection/_CreateOrUpdate.TabDocuments.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Collection/_CreateOrUpdate.TabDocuments.cshtml
index 9861b42ce..3939a19ff 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Collection/_CreateOrUpdate.TabDocuments.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Collection/_CreateOrUpdate.TabDocuments.cshtml
@@ -20,7 +20,7 @@
dataSource: {
transport: {
read: {
- url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Collection, ObjectId = Model.Id, area = Constants.AreaAdmin }))",
+ url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Collection, ObjectId = Model.Id, StatusId = -1, area = Constants.AreaAdmin }))",
type: "POST",
dataType: "json",
data: addAntiForgeryToken
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/_CreateOrUpdate.Documents.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/_CreateOrUpdate.Documents.cshtml
index 5c411cbf9..e26767bde 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/_CreateOrUpdate.Documents.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/_CreateOrUpdate.Documents.cshtml
@@ -17,7 +17,7 @@ $(document).ready(function () {
dataSource: {
transport: {
read: {
- url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { customerId = Model.Id, area = Constants.AreaAdmin }))",
+ url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { customerId = Model.Id, StatusId = -1, area = Constants.AreaAdmin }))",
type: "POST",
dataType: "json",
data: addAntiForgeryToken
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Document/List.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Document/List.cshtml
index 40e3a1d24..0d3fe20ac 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Document/List.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Document/List.cshtml
@@ -1,9 +1,11 @@
@model DocumentListModel
@inject AdminAreaSettings adminAreaSettings
-
+@inject Grand.Business.Common.Interfaces.Localization.ITranslationService translationService
@{
//page title
ViewBag.Title = Loc["Admin.Documents.Document.Manage"];
+ var selectedList = DocumentStatus.Open.ToSelectList(Context, false).ToList();
+ selectedList.Insert(0, new SelectListItem { Text = translationService.GetResource("Admin.Common.All"), Value = "-1", Selected = true });
}
<div class="row">
@@ -61,7 +63,7 @@
<div class="form-group">
<admin-label asp-for="StatusId" class="col-sm-3 control-label" />
<div class="col-md-9 col-sm-9">
- <admin-select asp-for="StatusId" asp-items="((DocumentStatus)Model.StatusId).ToSelectList(Context)" />
+ @Html.DropDownList("StatusId", selectedList, new { @class = "form-control" })
</div>
</div>
</div>
@@ -77,6 +79,8 @@
</div>
<script>
$(document).ready(function () {
+ $('#StatusId').val("-1");
+
$("#documents-grid").kendoGrid({
dataSource: {
transport: {
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/MerchandiseReturn/_CreateOrUpdate.TabDocuments.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/MerchandiseReturn/_CreateOrUpdate.TabDocuments.cshtml
index 0dc588e74..3c426ff49 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/MerchandiseReturn/_CreateOrUpdate.TabDocuments.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/MerchandiseReturn/_CreateOrUpdate.TabDocuments.cshtml
@@ -17,7 +17,7 @@ $(document).ready(function () {
dataSource: {
transport: {
read: {
- url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.MerchandiseReturn, ObjectId = Model.Id, area = Constants.AreaAdmin }))",
+ url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.MerchandiseReturn, ObjectId = Model.Id, StatusId = -1, area = Constants.AreaAdmin }))",
type: "POST",
dataType: "json",
data: addAntiForgeryToken
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/_OrderDetails.Documents.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/_OrderDetails.Documents.cshtml
index 58f93a4c1..eba8f38a6 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/_OrderDetails.Documents.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/_OrderDetails.Documents.cshtml
@@ -17,7 +17,7 @@ $(document).ready(function () {
dataSource: {
transport: {
read: {
- url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Order, ObjectId = Model.Id, area = Constants.AreaAdmin }))",
+ url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Order, ObjectId = Model.Id, StatusId = -1, area = Constants.AreaAdmin }))",
type: "POST",
dataType: "json",
data: addAntiForgeryToken
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/_CreateOrUpdate.Documents.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/_CreateOrUpdate.Documents.cshtml
index 82d88bc63..e268c9196 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/_CreateOrUpdate.Documents.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/_CreateOrUpdate.Documents.cshtml
@@ -17,7 +17,7 @@ $(document).ready(function () {
dataSource: {
transport: {
read: {
- url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Product, ObjectId = Model.Id, area = Constants.AreaAdmin }))",
+ url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Product, ObjectId = Model.Id, StatusId = -1, area = Constants.AreaAdmin }))",
type: "POST",
dataType: "json",
data: addAntiForgeryToken
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/_Documents.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/_Documents.cshtml
index e89a2af77..821bbfd6b 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/_Documents.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/_Documents.cshtml
@@ -17,7 +17,7 @@ $(document).ready(function () {
dataSource: {
transport: {
read: {
- url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Shipment, ObjectId = Model.Id, area = Constants.AreaAdmin }))",
+ url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Shipment, ObjectId = Model.Id, StatusId = -1, area = Constants.AreaAdmin }))",
type: "POST",
dataType: "json",
data: addAntiForgeryToken
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Vendor/_CreateOrUpdate.TabDocuments.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Vendor/_CreateOrUpdate.TabDocuments.cshtml
index 60da194c4..ac2701934 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Vendor/_CreateOrUpdate.TabDocuments.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Vendor/_CreateOrUpdate.TabDocuments.cshtml
@@ -20,7 +20,7 @@
dataSource: {
transport: {
read: {
- url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Vendor, ObjectId = Model.Id, area = Constants.AreaAdmin }))",
+ url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Vendor, ObjectId = Model.Id, StatusId = -1, area = Constants.AreaAdmin }))",
type: "POST",
dataType: "json",
data: addAntiForgeryToken
diff --git a/src/Web/Grand.Web.Admin/Services/DocumentViewModelService.cs b/src/Web/Grand.Web.Admin/Services/DocumentViewModelService.cs
index 8c0c0ebd8..d6f38c9e7 100644
--- a/src/Web/Grand.Web.Admin/Services/DocumentViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/DocumentViewModelService.cs
@@ -80,7 +80,7 @@ namespace Grand.Web.Admin.Services
public virtual async Task<(IEnumerable<DocumentModel> documetListModel, int totalCount)> PrepareDocumentListModel(DocumentListModel model, int pageIndex, int pageSize)
{
- var documents = await _documentService.GetAll(customerId: "", name: model.SearchName, number: model.SearchNumber,
+ var documents = await _documentService.GetAll(name: model.SearchName, number: model.SearchNumber,
email: model.SearchEmail, reference: (Reference)model.Reference, objectId: model.ObjectId, status: model.StatusId, pageIndex: pageIndex - 1, pageSize: pageSize);
var documentListModel = new List<DocumentModel>();
@@ -223,8 +223,10 @@ namespace Grand.Web.Admin.Services
public virtual async Task<Document> InsertDocument(DocumentModel model)
{
- if (string.IsNullOrEmpty(model.CustomerId))
+ if (!string.IsNullOrEmpty(model.CustomerEmail))
model.CustomerId = (await _customerService.GetCustomerByEmail(model.CustomerEmail))?.Id;
+ else
+ model.CustomerId = string.Empty;
var document = model.ToEntity();
document.CreatedOnUtc = DateTime.UtcNow;
@@ -242,8 +244,13 @@ namespace Grand.Web.Admin.Services
{
var prevAttachmentId = document.DownloadId;
- if (string.IsNullOrEmpty(model.CustomerId))
+ if (!string.IsNullOrEmpty(model.CustomerEmail))
+ {
+ model.CustomerEmail = model.CustomerEmail.ToLowerInvariant();
model.CustomerId = (await _customerService.GetCustomerByEmail(model.CustomerEmail))?.Id;
+ }
+ else
+ model.CustomerId = string.Empty;
document = model.ToEntity(document);
document.UpdatedOnUtc = DateTime.UtcNow;
diff --git a/src/Web/Grand.Web/Features/Handlers/Customers/GetDocumentsHandler.cs b/src/Web/Grand.Web/Features/Handlers/Customers/GetDocumentsHandler.cs
index 9df2cf345..89ba02156 100644
--- a/src/Web/Grand.Web/Features/Handlers/Customers/GetDocumentsHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Customers/GetDocumentsHandler.cs
@@ -38,7 +38,7 @@ namespace Grand.Web.Features.Handlers.Customers
{
CustomerId = request.Customer.Id
};
- var documents = await _documentService.GetAll(request.Customer.Id,
+ var documents = await _documentService.GetAll(email: request.Customer.Email,
pageIndex: request.Command.PageNumber - 1,
pageSize: request.Command.PageSize);
model.PagingContext.LoadPagedList(documents);