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(); } ///