From 7b32e4594cd91c664950047cb3a59e30037253ea Mon Sep 17 00:00:00 2001 From: wanghaomei <86whm@163.com> Date: Fri, 19 Apr 2024 15:54:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Core/Myshipping.Core.xml | 10 ++++++ .../Service/DjyCustomer/DjyCustomerService.cs | 34 ++++++++++++++++--- .../DjyCustomer/Dto/DjyCustomerInput.cs | 13 +++++-- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/Myshipping.Core/Myshipping.Core.xml b/Myshipping.Core/Myshipping.Core.xml index 48d364c0..93553037 100644 --- a/Myshipping.Core/Myshipping.Core.xml +++ b/Myshipping.Core/Myshipping.Core.xml @@ -12103,6 +12103,11 @@ 订舱客户新增输入参数 + + + 联系人 + + 订舱客户修改输入参数 @@ -12113,6 +12118,11 @@ 主键 + + + 联系人 + + 订舱客户获取(删除)输入参数 diff --git a/Myshipping.Core/Service/DjyCustomer/DjyCustomerService.cs b/Myshipping.Core/Service/DjyCustomer/DjyCustomerService.cs index ae01eb64..21c5771e 100644 --- a/Myshipping.Core/Service/DjyCustomer/DjyCustomerService.cs +++ b/Myshipping.Core/Service/DjyCustomer/DjyCustomerService.cs @@ -154,10 +154,36 @@ namespace Myshipping.Core.Service } await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); - await _repContact.DeleteAsync(x => x.CustomerId == input.Id); - var contactList = input.Contacts.Adapt>(); - contactList.ForEach(x => x.CustomerId = entity.Id); - await _repContact.InsertAsync(contactList); + + //await _repContact.DeleteAsync(x => x.CustomerId == input.Id); + //var contactList = input.Contacts.Adapt>(); + //contactList.ForEach(x => x.CustomerId = entity.Id); + //await _repContact.InsertAsync(contactList); + + var dbContact = await _repContact.AsQueryable().Where(x => x.CustomerId == input.Id).ToListAsync(); + foreach (var dtoUser in input.Contacts) + { + if (dtoUser.Id > 0) + { + var contact = dbContact.First(x => x.Id == dtoUser.Id); + dtoUser.Adapt(contact); + contact.CustomerId = entity.Id; + await _repContact.UpdateAsync(contact); + dbContact.Remove(contact); + } + else + { + var contact = dtoUser.Adapt(); + contact.CustomerId = entity.Id; + await _repContact.InsertAsync(contact); + } + } + + foreach (var contact in dbContact) + { + await _repContact.DeleteAsync(contact); + } + //地址 await _repAddr.DeleteAsync(x => x.CustomerId == input.Id); var addrList = input.Addrs.Adapt>(); diff --git a/Myshipping.Core/Service/DjyCustomer/Dto/DjyCustomerInput.cs b/Myshipping.Core/Service/DjyCustomer/Dto/DjyCustomerInput.cs index 4cd85f6e..b4d39808 100644 --- a/Myshipping.Core/Service/DjyCustomer/Dto/DjyCustomerInput.cs +++ b/Myshipping.Core/Service/DjyCustomer/Dto/DjyCustomerInput.cs @@ -12,7 +12,7 @@ namespace Myshipping.Core.Service { public DjyCustomerInput() { - this.Contacts = new List(); + //this.Contacts = new List(); this.Addrs = new List(); } @@ -168,7 +168,6 @@ namespace Myshipping.Core.Service /// 服务项目 /// public string ServiceItem { get; set; } - public List Contacts { get; set; } /// /// 地址列表 @@ -181,6 +180,10 @@ namespace Myshipping.Core.Service /// public class AddDjyCustomerInput : DjyCustomerInput { + /// + /// 联系人 + /// + public List Contacts { get; set; } = new List(); } @@ -194,7 +197,11 @@ namespace Myshipping.Core.Service /// [Required(ErrorMessage = "主键不能为空")] public long Id { get; set; } - + + /// + /// 联系人 + /// + public List Contacts { get; set; } = new List(); } ///