Beispiel #1
0
        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);
        }
Beispiel #2
0
        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();
        }