private static void CopyRecordFromMyob(AMSDbContext connect, MYOBCustomer jtItem, Customer item) { jtItem.CompanyName = item.IsIndividual ? HandyContactFunctions.FormattedLastAndFirstName(item.LastName, item.FirstName) : item.CompanyName; jtItem.DisplayID = item.DisplayID; jtItem.FirstName = item.FirstName; jtItem.LastName = item.LastName; jtItem.IsIndividual = item.IsIndividual; jtItem.IsActive = item.IsActive; jtItem.RowVersion = item.RowVersion; jtItem.Uid = item.UID; jtItem.LastModified = item.LastModified; jtItem.URI = item.URI.ToString(); if (item.SellingDetails?.InvoiceDelivery != null) { jtItem.DocumentAction = (DocumentAction)item.SellingDetails.InvoiceDelivery; } SyncAddresses(connect, jtItem, item); }
private static void CopyRecordFromMYOB(AMSDbContext connect, MYOBSupplier jtItem, Supplier item) { jtItem.CompanyName = HandyContactFunctions.MakeKey( item.IsIndividual, item.LastName, item.FirstName, item.CompanyName); jtItem.DisplayID = item.DisplayID; jtItem.FirstName = item.FirstName; jtItem.LastName = item.LastName; jtItem.IsIndividual = item.IsIndividual; jtItem.IsActive = item.IsActive; jtItem.RowVersion = item.RowVersion; jtItem.Uid = item.UID; jtItem.LastModified = item.LastModified; jtItem.URI = item.URI.ToString(); jtItem.IsActive = item.IsActive; SyncAddresses(connect, jtItem, item); }
private static void AddNewUpdateExistingRecords( Supplier[] ar, AMSDbContext connect, IProgress <int> progressCallback) { var info = ""; var stepNum = 1; var numSteps = ar.Count(); foreach (var item in ar) { var key = HandyContactFunctions.MakeKey( item.IsIndividual, item.LastName, item.FirstName, item.CompanyName); if (key == info) { throw new ExceptionDuplicateKey($"{info}"); } info = key; HandyFunctions.Log(info); var jtSupplier = connect.MYOBSuppliers.SingleOrDefault(x => x.Uid == item.UID); //unique idex should ensure only 1 if (jtSupplier == null) { jtSupplier = new MYOBSupplier(); connect.MYOBSuppliers.Add(jtSupplier); } CopyRecordFromMYOB(connect, jtSupplier, item); progressCallback.Report((100 * stepNum) / numSteps); stepNum++; } connect.SaveChanges(); }
private static string MakeAlternateKey(Customer customer) { return(customer.IsIndividual ? customer.CompanyName : HandyContactFunctions.FormattedLastAndFirstName(customer.LastName, customer.FirstName)); }